Skip to content

Commit 7f95a85

Browse files
authored
Fix autotests now with workspaces server (#161)
* trigger autotests * add create ws api + create ws for test users * format code * fix accessing username * remove check for organisation project * let server decide if ws already exists
1 parent b68a7ab commit 7f95a85

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

mergin/client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,24 @@ def workspaces_list(self):
384384
workspaces = json.load(resp)
385385
return workspaces
386386

387+
def create_workspace(self, workspace_name):
388+
"""
389+
Create new workspace for currently active user.
390+
391+
:param workspace_name: Workspace name to create
392+
:type workspace_name: String
393+
"""
394+
if not self._user_info:
395+
raise Exception("Authentication required")
396+
397+
params = {"name": workspace_name}
398+
399+
try:
400+
self.post("/v1/workspace", params, {"Content-Type": "application/json"})
401+
except Exception as e:
402+
detail = f"Workspace name: {workspace_name}"
403+
raise ClientError(str(e), detail)
404+
387405
def create_project(self, project_name, is_public=False, namespace=None):
388406
"""
389407
Create new project repository in user namespace on Mergin Maps server.

mergin/test/test_client.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,30 @@
3535

3636
@pytest.fixture(scope="function")
3737
def mc():
38-
return create_client(API_USER, USER_PWD)
38+
client = create_client(API_USER, USER_PWD)
39+
create_workspace_for_client(client)
40+
return client
3941

4042

4143
@pytest.fixture(scope="function")
4244
def mc2():
43-
return create_client(API_USER2, USER_PWD2)
45+
client = create_client(API_USER2, USER_PWD2)
46+
create_workspace_for_client(client)
47+
return client
4448

4549

4650
def create_client(user, pwd):
4751
assert SERVER_URL and SERVER_URL.rstrip("/") != "https://app.merginmaps.com" and user and pwd
4852
return MerginClient(SERVER_URL, login=user, password=pwd)
4953

5054

55+
def create_workspace_for_client(mc):
56+
try:
57+
mc.create_workspace(mc.username())
58+
except ClientError:
59+
return
60+
61+
5162
def cleanup(mc, project, dirs):
5263
# cleanup leftovers from previous test if needed such as remote project and local directories
5364
try:
@@ -1765,13 +1776,7 @@ def test_project_versions_list(mc, mc2):
17651776
# now user shold have write access
17661777
assert mc.has_writing_permissions(test_project_fullname)
17671778

1768-
# test organization permissions
1769-
test_project_fullname = "testorg" + "/" + "test_org_permissions"
1770-
17711779
# owner should have write access
1772-
assert mc.has_writing_permissions(test_project_fullname)
1773-
1774-
# writer should have write access
17751780
assert mc2.has_writing_permissions(test_project_fullname)
17761781

17771782

mergin/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def save_to_file(stream, path):
3333
:param path: destination file path
3434
"""
3535
directory = os.path.abspath(os.path.dirname(path))
36+
3637
os.makedirs(directory, exist_ok=True)
3738

3839
with open(path, "wb") as output:

0 commit comments

Comments
 (0)