Skip to content

Commit

Permalink
add test case where json_str is set to None
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Jul 30, 2024
1 parent 8e0a521 commit f148ef3
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions tests/api/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,41 @@ def test_file_upload(self):
# Assert
assert response.status_code == 200, "File upload failed."

def test_file_upload_without_metadata(self):
"""
Test case for uploading a file to a dataset without metadata.
--> json_str will be set as None
This test case performs the following steps:
1. Creates a dataset using the provided metadata.
2. Prepares a file for upload.
3. Uploads the file to the dataset.
4. Asserts that the file upload was successful.
Raises:
AssertionError: If the file upload fails.
"""
# Arrange
BASE_URL = os.getenv("BASE_URL").rstrip("/")
API_TOKEN = os.getenv("API_TOKEN")

# Create dataset
metadata = json.load(open("tests/data/file_upload_ds_minimum.json"))
pid = self._create_dataset(BASE_URL, API_TOKEN, metadata)
api = NativeApi(BASE_URL, API_TOKEN)

# Act
response = api.upload_datafile(
identifier=pid,
filename="tests/data/datafile.txt",
json_str=None,
)

# Assert
assert response.status_code == 200, "File upload failed."

def test_bulk_file_upload(self, create_mock_file):
"""
Test case for uploading bulk files to a dataset.
Expand Down Expand Up @@ -161,9 +196,13 @@ def test_file_replacement(self):
replaced_id,
)

assert data_file["description"] == "My description.", "Description does not match."
assert (
data_file["description"] == "My description."
), "Description does not match."
assert data_file["categories"] == ["Data"], "Categories do not match."
assert file_metadata["directoryLabel"] == "some/other", "Directory label does not match."
assert (
file_metadata["directoryLabel"] == "some/other"
), "Directory label does not match."
assert response.status_code == 200, "File replacement failed."
assert (
replaced_content == mutated
Expand Down Expand Up @@ -253,7 +292,6 @@ def _fetch_datafile_content(

return response.content.decode("utf-8")


@staticmethod
def _get_file_metadata(
BASE_URL: str,
Expand Down

0 comments on commit f148ef3

Please sign in to comment.