Skip to content

Commit

Permalink
tests: add serializer test for empty record
Browse files Browse the repository at this point in the history
  • Loading branch information
rekt-hard authored and max-moser committed Sep 18, 2024
1 parent 7e5fde0 commit 8476188
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,19 @@ def minimal_record():
}


@pytest.fixture()
def empty_record():
"""Almost empty record data as dict coming from the external world."""
return {
"pids": {},
"access": {},
"files": {
"enabled": False, # Most tests don't care about files
},
"metadata": {},
}


@pytest.fixture()
def minimal_restricted_record(minimal_record):
"""Data for restricted record."""
Expand Down
11 changes: 11 additions & 0 deletions tests/resources/serializers/test_csl_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,14 @@ def test_citation_string_serializer_record(
# in case of error, the response is JSON
assert response.headers["content-type"] == "application/json"
assert f"Citation string style not found." in body


def test_citation_string_serializer_empty_record(running_app, empty_record):
"""Test Citation String Serializer for an empty record."""

expected_data = {}

serializer = CSLJSONSchema()
serialized_record = serializer.dump(empty_record)

assert serialized_record == expected_data
11 changes: 11 additions & 0 deletions tests/resources/serializers/test_datacite_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,14 @@ def test_datacite43_serializer_updated_date(running_app, full_modified_date_reco

assert expected_dates == serialized_record["dates"]
assert len(serialized_record["dates"]) == 3


def test_datacite43_serializer_empty_record(running_app, empty_record):
"""Test if the DataCite 4.3 JSON serializer handles an empty record."""

expected_data = {"schemaVersion": "http://datacite.org/schema/kernel-4"}

serializer = DataCite43JSONSerializer()
serialized_record = serializer.dump_obj(empty_record)

assert serialized_record == expected_data
11 changes: 11 additions & 0 deletions tests/resources/serializers/test_dublincore_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ def test_dublincorejson_serializer_minimal(running_app, updated_minimal_record):
assert serialized_record == expected_data


def test_dublincorejson_serializer_empty_record(running_app, empty_record):
"""Test serializer to Dublin Core JSON with an empty record"""

expected_data = {}

serializer = DublinCoreJSONSerializer()
serialized_record = serializer.dump_obj(empty_record)

assert serialized_record == expected_data


def test_vocabulary_type_error(running_app, updated_minimal_record):
"""Test error thrown on missing resource type."""
updated_minimal_record["metadata"]["resource_type"]["id"] = "invalid"
Expand Down
13 changes: 13 additions & 0 deletions tests/resources/serializers/test_schemaorg_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,16 @@ def test_schemaorg_serializer_minimal_record(running_app, minimal_record):
serialized_record = serializer.dump_obj(minimal_record)

assert serialized_record == expected_data


def test_schemaorg_serializer_empty_record(running_app, empty_record):
"""Test Schemaorg JSON-LD serializer with minimal record."""

expected_data = {
"@context": "http://schema.org",
}

serializer = SchemaorgJSONLDSerializer()
serialized_record = serializer.dump_obj(empty_record)

assert serialized_record == expected_data

0 comments on commit 8476188

Please sign in to comment.