Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions mergin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 13 additions & 8 deletions mergin/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,30 @@

@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):
assert SERVER_URL and SERVER_URL.rstrip("/") != "https://app.merginmaps.com" and user and 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:
Expand Down Expand Up @@ -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)


Expand Down
1 change: 1 addition & 0 deletions mergin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down