dump-things-service/dump_things_service/tests/test_canonical.py
2026-07-03 16:00:04 +02:00

56 lines
1.7 KiB
Python

from pathlib import Path
from dump_things_service import HTTP_200_OK
from dump_things_service.abstract_config import (
MappingMethod,
mapping_functions,
)
def test_canonicalization(fastapi_client_simple):
test_client, store_path, _admin_token = fastapi_client_simple
pid = 'http://example.com/test_canonicalization/1'
record_a = {
'pid': pid,
'given_name': 'Alice',
}
record_b = {
'given_name': 'Bob',
'pid': pid,
}
# Ensure that the two records are represented in the same order on disk.
# (The current implementation should guarantee that because the pydantic
# objects that are instantiated from the JSON input have a fixed order
# of attributes. Once the implementation is changed, this test here might
# catch regressions).
file_content = []
for record in (record_a, record_b):
response = test_client.post(
'/collection_1/record/Person',
headers={'x-dumpthings-token': 'token-1'},
json=record,
)
assert response.status_code == HTTP_200_OK
file_content.append(
_get_record_dir_record(
store_path,
'incoming/collection_1/in_token_1/Person',
pid,
MappingMethod.digest_md5,
),
)
assert file_content[0] == file_content[1].replace('Bob', 'Alice')
def _get_record_dir_record(
store_path: Path,
path_part: str | Path,
pid: str,
mapping_method: MappingMethod,
) -> str:
file_name = mapping_functions[mapping_method](pid, 'yaml')
with (store_path / path_part / file_name).open('rt') as f:
return f.read()