userver: samples/postgres_auth/tests/test_postgres.py
Loading...
Searching...
No Matches
samples/postgres_auth/tests/test_postgres.py
1# /// [Functional test]
2import pytest
3
4
5@pytest.mark.pgsql('auth', files=['test_data.sql'])
6async def test_postgres(service_client):
7 response = await service_client.get('/v1/hello')
8 assert response.status == 401
9 assert response.content == b'Empty \'Authorization\' header'
10
11 response = await service_client.get(
12 '/v1/hello', headers={'Authorization': 'Bearer THE_USER_TOKEN'},
13 )
14 assert response.status == 200
15 assert response.content == b'Hello world, Dear User!\n'
16 # /// [Functional test]
17
18 response = await service_client.get(
19 '/v1/hello', headers={'Authorization': 'wrong format'},
20 )
21 assert response.status == 401
22 assert b'Bearer some-token' in response.content
23
24 response = await service_client.get(
25 '/v1/hello', headers={'Authorization': 'wrong'},
26 )
27 assert response.status == 401
28 assert b'Bearer some-token' in response.content
29
30 response = await service_client.get(
31 '/v1/hello', headers={'Authorization': 'Bearer wrong-token'},
32 )
33 assert response.status == 403
34
35 response = await service_client.get(
36 '/v1/hello', headers={'Authorization': 'Bearer '},
37 )
38 assert response.status == 403
39
40 response = await service_client.get(
41 '/v1/hello', headers={'Authorization': 'Bearer wrong-scopes-token'},
42 )
43 assert response.status == 403