Skip to content

Commit

Permalink
refactor sign_up endpoint test, add log_in endpoint test
Browse files Browse the repository at this point in the history
  • Loading branch information
markparonyan committed May 14, 2024
1 parent 521a046 commit 6a71038
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion backend/api/auth/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

import pytest
from fastapi import Depends
from fastapi.testclient import TestClient

from main import app
Expand All @@ -17,4 +18,18 @@
def test_sign_up(fill_db, user: dict, status: int):
req = client.post('/api/sign-up', content=json.dumps(user))
assert req.status_code == status
assert 1 == 1


@pytest.mark.parametrize('user,status',
[
({'name': 'new_user', 'password': 'test', 'lifetime': 1}, 401),
({'name': 'existing_user', 'password': 'wrong_password', 'lifetime': 2}, 401),
({'name': 'existing_user', 'password': 'test', 'lifetime': 2}, 200),
({'name': 'bad_user', 'pass': 'test'}, 422),
])
def test_log_in(db_connection, fill_db, user: dict, status: int):
token_model = db_connection[1].fetch_token_by_username(next(db_connection[1].get_db())
, user.get('name'))
client.cookies = {'access_token': token_model and token_model.token}
req = client.post('/api/login', content=json.dumps(user))
assert req.status_code == status

0 comments on commit 6a71038

Please sign in to comment.