Skip to content

Commit 6a71038

Browse files
committed
refactor sign_up endpoint test, add log_in endpoint test
1 parent 521a046 commit 6a71038

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

backend/api/auth/test_auth.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22

33
import pytest
4+
from fastapi import Depends
45
from fastapi.testclient import TestClient
56

67
from main import app
@@ -17,4 +18,18 @@
1718
def test_sign_up(fill_db, user: dict, status: int):
1819
req = client.post('/api/sign-up', content=json.dumps(user))
1920
assert req.status_code == status
20-
assert 1 == 1
21+
22+
23+
@pytest.mark.parametrize('user,status',
24+
[
25+
({'name': 'new_user', 'password': 'test', 'lifetime': 1}, 401),
26+
({'name': 'existing_user', 'password': 'wrong_password', 'lifetime': 2}, 401),
27+
({'name': 'existing_user', 'password': 'test', 'lifetime': 2}, 200),
28+
({'name': 'bad_user', 'pass': 'test'}, 422),
29+
])
30+
def test_log_in(db_connection, fill_db, user: dict, status: int):
31+
token_model = db_connection[1].fetch_token_by_username(next(db_connection[1].get_db())
32+
, user.get('name'))
33+
client.cookies = {'access_token': token_model and token_model.token}
34+
req = client.post('/api/login', content=json.dumps(user))
35+
assert req.status_code == status

0 commit comments

Comments
 (0)