dump-things-service/dump_things_service/tests/test_token_endpoints.py
Christian Monch fc3e398178
All checks were successful
Codespell / Check for spelling errors (push) Successful in 27s
Ruff / Code linting (push) Successful in 38s
Test execution / Test-all (push) Successful in 1m12s
fix: ensure that default tokens cannot be deleted
2026-07-15 13:12:14 +02:00

53 lines
1.6 KiB
Python

from starlette.status import HTTP_406_NOT_ACCEPTABLE, HTTP_409_CONFLICT
from dump_things_service import HTTP_201_CREATED
def test_token_creation(fastapi_client_simple):
test_client, _, admin_token = fastapi_client_simple
json_record = {
'name': 'a',
'user_id': 'u_a',
'representation': '8bb6805ff10bcb1c2ca49dcd4bfef94d',
'collections': {
'collection_1': {'mode': 'WRITE_COLLECTION', 'incoming_label': 'i_a'}
},
}
# Create a token with name 'a'
response = test_client.post(
'/tokens',
headers={'x-dumpthings-token': admin_token},
json=json_record,
)
assert response.status_code == HTTP_201_CREATED
# Try to create another token with name 'a', should result in a 4ß9-error
response = test_client.post(
'/tokens',
headers={'x-dumpthings-token': admin_token},
json=json_record,
)
assert response.status_code == HTTP_409_CONFLICT
# Try to create another token with name 'b' and the same representation
# as 'a', should result in a 4ß9-error
json_record['name'] = 'b'
response = test_client.post(
'/tokens',
headers={'x-dumpthings-token': admin_token},
json=json_record,
)
assert response.status_code == HTTP_409_CONFLICT
def test_default_token_removal(fastapi_client_simple):
test_client, _, admin_token = fastapi_client_simple
# Create a token with name 'a'
response = test_client.delete(
'/tokens/test_default_token',
headers={'x-dumpthings-token': admin_token},
)
assert response.status_code == HTTP_406_NOT_ACCEPTABLE