From 1f4bf34dd0da90097cb8f2011ceb1fe8cc8eb91b Mon Sep 17 00:00:00 2001 From: Tomas Mizera Date: Tue, 31 Jan 2023 16:27:04 +0100 Subject: [PATCH 1/6] trigger autotests --- mergin/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mergin/utils.py b/mergin/utils.py index 8602a9f8..0044560c 100644 --- a/mergin/utils.py +++ b/mergin/utils.py @@ -33,6 +33,7 @@ def save_to_file(stream, path): :param path: destination file path """ directory = os.path.abspath(os.path.dirname(path)) + os.makedirs(directory, exist_ok=True) with open(path, "wb") as output: From 79009682bf072599f3658ed7971171d8a349df09 Mon Sep 17 00:00:00 2001 From: Tomas Mizera Date: Tue, 31 Jan 2023 17:28:29 +0100 Subject: [PATCH 2/6] add create ws api + create ws for test users --- mergin/client.py | 19 +++++++++++++++++++ mergin/test/test_client.py | 19 +++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/mergin/client.py b/mergin/client.py index 7d3cc3c9..cb6b97b5 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -384,6 +384,25 @@ def workspaces_list(self): workspaces = json.load(resp) return workspaces + def create_workspace(self, workspace_name): + """ + Create new workspace for currently active user. + + :param workspace_name: Workspace name to create + :type workspace_name: String + """ + if not self._user_info: + raise Exception("Authentication required") + + params = {"name": workspace_name} + + try: + self.post("/v1/workspace", params, {"Content-Type": "application/json"}) + except Exception as e: + detail = f"Username: {self.username}, workspace name: {workspace_name}" + raise ClientError(str(e), detail) + + def create_project(self, project_name, is_public=False, namespace=None): """ Create new project repository in user namespace on Mergin Maps server. diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index ce3d0b43..f60a34aa 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -35,12 +35,16 @@ @pytest.fixture(scope="function") def mc(): - return create_client(API_USER, USER_PWD) + client = create_client(API_USER, USER_PWD) + create_workspace_for_client( client ) + return client @pytest.fixture(scope="function") def mc2(): - return create_client(API_USER2, USER_PWD2) + client = create_client(API_USER2, USER_PWD2) + create_workspace_for_client( client ) + return client def create_client(user, pwd): @@ -48,6 +52,17 @@ def create_client(user, pwd): return MerginClient(SERVER_URL, login=user, password=pwd) +def create_workspace_for_client(mc): + info = mc.user_info() + + # check if mc already have workspace with its name + wsAlreadyCreated = len( list( filter( lambda x: x.name == mc.username, info.get("workspaces") ) ) ) > 0 + if wsAlreadyCreated: + return + + mc.create_workspace( mc.username ) + + def cleanup(mc, project, dirs): # cleanup leftovers from previous test if needed such as remote project and local directories try: From 72ac736cdb0276e0d435b01e34b9ee73751fb470 Mon Sep 17 00:00:00 2001 From: Tomas Mizera Date: Tue, 31 Jan 2023 19:30:09 +0100 Subject: [PATCH 3/6] format code --- mergin/client.py | 1 - mergin/test/test_client.py | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mergin/client.py b/mergin/client.py index cb6b97b5..86a75578 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -402,7 +402,6 @@ def create_workspace(self, workspace_name): detail = f"Username: {self.username}, workspace name: {workspace_name}" raise ClientError(str(e), detail) - def create_project(self, project_name, is_public=False, namespace=None): """ Create new project repository in user namespace on Mergin Maps server. diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index f60a34aa..92cf5f04 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -36,14 +36,14 @@ @pytest.fixture(scope="function") def mc(): client = create_client(API_USER, USER_PWD) - create_workspace_for_client( client ) + create_workspace_for_client(client) return client @pytest.fixture(scope="function") def mc2(): client = create_client(API_USER2, USER_PWD2) - create_workspace_for_client( client ) + create_workspace_for_client(client) return client @@ -56,11 +56,11 @@ def create_workspace_for_client(mc): info = mc.user_info() # check if mc already have workspace with its name - wsAlreadyCreated = len( list( filter( lambda x: x.name == mc.username, info.get("workspaces") ) ) ) > 0 + wsAlreadyCreated = len(list(filter(lambda x: x.name == mc.username, info.get("workspaces")))) > 0 if wsAlreadyCreated: return - mc.create_workspace( mc.username ) + mc.create_workspace(mc.username) def cleanup(mc, project, dirs): From a98a45e4b6b55d20bb4570bd2c73462cf9b74a93 Mon Sep 17 00:00:00 2001 From: Tomas Mizera Date: Tue, 31 Jan 2023 20:01:08 +0100 Subject: [PATCH 4/6] fix accessing username --- mergin/client.py | 2 +- mergin/test/test_client.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mergin/client.py b/mergin/client.py index 86a75578..c43e13cd 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -399,7 +399,7 @@ def create_workspace(self, workspace_name): try: self.post("/v1/workspace", params, {"Content-Type": "application/json"}) except Exception as e: - detail = f"Username: {self.username}, workspace name: {workspace_name}" + detail = f"Workspace name: {workspace_name}" raise ClientError(str(e), detail) def create_project(self, project_name, is_public=False, namespace=None): diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index 92cf5f04..ac6f799e 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -56,11 +56,11 @@ def create_workspace_for_client(mc): info = mc.user_info() # check if mc already have workspace with its name - wsAlreadyCreated = len(list(filter(lambda x: x.name == mc.username, info.get("workspaces")))) > 0 + wsAlreadyCreated = len(list(filter(lambda x: x["name"] == mc.username(), info.get("workspaces")))) > 0 if wsAlreadyCreated: return - mc.create_workspace(mc.username) + mc.create_workspace(mc.username()) def cleanup(mc, project, dirs): From cae8ceffe26fae7de9863a3904d08d8c2ecae12c Mon Sep 17 00:00:00 2001 From: Tomas Mizera Date: Tue, 31 Jan 2023 21:13:52 +0100 Subject: [PATCH 5/6] remove check for organisation project --- mergin/test/test_client.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index ac6f799e..8d9a0591 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -1780,13 +1780,7 @@ def test_project_versions_list(mc, mc2): # now user shold have write access assert mc.has_writing_permissions(test_project_fullname) - # test organization permissions - test_project_fullname = "testorg" + "/" + "test_org_permissions" - # owner should have write access - assert mc.has_writing_permissions(test_project_fullname) - - # writer should have write access assert mc2.has_writing_permissions(test_project_fullname) From 6d790181c341d0f972f6d9661a5bd8eee2d2f7b6 Mon Sep 17 00:00:00 2001 From: Tomas Mizera Date: Wed, 1 Feb 2023 10:24:46 +0100 Subject: [PATCH 6/6] let server decide if ws already exists --- mergin/test/test_client.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index 8d9a0591..320cc312 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -53,15 +53,11 @@ def create_client(user, pwd): def create_workspace_for_client(mc): - info = mc.user_info() - - # check if mc already have workspace with its name - wsAlreadyCreated = len(list(filter(lambda x: x["name"] == mc.username(), info.get("workspaces")))) > 0 - if wsAlreadyCreated: + try: + mc.create_workspace(mc.username()) + except ClientError: return - mc.create_workspace(mc.username()) - def cleanup(mc, project, dirs): # cleanup leftovers from previous test if needed such as remote project and local directories