dump-things-service/dump_things_service/tests/test_validate.py
Michael Hanke c332abbd1b
Some checks failed
Codespell / Check for spelling errors (push) Successful in 42s
Codespell / Check for spelling errors (pull_request) Successful in 43s
Ruff / Code linting (push) Failing after 52s
Ruff / Code linting (pull_request) Failing after 54s
Test execution / Test-all (push) Successful in 1m27s
Type annotation (PR) / check (pull_request) Failing after 1m30s
chore: auto-apply code formatting fixes via hatch check fmt --fix
2026-06-30 20:41:05 +02:00

65 lines
1.7 KiB
Python

from dump_things_service import HTTP_422_UNPROCESSABLE_CONTENT
json_records = [
({'name': 'Henry', 'pid': 'unknown_prefix:henry'}, HTTP_422_UNPROCESSABLE_CONTENT),
(
{'given_name': 'Henry', 'pid': 'unknown_prefix:henry'},
HTTP_422_UNPROCESSABLE_CONTENT,
),
({'given_name': 'Henry', 'pid': 'xyz:henry'}, 200),
]
ttl_records = [
(
"""
@prefix abc: <http://example.org/person-schema/abc/> .
@prefix xyz: <https://www.example.com/xyz/> .
xyz:henry a abc:Person ;
abc:given_name "Henry" .
""",
200,
),
(
# Faulty class id
"""
@prefix abc: <http://example.org/person-schema/abc/> .
@prefix xyz: <https://www.example.com/xyz/> .
xyz:henry a xyz:Person ;
abc:given_name "Henry" .
""",
422,
),
(
# Faulty attribute id
"""
@prefix abc: <http://example.org/person-schema/abc/> .
@prefix xyz: <https://www.example.com/xyz/> .
xyz:henry a abc:Person ;
xyz:given_name "Henry" .
""",
422,
),
]
def test_validate_record(fastapi_client_simple):
test_client, _, _ = fastapi_client_simple
for record, expected_status in json_records:
response = test_client.post(
'/collection_1/validate/record/Person',
headers={'x-dumpthings-token': 'token-1'},
json=record,
)
assert response.status_code == expected_status
for record, expected_status in ttl_records:
response = test_client.post(
'/collection_1/validate/record/Person?format=ttl',
headers={'x-dumpthings-token': 'token-1'},
json=record,
)
assert response.status_code == expected_status