Linted and formatted all files

This commit is contained in:
2025-05-28 21:52:39 -05:00
parent e46f13930d
commit 02913c7385
31 changed files with 1264 additions and 766 deletions

View File

@@ -1,34 +1,35 @@
from unittest.mock import patch
import pytest
from fastapi.testclient import TestClient
from fastapi import HTTPException, status
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
@pytest.fixture
def mock_successful_auth():
return {
"AccessToken": "mock_access_token",
"IdToken": "mock_id_token",
"RefreshToken": "mock_refresh_token"
"RefreshToken": "mock_refresh_token",
}
@pytest.fixture
def mock_successful_auth_no_refresh():
return {
"AccessToken": "mock_access_token",
"IdToken": "mock_id_token"
}
return {"AccessToken": "mock_access_token", "IdToken": "mock_id_token"}
def test_signin_success(mock_successful_auth):
"""Test successful signin with all tokens"""
with patch('app.routers.auth.initiate_auth', return_value=mock_successful_auth):
with patch("app.routers.auth.initiate_auth", return_value=mock_successful_auth):
response = client.post(
"/auth/signin",
json={"username": "testuser", "password": "testpass"}
"/auth/signin", json={"username": "testuser", "password": "testpass"}
)
assert response.status_code == 200
data = response.json()
assert data["access_token"] == "mock_access_token"
@@ -36,14 +37,16 @@ def test_signin_success(mock_successful_auth):
assert data["refresh_token"] == "mock_refresh_token"
assert data["token_type"] == "Bearer"
def test_signin_success_no_refresh(mock_successful_auth_no_refresh):
"""Test successful signin without refresh token"""
with patch('app.routers.auth.initiate_auth', return_value=mock_successful_auth_no_refresh):
with patch(
"app.routers.auth.initiate_auth", return_value=mock_successful_auth_no_refresh
):
response = client.post(
"/auth/signin",
json={"username": "testuser", "password": "testpass"}
"/auth/signin", json={"username": "testuser", "password": "testpass"}
)
assert response.status_code == 200
data = response.json()
assert data["access_token"] == "mock_access_token"
@@ -51,57 +54,48 @@ def test_signin_success_no_refresh(mock_successful_auth_no_refresh):
assert data["refresh_token"] is None
assert data["token_type"] == "Bearer"
def test_signin_invalid_input():
"""Test signin with invalid input format"""
# Missing password
response = client.post(
"/auth/signin",
json={"username": "testuser"}
)
response = client.post("/auth/signin", json={"username": "testuser"})
assert response.status_code == 422
# Missing username
response = client.post(
"/auth/signin",
json={"password": "testpass"}
)
response = client.post("/auth/signin", json={"password": "testpass"})
assert response.status_code == 422
# Empty payload
response = client.post(
"/auth/signin",
json={}
)
response = client.post("/auth/signin", json={})
assert response.status_code == 422
def test_signin_auth_failure():
"""Test signin with authentication failure"""
with patch('app.routers.auth.initiate_auth') as mock_auth:
with patch("app.routers.auth.initiate_auth") as mock_auth:
mock_auth.side_effect = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid username or password"
detail="Invalid username or password",
)
response = client.post(
"/auth/signin",
json={"username": "testuser", "password": "wrongpass"}
"/auth/signin", json={"username": "testuser", "password": "wrongpass"}
)
assert response.status_code == 401
data = response.json()
assert data["detail"] == "Invalid username or password"
def test_signin_user_not_found():
"""Test signin with non-existent user"""
with patch('app.routers.auth.initiate_auth') as mock_auth:
with patch("app.routers.auth.initiate_auth") as mock_auth:
mock_auth.side_effect = HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="User not found"
status_code=status.HTTP_404_NOT_FOUND, detail="User not found"
)
response = client.post(
"/auth/signin",
json={"username": "nonexistent", "password": "testpass"}
"/auth/signin", json={"username": "nonexistent", "password": "testpass"}
)
assert response.status_code == 404
data = response.json()
assert data["detail"] == "User not found"
assert data["detail"] == "User not found"