|
1 | | -from datetime import datetime, timedelta |
2 | | - |
3 | | -import jwt |
4 | 1 | import pytest |
5 | | -import pytest_asyncio |
6 | 2 | from loguru import logger as log |
7 | 3 |
|
8 | | -from app.config import settings |
9 | 4 | from app.users.user_deps import create_reset_password_token |
10 | 5 |
|
11 | 6 |
|
12 | | -@pytest_asyncio.fixture(scope="function") |
13 | | -def token(auth_user): |
14 | | - """Create a reset password token for a given user.""" |
15 | | - payload = { |
16 | | - "sub": auth_user.email_address, |
17 | | - "exp": datetime.utcnow() |
18 | | - + timedelta(minutes=settings.RESET_PASSWORD_TOKEN_EXPIRE_MINUTES), |
19 | | - } |
20 | | - return jwt.encode(payload, settings.SECRET_KEY, algorithm=settings.ALGORITHM) |
| 7 | +@pytest.mark.asyncio |
| 8 | +async def test_my_info(client): |
| 9 | + """Test the /my-info/ endpoint to ensure a logged-in user can fetch their data.""" |
| 10 | + response = await client.get("/api/users/my-info/") |
| 11 | + assert response.status_code == 200 |
| 12 | + user_info = response.json() |
| 13 | + |
| 14 | + assert user_info["email_address"] == "admin@hotosm.org" |
| 15 | + |
| 16 | + |
| 17 | +@pytest.mark.asyncio |
| 18 | +async def test_refresh_token(client): |
| 19 | + """Test the /refresh-token endpoint to ensure a new access token can be obtained.""" |
| 20 | + response = await client.get("/api/users/refresh-token") |
| 21 | + assert response.status_code == 200 |
| 22 | + token_data = response.json() |
| 23 | + assert "access_token" in token_data |
| 24 | + assert "refresh_token" in token_data |
21 | 25 |
|
22 | 26 |
|
23 | 27 | @pytest.mark.asyncio |
24 | 28 | async def test_reset_password_success(client, auth_user): |
25 | 29 | """Test successful password reset using a valid token.""" |
26 | | - token = create_reset_password_token(auth_user.email_address) |
| 30 | + token = create_reset_password_token(auth_user.email) |
27 | 31 | new_password = "QPassword@12334" |
28 | 32 |
|
29 | 33 | response = await client.post( |
|
0 commit comments