99
1010
1111class TestFileUpload :
12-
1312 def test_file_upload (self ):
1413 """
1514 Test case for uploading a file to a dataset.
@@ -46,6 +45,58 @@ def test_file_upload(self):
4645 # Assert
4746 assert response .status_code == 200 , "File upload failed."
4847
48+ def test_bulk_file_upload (self , create_mock_file ):
49+ """
50+ Test case for uploading bulk files to a dataset.
51+
52+ This test is meant to check the performance of the file upload feature
53+ and that nothing breaks when uploading multiple files in line.
54+
55+ This test case performs the following steps:
56+ 0. Create 50 mock files.
57+ 1. Creates a dataset using the provided metadata.
58+ 2. Prepares a file for upload.
59+ 3. Uploads the file to the dataset.
60+ 4. Asserts that the file upload was successful.
61+
62+ Raises:
63+ AssertionError: If the file upload fails.
64+
65+ """
66+ # Arrange
67+ BASE_URL = os .getenv ("BASE_URL" ).rstrip ("/" )
68+ API_TOKEN = os .getenv ("API_TOKEN" )
69+
70+ # Create dataset
71+ metadata = json .load (open ("tests/data/file_upload_ds_minimum.json" ))
72+ pid = self ._create_dataset (BASE_URL , API_TOKEN , metadata )
73+ api = NativeApi (BASE_URL , API_TOKEN )
74+
75+ with tempfile .TemporaryDirectory () as tmp_dir :
76+ # Create mock files
77+ mock_files = [
78+ create_mock_file (
79+ filename = f"mock_file_{ i } .txt" ,
80+ dir = tmp_dir ,
81+ size = 1024 ** 2 , # 1MB
82+ )
83+ for i in range (50 )
84+ ]
85+
86+ for mock_file in mock_files :
87+ # Prepare file upload
88+ df = Datafile ({"pid" : pid , "filename" : os .path .basename (mock_file )})
89+
90+ # Act
91+ response = api .upload_datafile (
92+ identifier = pid ,
93+ filename = mock_file ,
94+ json_str = df .json (),
95+ )
96+
97+ # Assert
98+ assert response .status_code == 200 , "File upload failed."
99+
49100 def test_file_replacement (self ):
50101 """
51102 Test case for replacing a file in a dataset.
@@ -56,7 +107,7 @@ def test_file_replacement(self):
56107 3. Replace the uploaded datafile with a mutated version.
57108 4. Verify that the file replacement was successful and the content matches the expected content.
58109 """
59-
110+
60111 # Arrange
61112 BASE_URL = os .getenv ("BASE_URL" ).rstrip ("/" )
62113 API_TOKEN = os .getenv ("API_TOKEN" )
@@ -79,7 +130,6 @@ def test_file_replacement(self):
79130
80131 # Act
81132 with tempfile .TemporaryDirectory () as tempdir :
82-
83133 original = open ("tests/data/replace.xyz" ).read ()
84134 mutated = "Z" + original [1 ::]
85135 mutated_path = os .path .join (tempdir , "replace.xyz" )
0 commit comments