Skip to content

Commit 007cf90

Browse files
committed
Added teardown for limit overrides
1 parent 23fa366 commit 007cf90

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

mergin/test/test_client.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,27 @@ def mc2():
6767

6868

6969
@pytest.fixture(scope="function")
70-
def mcStorage():
70+
def mcStorage(request):
7171
client = create_client(API_USER, USER_PWD)
72-
create_workspace_for_client(client, STORAGE_WORKSPACE)
72+
workspace_name = create_workspace_for_client(client, STORAGE_WORKSPACE)
73+
print(workspace_name)
74+
client_workspace = None
75+
for workspace in client.workspaces_list():
76+
if workspace["name"] == workspace_name:
77+
client_workspace = workspace
78+
break
79+
client_workspace_id = client_workspace["id"]
80+
client_workspace_storage = client_workspace["storage"]
81+
82+
def teardown():
83+
# back to original values... (1 project, api allowed ...)
84+
client.patch(
85+
f"/v1/tests/workspaces/{client_workspace_id}",
86+
{"limits_override": {"storage": client_workspace_storage, "projects": 1, "api_allowed": True}},
87+
{"Content-Type": "application/json"},
88+
)
89+
90+
request.addfinalizer(teardown)
7391
return client
7492

7593

@@ -78,11 +96,13 @@ def create_client(user, pwd):
7896
return MerginClient(SERVER_URL, login=user, password=pwd)
7997

8098

81-
def create_workspace_for_client(mc: MerginClient, workspace_name=None):
99+
def create_workspace_for_client(mc: MerginClient, workspace_name=None) -> str:
100+
workspace_name = workspace_name or mc.username()
82101
try:
83-
mc.create_workspace(workspace_name or mc.username())
102+
mc.create_workspace(workspace_name)
84103
except ClientError:
85-
return
104+
pass
105+
return workspace_name
86106

87107

88108
def cleanup(mc, project, dirs):
@@ -798,7 +818,6 @@ def test_available_workspace_storage(mcStorage):
798818
try:
799819
mcStorage.push_project(project_dir)
800820
except ClientError as e:
801-
print("Pushe fail")
802821
# Expecting "You have reached a data limit" 400 server error msg.
803822
assert "You have reached a data limit" in str(e)
804823
got_right_err = True
@@ -813,13 +832,6 @@ def test_available_workspace_storage(mcStorage):
813832
# remove dummy big file from a disk
814833
remove_folders([project_dir])
815834

816-
# revert storage limit to default value
817-
mcStorage.patch(
818-
f"/v1/tests/workspaces/{client_workspace_id}",
819-
{"limits_override": {"storage": current_storage, "projects": 1, "api_allowed": True}},
820-
{"Content-Type": "application/json"},
821-
)
822-
823835

824836
def test_available_storage_validation2(mc, mc2):
825837
"""
@@ -2699,10 +2711,3 @@ def test_error_projects_limit_hit(mcStorage: MerginClient):
26992711
assert e.value.http_error == 422
27002712
assert e.value.http_method == "POST"
27012713
assert e.value.url == f"{mcStorage.url}v1/project/testpluginstorage"
2702-
2703-
# back to original values... (1 project, api allowed ...)
2704-
mcStorage.patch(
2705-
f"/v1/tests/workspaces/{client_workspace_id}",
2706-
{"limits_override": {"storage": client_workspace_storage, "projects": 1, "api_allowed": True}},
2707-
{"Content-Type": "application/json"},
2708-
)

0 commit comments

Comments
 (0)