diff --git a/.github/workflows/python-app.yml b/.github/workflows/backend-tests.yml similarity index 88% rename from .github/workflows/python-app.yml rename to .github/workflows/backend-tests.yml index 9f16b12..39a96a6 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/backend-tests.yml @@ -54,8 +54,4 @@ jobs: - name: Run tests with coverage run: | cd backend - uv run pytest --cov=app tests/ --cov-report=term-missing --cov-fail-under=60 - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v4 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file + uv run pytest --cov=app tests/ --cov-report=term-missing --cov-fail-under=60 \ No newline at end of file diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index 9b35f95..69ad5af 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -1,11 +1,12 @@ import os import uuid -import pytest from datetime import datetime, timedelta + +import pytest +from app import create_app, db +from app.models import Cart, Product, User from sqlalchemy import create_engine, text from sqlalchemy.orm import scoped_session, sessionmaker -from app import create_app, db -from app.models import User, Product, Cart, Order from werkzeug.security import generate_password_hash @@ -40,11 +41,15 @@ def _create_test_db(): class TestConfig: """Test configuration.""" + TESTING = True - SQLALCHEMY_DATABASE_URI = f"postgresql://postgres:postgres@{get_database_host()}:5432/pharmacy_test_db" + SQLALCHEMY_DATABASE_URI = ( + f"postgresql://postgres:postgres@{get_database_host()}:5432/pharmacy_test_db" + ) SQLALCHEMY_TRACK_MODIFICATIONS = False SECRET_KEY = "test_secret_key" TOKEN_SECRET_KEY = "test_token_secret_key" * 2 + FRONTEND_URL = "http://localhost:8081" MAIL_SERVER = "localhost" MAIL_PORT = 25 MAIL_USE_TLS = False @@ -107,7 +112,10 @@ def test_user(db_session): email = f"test_{unique_id[:8]}@example.com" user = User( - username=username, email=email, password=generate_password_hash("Test123!") + username=username, + email=email, + password=generate_password_hash("Test123!"), + email_verified=True, ) db_session.add(user) db_session.commit() diff --git a/backend/tests/test_auth.py b/backend/tests/test_auth.py index 46660e2..30e5a29 100644 --- a/backend/tests/test_auth.py +++ b/backend/tests/test_auth.py @@ -1,22 +1,27 @@ -import pytest +from unittest.mock import patch + from flask import json def test_register_success(client): """Test successful user registration.""" - response = client.post( - "/api/auth/register", - json={ - "username": "newuser", - "email": "newuser@example.com", - "password": "TestPass123!", - }, - ) - assert response.status_code == 201 - data = json.loads(response.data) - assert "user" in data - assert data["user"]["username"] == "newuser" - assert data["user"]["email"] == "newuser@example.com" + with patch("app.routes.auth.send_verification_email") as mock_email: + mock_email.return_value = True + + response = client.post( + "/api/auth/register", + json={ + "username": "newuser", + "email": "newuser@example.com", + "password": "TestPass123!", + }, + ) + assert response.status_code == 201 + data = json.loads(response.data) + assert "user" in data + assert data["user"]["username"] == "newuser" + assert data["user"]["email"] == "newuser@example.com" + assert not data["user"]["email_verified"] def test_register_duplicate_username(client, test_user): @@ -70,7 +75,7 @@ def test_login_success(client, test_user): "/api/auth/login", json={ "username": test_user.username, - "password": "Test123!", # Must match the password set in test_user fixture + "password": "Test123!", }, ) assert response.status_code == 200