dump-things-server/dump_things_service/tests/test_token_endpoints.py
Christian Monch 2053997b53 return admin_token in test fixture
The test-fixture `fast_api_simple` now
returns a tuple containing:

- test_client instance
- store path
- admin token
2026-06-12 12:41:54 +02:00

45 lines
1.3 KiB
Python

from starlette.status import 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 eith 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 eith 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