52
52
STORAGE_WORKSPACE = os .environ .get ("TEST_STORAGE_WORKSPACE" , "testpluginstorage" )
53
53
54
54
55
+ def get_limit_overrides (storage : int ):
56
+ return {"storage" : storage , "projects" : 2 , "api_allowed" : True , "monthly_contributors" : - 1 }
57
+
58
+
55
59
@pytest .fixture (scope = "function" )
56
60
def mc ():
57
61
client = create_client (API_USER , USER_PWD )
@@ -70,7 +74,6 @@ def mc2():
70
74
def mcStorage (request ):
71
75
client = create_client (API_USER , USER_PWD )
72
76
workspace_name = create_workspace_for_client (client , STORAGE_WORKSPACE )
73
- print (workspace_name )
74
77
client_workspace = None
75
78
for workspace in client .workspaces_list ():
76
79
if workspace ["name" ] == workspace_name :
@@ -83,7 +86,7 @@ def teardown():
83
86
# back to original values... (1 project, api allowed ...)
84
87
client .patch (
85
88
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 ) },
87
90
{"Content-Type" : "application/json" },
88
91
)
89
92
@@ -2683,8 +2686,10 @@ def test_error_push_already_named_project(mc: MerginClient):
2683
2686
2684
2687
2685
2688
def test_error_projects_limit_hit (mcStorage : MerginClient ):
2686
- test_project = "test_another_project_above_projects_limit "
2689
+ test_project = "project_above_projects_limit "
2687
2690
test_project_fullname = STORAGE_WORKSPACE + "/" + test_project
2691
+ project_dir = os .path .join (TMP_DIR , test_project , API_USER )
2692
+ cleanup (mcStorage , test_project , [project_dir ])
2688
2693
2689
2694
client_workspace = None
2690
2695
for workspace in mcStorage .workspaces_list ():
@@ -2695,12 +2700,10 @@ def test_error_projects_limit_hit(mcStorage: MerginClient):
2695
2700
client_workspace_storage = client_workspace ["storage" ]
2696
2701
mcStorage .patch (
2697
2702
f"/v1/tests/workspaces/{ client_workspace_id } " ,
2698
- {"limits_override" : {"storage" : client_workspace_storage , "projects" : 0 , "api_allowed" : True }},
2703
+ {"limits_override" : {** get_limit_overrides ( client_workspace_storage ) , "projects" : 0 }},
2699
2704
{"Content-Type" : "application/json" },
2700
2705
)
2701
2706
2702
- project_dir = os .path .join (TMP_DIR , test_project , API_USER )
2703
-
2704
2707
with pytest .raises (ClientError ) as e :
2705
2708
mcStorage .create_project_and_push (test_project_fullname , project_dir )
2706
2709
assert e .value .server_code == ErrorCode .ProjectsLimitHit .value
@@ -2711,3 +2714,40 @@ def test_error_projects_limit_hit(mcStorage: MerginClient):
2711
2714
assert e .value .http_error == 422
2712
2715
assert e .value .http_method == "POST"
2713
2716
assert e .value .url == f"{ mcStorage .url } v1/project/testpluginstorage"
2717
+
2718
+
2719
+ # TODO: refactor tests to create workspaces on each run and apply test_error_monthly_contributors_limit_hit
2720
+ def test_error_monthly_contributors_limit_hit (mcStorage : MerginClient ):
2721
+ test_project = "test_monthly_contributors_limit_hit"
2722
+ project_dir = os .path .join (TMP_DIR , test_project )
2723
+ test_project_fullname = STORAGE_WORKSPACE + "/" + test_project
2724
+ cleanup (mcStorage , test_project_fullname , [project_dir ])
2725
+
2726
+ client_workspace = None
2727
+ for workspace in mcStorage .workspaces_list ():
2728
+ if workspace ["name" ] == STORAGE_WORKSPACE :
2729
+ client_workspace = workspace
2730
+ break
2731
+
2732
+ client_workspace_id = client_workspace ["id" ]
2733
+ client_workspace_storage = client_workspace ["storage" ]
2734
+ mcStorage .patch (
2735
+ f"/v1/tests/workspaces/{ client_workspace_id } " ,
2736
+ {"limits_override" : {** get_limit_overrides (client_workspace_storage ), "monthly_contributors" : 0 }},
2737
+ {"Content-Type" : "application/json" },
2738
+ )
2739
+
2740
+ mcStorage .create_project_and_push (test_project_fullname , project_dir )
2741
+ shutil .copy (os .path .join (TEST_DATA_DIR , "test.txt" ), project_dir )
2742
+ with pytest .raises (ClientError ) as e :
2743
+ mcStorage .push_project (project_dir )
2744
+
2745
+ assert e .value .server_code == ErrorCode .MonthlyContributorsLimitHit .value
2746
+ assert e .value .detail == (
2747
+ "Maximum number of workspace contributors is reached. "
2748
+ "Please upgrade your subscription to push changes or create projects. (MonthlyContributorsLimitHit)"
2749
+ )
2750
+ assert e .value .http_error == 422
2751
+ assert e .value .http_method == "POST"
2752
+ assert e .value .url == f"{ mcStorage .url } v1/project/push/testpluginstorage/{ test_project } "
2753
+ assert e .value .server_response .get ("contributors_quota" ) == 0
0 commit comments