53 lines
1.6 KiB
Python
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
|