Skip to content

Commit 8d373fd

Browse files
committed
Merge branch 'master' into project-history
2 parents e1c0b2b + 74222e4 commit 8d373fd

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

mergin/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
class ErrorCode(Enum):
1515
ProjectsLimitHit = "ProjectsLimitHit"
1616
StorageLimitHit = "StorageLimitHit"
17+
MonthlyContributorsLimitHit = "MonthlyContributorsLimitHit"
1718

1819

1920
class ClientError(Exception):
@@ -36,6 +37,8 @@ def __str__(self):
3637
string_res += f"URL: {self.url}\n"
3738
if self.http_method:
3839
string_res += f"Method: {self.http_method}\n"
40+
if self.server_code:
41+
string_res += f"Error code: {self.server_code}\n"
3942
if self.extra:
4043
string_res += f"{self.extra}\n"
4144
return string_res

mergin/test/test_client.py

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
STORAGE_WORKSPACE = os.environ.get("TEST_STORAGE_WORKSPACE", "testpluginstorage")
5353

5454

55+
def get_limit_overrides(storage: int):
56+
return {"storage": storage, "projects": 2, "api_allowed": True, "monthly_contributors": -1}
57+
58+
5559
@pytest.fixture(scope="function")
5660
def mc():
5761
client = create_client(API_USER, USER_PWD)
@@ -70,7 +74,6 @@ def mc2():
7074
def mcStorage(request):
7175
client = create_client(API_USER, USER_PWD)
7276
workspace_name = create_workspace_for_client(client, STORAGE_WORKSPACE)
73-
print(workspace_name)
7477
client_workspace = None
7578
for workspace in client.workspaces_list():
7679
if workspace["name"] == workspace_name:
@@ -83,7 +86,7 @@ def teardown():
8386
# back to original values... (1 project, api allowed ...)
8487
client.patch(
8588
f"/v1/tests/workspaces/{client_workspace_id}",
86-
{"limits_override": {"storage": client_workspace_storage, "projects": 1, "api_allowed": True}},
89+
{"limits_override": get_limit_overrides(client_workspace_storage)},
8790
{"Content-Type": "application/json"},
8891
)
8992

@@ -2691,8 +2694,10 @@ def test_error_push_already_named_project(mc: MerginClient):
26912694

26922695

26932696
def test_error_projects_limit_hit(mcStorage: MerginClient):
2694-
test_project = "test_another_project_above_projects_limit"
2697+
test_project = "project_above_projects_limit"
26952698
test_project_fullname = STORAGE_WORKSPACE + "/" + test_project
2699+
project_dir = os.path.join(TMP_DIR, test_project, API_USER)
2700+
cleanup(mcStorage, test_project, [project_dir])
26962701

26972702
client_workspace = None
26982703
for workspace in mcStorage.workspaces_list():
@@ -2703,12 +2708,10 @@ def test_error_projects_limit_hit(mcStorage: MerginClient):
27032708
client_workspace_storage = client_workspace["storage"]
27042709
mcStorage.patch(
27052710
f"/v1/tests/workspaces/{client_workspace_id}",
2706-
{"limits_override": {"storage": client_workspace_storage, "projects": 0, "api_allowed": True}},
2711+
{"limits_override": {**get_limit_overrides(client_workspace_storage), "projects": 0}},
27072712
{"Content-Type": "application/json"},
27082713
)
27092714

2710-
project_dir = os.path.join(TMP_DIR, test_project, API_USER)
2711-
27122715
with pytest.raises(ClientError) as e:
27132716
mcStorage.create_project_and_push(test_project_fullname, project_dir)
27142717
assert e.value.server_code == ErrorCode.ProjectsLimitHit.value
@@ -2719,3 +2722,40 @@ def test_error_projects_limit_hit(mcStorage: MerginClient):
27192722
assert e.value.http_error == 422
27202723
assert e.value.http_method == "POST"
27212724
assert e.value.url == f"{mcStorage.url}v1/project/testpluginstorage"
2725+
2726+
2727+
# TODO: refactor tests to create workspaces on each run and apply test_error_monthly_contributors_limit_hit
2728+
def test_error_monthly_contributors_limit_hit(mcStorage: MerginClient):
2729+
test_project = "test_monthly_contributors_limit_hit"
2730+
project_dir = os.path.join(TMP_DIR, test_project)
2731+
test_project_fullname = STORAGE_WORKSPACE + "/" + test_project
2732+
cleanup(mcStorage, test_project_fullname, [project_dir])
2733+
2734+
client_workspace = None
2735+
for workspace in mcStorage.workspaces_list():
2736+
if workspace["name"] == STORAGE_WORKSPACE:
2737+
client_workspace = workspace
2738+
break
2739+
2740+
client_workspace_id = client_workspace["id"]
2741+
client_workspace_storage = client_workspace["storage"]
2742+
mcStorage.patch(
2743+
f"/v1/tests/workspaces/{client_workspace_id}",
2744+
{"limits_override": {**get_limit_overrides(client_workspace_storage), "monthly_contributors": 0}},
2745+
{"Content-Type": "application/json"},
2746+
)
2747+
2748+
mcStorage.create_project_and_push(test_project_fullname, project_dir)
2749+
shutil.copy(os.path.join(TEST_DATA_DIR, "test.txt"), project_dir)
2750+
with pytest.raises(ClientError) as e:
2751+
mcStorage.push_project(project_dir)
2752+
2753+
assert e.value.server_code == ErrorCode.MonthlyContributorsLimitHit.value
2754+
assert e.value.detail == (
2755+
"Maximum number of workspace contributors is reached. "
2756+
"Please upgrade your subscription to push changes or create projects. (MonthlyContributorsLimitHit)"
2757+
)
2758+
assert e.value.http_error == 422
2759+
assert e.value.http_method == "POST"
2760+
assert e.value.url == f"{mcStorage.url}v1/project/push/testpluginstorage/{test_project}"
2761+
assert e.value.server_response.get("contributors_quota") == 0

0 commit comments

Comments
 (0)