3232from ..utils import (
3333 generate_checksum ,
3434 get_versions_with_file_changes ,
35- is_version_acceptable ,
3635 unique_path_name ,
3736 conflicted_copy_file_name ,
3837 edit_conflict_file_name ,
@@ -745,12 +744,12 @@ def test_set_editor_access(mc):
745744 assert API_USER2 not in access ["writersnames" ]
746745
747746
748- def test_available_storage_validation (mcStorage ):
747+ def test_available_workspace_storage (mcStorage ):
749748 """
750749 Testing of storage limit - applies to user pushing changes into own project (namespace matching username).
751750 This test also tests giving read and write access to another user. Additionally tests also uploading of big file.
752751 """
753- test_project = "test_available_storage_validation "
752+ test_project = "test_available_workspace_storage "
754753 test_project_fullname = STORAGE_WORKSPACE + "/" + test_project
755754
756755 # cleanups
@@ -766,15 +765,28 @@ def test_available_storage_validation(mcStorage):
766765
767766 # get info about storage capacity
768767 storage_remaining = 0
768+ client_workspace = None
769+ for workspace in mcStorage .workspaces_list ():
770+ if workspace ["name" ] == STORAGE_WORKSPACE :
771+ client_workspace = workspace
772+ break
773+ assert client_workspace is not None
774+ current_storage = client_workspace ["storage" ]
775+ client_workspace_id = client_workspace ["id" ]
776+ # 5 MB
777+ testing_storage = 5242880
778+ # add storage limit, to prevent creating too big files
779+ mcStorage .patch (
780+ f"/v1/tests/workspaces/{ client_workspace_id } " ,
781+ {"limits_override" : {"storage" : testing_storage , "projects" : 1 , "api_allowed" : True }},
782+ {"Content-Type" : "application/json" },
783+ )
769784
770785 if mcStorage .server_type () == ServerType .OLD :
771786 user_info = mcStorage .user_info ()
772- storage_remaining = user_info [ "storage" ] - user_info ["disk_usage" ]
787+ storage_remaining = testing_storage - user_info ["disk_usage" ]
773788 else :
774- for workspace in mcStorage .workspaces_list ():
775- if workspace ["name" ] == STORAGE_WORKSPACE :
776- storage_remaining = workspace ["storage" ] - workspace ["disk_usage" ]
777- break
789+ storage_remaining = testing_storage - client_workspace ["disk_usage" ]
778790
779791 # generate dummy data (remaining storage + extra 1024b)
780792 dummy_data_path = project_dir + "/data"
@@ -786,18 +798,23 @@ def test_available_storage_validation(mcStorage):
786798 try :
787799 mcStorage .push_project (project_dir )
788800 except ClientError as e :
801+ print ("Pushe fail" )
789802 # Expecting "You have reached a data limit" 400 server error msg.
790803 assert "You have reached a data limit" in str (e )
791804 got_right_err = True
792- assert got_right_err
805+ finally :
806+ assert got_right_err
793807
794- # Expecting empty project
795- project_info = get_project_info (mcStorage , STORAGE_WORKSPACE , test_project )
796- assert project_info ["version" ] == "v0"
797- assert project_info ["disk_usage" ] == 0
808+ # Expecting empty project
809+ project_info = get_project_info (mcStorage , STORAGE_WORKSPACE , test_project )
810+ assert project_info ["version" ] == "v0"
811+ assert project_info ["disk_usage" ] == 0
798812
799- # remove dummy big file from a disk
800- remove_folders ([project_dir ])
813+ # remove dummy big file from a disk
814+ remove_folders ([project_dir ])
815+
816+ # revert storage limit to default value
817+ mcStorage .patch (f"/v1/tests/workspaces/{ client_workspace_id } " , {"limits_override" : { "storage" : current_storage , "projects" : 1 , "api_allowed" : True }}, {"Content-Type" : "application/json" })
801818
802819
803820def test_available_storage_validation2 (mc , mc2 ):
@@ -866,7 +883,7 @@ def get_project_info(mc, namespace, project_name):
866883 :param project_name: project's name
867884 :return: dict with project info
868885 """
869- projects = mc .projects_list (flag = "created" )
886+ projects = mc .projects_list (flag = "created" , namespace = namespace )
870887 test_project_list = [p for p in projects if p ["name" ] == project_name and p ["namespace" ] == namespace ]
871888 assert len (test_project_list ) == 1
872889 return test_project_list [0 ]
0 commit comments