|
3 | 3 | """
|
4 | 4 |
|
5 | 5 | import secrets
|
| 6 | + |
| 7 | +from faker import Faker |
6 | 8 | from flask import url_for
|
7 | 9 |
|
8 | 10 | from quotes_api.common import HttpStatus
|
9 | 11 |
|
| 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 | + |
10 | 57 |
|
11 | 58 | def test_get_user_tokens(client, admin_headers, new_admin):
|
12 | 59 | """Tests the get user tokens operation."""
|
|
0 commit comments