5252STORAGE_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" )
5660def mc ():
5761 client = create_client (API_USER , USER_PWD )
@@ -70,7 +74,6 @@ def mc2():
7074def 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
@@ -2683,8 +2686,10 @@ def test_error_push_already_named_project(mc: MerginClient):
26832686
26842687
26852688def test_error_projects_limit_hit (mcStorage : MerginClient ):
2686- test_project = "test_another_project_above_projects_limit "
2689+ test_project = "project_above_projects_limit "
26872690 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 ])
26882693
26892694 client_workspace = None
26902695 for workspace in mcStorage .workspaces_list ():
@@ -2695,12 +2700,10 @@ def test_error_projects_limit_hit(mcStorage: MerginClient):
26952700 client_workspace_storage = client_workspace ["storage" ]
26962701 mcStorage .patch (
26972702 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 }},
26992704 {"Content-Type" : "application/json" },
27002705 )
27012706
2702- project_dir = os .path .join (TMP_DIR , test_project , API_USER )
2703-
27042707 with pytest .raises (ClientError ) as e :
27052708 mcStorage .create_project_and_push (test_project_fullname , project_dir )
27062709 assert e .value .server_code == ErrorCode .ProjectsLimitHit .value
@@ -2714,32 +2717,38 @@ def test_error_projects_limit_hit(mcStorage: MerginClient):
27142717
27152718
27162719# TODO: refactor tests to create workspaces on each run and apply test_error_monthly_contributors_limit_hit
2717- # def test_error_monthly_contributors_limit_hit(mcStorage: MerginClient):
2718- # test_project = "test_monthly_contributors_limit_hit"
2719- # test_project_fullname = STORAGE_WORKSPACE + "/" + test_project
2720-
2721- # client_workspace = None
2722- # for workspace in mcStorage.workspaces_list():
2723- # if workspace["name"] == STORAGE_WORKSPACE:
2724- # client_workspace = workspace
2725- # break
2726-
2727- # client_workspace_id = client_workspace["id"]
2728- # mcStorage.patch(
2729- # f"/v1/tests/workspaces/{client_workspace_id}",
2730- # {"limits_override": {"monthly_contributors": 0, "api_allowed": True}},
2731- # {"Content-Type": "application/json"},
2732- # )
2733-
2734- # with pytest.raises(ClientError) as e:
2735- # mcStorage.create_project_and_push(test_project_fullname, project_dir)
2736-
2737- # assert e.value.server_code == ErrorCode.MonthlyContributorsLimitHit.value
2738- # assert e.value.detail == (
2739- # "Maximum number of workspace contributors is reached. "
2740- # "Please upgrade your subscription to push changes or create projects."
2741- # )
2742- # assert e.value.http_error == 422
2743- # assert e.value.http_method == "POST"
2744- # assert e.value.url == f"{mc.url}v1/project/testpluginstorage"
2745- # assert e.value.contributors_quota == 0
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+ print (e .value .server_response )
2746+ assert e .value .server_code == ErrorCode .MonthlyContributorsLimitHit .value
2747+ assert e .value .detail == (
2748+ "Maximum number of workspace contributors is reached. "
2749+ "Please upgrade your subscription to push changes or create projects. (MonthlyContributorsLimitHit)"
2750+ )
2751+ assert e .value .http_error == 422
2752+ assert e .value .http_method == "POST"
2753+ assert e .value .url == f"{ mcStorage .url } v1/project/push/testpluginstorage/{ test_project } "
2754+ assert e .value .server_response .get ("contributors_quota" ) == 0
0 commit comments