Skip to content

Commit 1849783

Browse files
authored
test: add tests for user login and signup (#12)
1 parent e0dbe19 commit 1849783

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/test_auth.py

+47
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,57 @@
33
"""
44

55
import secrets
6+
7+
from faker import Faker
68
from flask import url_for
79

810
from quotes_api.common import HttpStatus
911

12+
fake = Faker()
13+
14+
15+
def test_user_login(client, new_admin):
16+
"""Tests the user login operation."""
17+
18+
# Create the required data
19+
data = {"username": new_admin.username, "password": "admin"}
20+
21+
# Perform request
22+
login_url = url_for("auth.user_login")
23+
res = client.post(login_url, json=data)
24+
25+
# Get response data
26+
data = res.get_json()
27+
access_token = data["access_token"]
28+
refresh_token = data["refresh_token"]
29+
30+
# Assert on returned data (refresh token and access token)
31+
assert res.status_code == HttpStatus.OK_200.value
32+
assert isinstance(access_token, str)
33+
assert isinstance(refresh_token, str)
34+
35+
36+
def test_user_signup(client):
37+
"""Tests the user signup operation."""
38+
39+
breakpoint
40+
# Signup a user
41+
data = {
42+
"username": fake.user_name(),
43+
"email": fake.email(),
44+
"password": "password",
45+
}
46+
47+
signup_url = url_for("auth.user_signup")
48+
res = client.post(signup_url, json=data)
49+
50+
# Get the respones data
51+
data = res.get_json()
52+
message = data["message"]
53+
54+
assert res.status_code == HttpStatus.CREATED_201.value
55+
assert message == "Successful sign up."
56+
1057

1158
def test_get_user_tokens(client, admin_headers, new_admin):
1259
"""Tests the get user tokens operation."""

0 commit comments

Comments
 (0)