|
| 1 | +import secrets |
| 2 | +import string |
| 3 | + |
1 | 4 | from terminusdb_client.woqlclient.connectionConfig import ConnectionConfig
|
2 | 5 |
|
3 | 6 |
|
4 | 7 | class TestConnectionConfig:
|
5 | 8 | start_server_url = "http://localhost:6363/"
|
6 | 9 | start_dbid = "testDB"
|
7 | 10 | local_user = "admin"
|
| 11 | + # Set of random string values that can as replacements for dummy id valuess |
| 12 | + # i.e accountid,branchid,refid etc |
| 13 | + id_value = "".join( |
| 14 | + secrets.choice(string.ascii_uppercase + string.ascii_lowercase) |
| 15 | + for _ in range(16) |
| 16 | + ) |
8 | 17 | # to be review !!!!!
|
9 | 18 | connection_config = ConnectionConfig(
|
10 | 19 | start_server_url,
|
@@ -38,3 +47,103 @@ def test_change_server(self):
|
38 | 47 |
|
39 | 48 | def test_check_basic_auth(self):
|
40 | 49 | assert self.connection_config.basic_auth == "admin:mykey"
|
| 50 | + |
| 51 | + def test_set_remote_auth(self): |
| 52 | + auth_dict = {type: "jwt", "key": "eyJhbGciOiJIUzI1NiIsInR5c"} |
| 53 | + self.connection_config.set_remote_auth(auth_dict) |
| 54 | + assert self.connection_config.remote_auth == auth_dict |
| 55 | + auth_dict = { |
| 56 | + type: "basic", |
| 57 | + "user": self.local_user, |
| 58 | + "key": "admin_testDB_Password", |
| 59 | + } |
| 60 | + self.connection_config.update(remote_auth=auth_dict) |
| 61 | + assert self.connection_config.remote_auth == auth_dict |
| 62 | + |
| 63 | + def test_update(self): |
| 64 | + self.connection_config.update(db=self.id_value) |
| 65 | + self.connection_config.update(account=self.id_value) |
| 66 | + self.connection_config.update(repo=self.id_value) |
| 67 | + self.connection_config.update(branch=self.id_value) |
| 68 | + self.connection_config.update(ref=self.id_value) |
| 69 | + self.connection_config.update(repo=self.id_value) |
| 70 | + assert self.connection_config.db == self.id_value |
| 71 | + assert self.connection_config.account == self.id_value |
| 72 | + assert self.connection_config.repo == self.id_value |
| 73 | + assert self.connection_config.branch == self.id_value |
| 74 | + assert self.connection_config.ref == self.id_value |
| 75 | + assert self.connection_config.repo == self.id_value |
| 76 | + |
| 77 | + def test_clear_cursor(self): |
| 78 | + self.connection_config.update(branch=self.id_value) |
| 79 | + self.connection_config.update(repo=self.id_value) |
| 80 | + self.connection_config.update(account=self.id_value) |
| 81 | + self.connection_config.update(db=self.id_value) |
| 82 | + self.connection_config.update(ref=self.id_value) |
| 83 | + self.connection_config.clear_cursor() |
| 84 | + assert self.connection_config.branch != self.id_value |
| 85 | + assert self.connection_config.repo != self.id_value |
| 86 | + assert self.connection_config.account is False |
| 87 | + assert self.connection_config.db is False |
| 88 | + assert self.connection_config.ref is False |
| 89 | + |
| 90 | + def test_user(self): |
| 91 | + assert self.connection_config.user() == self.local_user |
| 92 | + auth_dict = {type: "jwt", "key": "eyJhbGciOiJIUzI1NiIsInR5c"} |
| 93 | + self.connection_config.update(remote=auth_dict) |
| 94 | + assert self.connection_config.user() == self.local_user |
| 95 | + |
| 96 | + def test_set_basic_auth(self): |
| 97 | + assert self.connection_config.set_basic_auth() is None |
| 98 | + self.connection_config.set_basic_auth(api_key="admin_testDB_Password") |
| 99 | + basic_auth = self.connection_config.basic_auth |
| 100 | + assert basic_auth == "admin:admin_testDB_Password" |
| 101 | + |
| 102 | + def test_db_url_fragmen(self): |
| 103 | + self.connection_config.update(db=self.id_value) |
| 104 | + self.connection_config.update(account=self.id_value) |
| 105 | + db_url_fragment = self.connection_config.db_url_fragment() |
| 106 | + assert db_url_fragment == f"{self.id_value}/{self.id_value}" |
| 107 | + |
| 108 | + def test_db_base(self): |
| 109 | + self.connection_config.update(db=self.id_value) |
| 110 | + self.connection_config.update(account=self.id_value) |
| 111 | + db_base = self.connection_config.db_base("push") |
| 112 | + assert db_base == f"http://localhost:6363/push/{self.id_value}/{self.id_value}" |
| 113 | + |
| 114 | + def test_repo_base(self): |
| 115 | + self.connection_config.update(db=self.id_value) |
| 116 | + self.connection_config.update(account=self.id_value) |
| 117 | + self.connection_config.db_base("pull") |
| 118 | + default_base = self.connection_config.repo_base("pull") |
| 119 | + assert ( |
| 120 | + default_base |
| 121 | + == f"http://localhost:6363/pull/{self.id_value}/{self.id_value}/local" |
| 122 | + ) |
| 123 | + |
| 124 | + self.connection_config.update(repo=self.id_value) |
| 125 | + updated_base = self.connection_config.db_base("pull") |
| 126 | + assert ( |
| 127 | + updated_base |
| 128 | + == f"http://localhost:6363/pull/{self.id_value}/{self.id_value}" |
| 129 | + ) |
| 130 | + |
| 131 | + def test_account(self): |
| 132 | + self.connection_config.account = self.id_value |
| 133 | + assert self.connection_config.account == self.id_value |
| 134 | + |
| 135 | + def test_db(self): |
| 136 | + self.connection_config.db = self.id_value |
| 137 | + assert self.connection_config.db == self.id_value |
| 138 | + |
| 139 | + def test_repo(self): |
| 140 | + self.connection_config.repo = self.id_value |
| 141 | + assert self.connection_config.repo == self.id_value |
| 142 | + |
| 143 | + def branch(self): |
| 144 | + self.connection_config.branch = self.id_value |
| 145 | + assert self.connection_config.branch == self.id_value |
| 146 | + |
| 147 | + def ref(self): |
| 148 | + self.connection_config.ref = self.id_value |
| 149 | + assert self.connection_config.ref == self.id_value |
0 commit comments