diff --git a/mergin/client.py b/mergin/client.py index 7d3cc3c9..c43e13cd 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -384,6 +384,24 @@ 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"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..320cc312 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,13 @@ def create_client(user, pwd): return MerginClient(SERVER_URL, login=user, password=pwd) +def create_workspace_for_client(mc): + try: + mc.create_workspace(mc.username()) + except ClientError: + return + + def cleanup(mc, project, dirs): # cleanup leftovers from previous test if needed such as remote project and local directories try: @@ -1765,13 +1776,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) 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: