Skip to content

Commit 7671e82

Browse files
committed
Introduce create_invitation method
1 parent 2440b66 commit 7671e82

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

mergin/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,3 +1444,11 @@ def send_logs(
14441444
else:
14451445
request = urllib.request.Request(url, data=payload, headers=header)
14461446
return self._do_request(request)
1447+
1448+
def create_invitation(self, workspace_id: int, email: str, workspace_role: WorkspaceRole):
1449+
"""
1450+
Create invitation to workspace for specific role
1451+
"""
1452+
params = {"email": email, "role": workspace_role.value}
1453+
ws_inv = self.post(f"v2/workspaces/{workspace_id}/invitations", params, json_headers)
1454+
return json.load(ws_inv)

mergin/test/test_client.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
decode_token_data,
2121
TokenError,
2222
ServerType,
23-
WorkspaceRole,
2423
)
2524
from ..client_push import push_project_async, push_project_cancel
2625
from ..client_pull import (
@@ -2911,3 +2910,20 @@ def test_do_request_error_handling(mc: MerginClient):
29112910

29122911
assert e.value.http_error == 400
29132912
assert "Passwords must be at least 8 characters long." in e.value.detail
2913+
2914+
2915+
def test_creat_invitation(mc: MerginClient):
2916+
"""Test client method to create workspace invitation"""
2917+
workspace_id = next((w["id"] for w in mc.workspaces_list() if w["name"] == mc.username()))
2918+
role = WorkspaceRole.WRITER
2919+
email = "invitation@client.py"
2920+
inv = mc.create_invitation(workspace_id, email, role)
2921+
assert inv["email"] == email
2922+
assert inv["role"] == role.value
2923+
mc.delete(f"v1/workspace/invitation/{inv['id']}") # resolves invitation to allow another invitation to the email
2924+
role = WorkspaceRole.GUEST
2925+
inv = mc.create_invitation(workspace_id, email, role)
2926+
assert inv["email"] == email
2927+
assert "projects" not in inv
2928+
mc.delete(f"v1/workspace/invitation/{inv['id']}")
2929+

0 commit comments

Comments
 (0)