Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/storage/test_storage.py
Show First 20 Lines • Show All 520 Lines • ▼ Show 20 Lines | example_data = [ | ||||
}, | }, | ||||
}, | }, | ||||
{ | { | ||||
"metadata": {"other": {}, "name": "test_metadata", "version": "0.0.1"}, | "metadata": {"other": {}, "name": "test_metadata", "version": "0.0.1"}, | ||||
}, | }, | ||||
] | ] | ||||
row_class = ContentMetadataRow | row_class = ContentMetadataRow | ||||
def test_add_with_null( | |||||
self, swh_indexer_storage_with_data: Tuple[IndexerStorageInterface, Any] | |||||
) -> None: | |||||
storage, data = swh_indexer_storage_with_data | |||||
etype = self.endpoint_type | |||||
tool = data.tools[self.tool_name] | |||||
# conftest fills it with mimetypes | |||||
storage.journal_writer.journal.objects = [] # type: ignore | |||||
query = [data.sha1_2, data.sha1_1] | |||||
data1 = self.row_class.from_dict( | |||||
{ | |||||
"id": data.sha1_2, | |||||
"metadata": {"description": "with\u0000nul"}, | |||||
"indexer_configuration_id": tool["id"], | |||||
} | |||||
) | |||||
# when | |||||
summary = endpoint(storage, etype, "add")([data1]) | |||||
assert summary == expected_summary(1, etype) | |||||
# then | |||||
actual_data = list(endpoint(storage, etype, "get")(query)) | |||||
# then | |||||
expected_data_postgresql = [ | |||||
self.row_class.from_dict( | |||||
{ | |||||
"id": data.sha1_2, | |||||
"metadata": {"description": "withnul"}, | |||||
"tool": tool, | |||||
} | |||||
) | |||||
] | |||||
expected_data_verbatim = [ | |||||
self.row_class.from_dict( | |||||
{ | |||||
"id": data.sha1_2, | |||||
"metadata": {"description": "with\u0000nul"}, | |||||
"tool": tool, | |||||
} | |||||
) | |||||
] | |||||
assert actual_data in (expected_data_postgresql, expected_data_verbatim) | |||||
journal_objects = storage.journal_writer.journal.objects # type: ignore | |||||
actual_journal_data = [ | |||||
obj for (obj_type, obj) in journal_objects if obj_type == self.endpoint_type | |||||
] | |||||
assert list(sorted(actual_journal_data)) == list(sorted(expected_data_verbatim)) | |||||
class TestIndexerStorageDirectoryIntrinsicMetadata(StorageETypeTester): | class TestIndexerStorageDirectoryIntrinsicMetadata(StorageETypeTester): | ||||
"""Test Indexer Storage directory_intrinsic_metadata related methods""" | """Test Indexer Storage directory_intrinsic_metadata related methods""" | ||||
tool_name = "swh-metadata-detector" | tool_name = "swh-metadata-detector" | ||||
endpoint_type = "directory_intrinsic_metadata" | endpoint_type = "directory_intrinsic_metadata" | ||||
example_data = [ | example_data = [ | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,272 Lines • Show Last 20 Lines |