dump-things-service/dump_things_service/tests/test_web_interface.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

84 lines
2.7 KiB
Python

"""Faulty input test for the Web interface"""
from itertools import product
import pytest
from .. import HTTP_500_INTERNAL_SERVER_ERROR
collection_names = ('collection_1', 'xasdasd', '../../../abc')
class_names = ('Person', 'Mosdlkjsdfnmxcfd', '../../../abc')
queries = ('format', 'somerslkhjsdfsdf')
format_names = ('json', 'ttl', 'sdfsdfkjsdkfsd')
pids = ('', '--------', '&&&&&', 'abc', 'abc&', 'abc&format=ttl')
@pytest.mark.parametrize(
'collection_name,class_name,query,format_name', # noqa: PT006
tuple(product(*(collection_names, class_names, queries, format_names))),
)
def test_web_interface_post_errors(
fastapi_client_simple,
collection_name,
class_name,
query,
format_name,
):
"""Check that no internal server error occurs with weird input"""
test_client, _, _ = fastapi_client_simple
result = test_client.post(
f'/{collection_name}/record/{class_name}?{query}={format_name}',
headers={'x-dumpthings-token': 'token-all'},
json={'pid': 'xyz:web_interface_test_pid0x123123'},
)
assert result.status_code < HTTP_500_INTERNAL_SERVER_ERROR
@pytest.mark.parametrize(
'collection_name,class_name,query,format_name', # noqa: PT006
tuple(product(*(collection_names, class_names, queries, format_names))),
)
def test_web_interface_get_class_errors(
fastapi_client_simple,
collection_name,
class_name,
query,
format_name,
):
"""Check that no internal server error occurs with weird input"""
test_client, _, _ = fastapi_client_simple
result = test_client.get(
f'/{collection_name}/records/{class_name}?{query}={format_name}',
)
assert result.status_code < HTTP_500_INTERNAL_SERVER_ERROR
result = test_client.get(
f'/{collection_name}/record/{class_name}?{query}={format_name}',
headers={'x-dumpthings-token': 'token-all'},
)
assert result.status_code < HTTP_500_INTERNAL_SERVER_ERROR
@pytest.mark.parametrize(
'collection_name,pid,query,format_name', # noqa: PT006
tuple(product(*(collection_names, pids, queries, format_names))),
)
def test_web_interface_get_pid_errors(
fastapi_client_simple,
collection_name,
pid,
query,
format_name,
):
"""Check that no internal server error occurs with weird input"""
test_client, _, _ = fastapi_client_simple
result = test_client.get(
f'/{collection_name}/records?{pid}&{query}={format_name}',
)
assert result.status_code < HTTP_500_INTERNAL_SERVER_ERROR
result = test_client.get(
f'/{collection_name}/records?{pid}&{query}={format_name}',
headers={'x-dumpthings-token': 'token-all'},
)
assert result.status_code < HTTP_500_INTERNAL_SERVER_ERROR