Fix code formatting and linting issues
- Auto-format all Python files with black and isort - Remove unused imports with autoflake - Fix flake8 issues (missing newlines, blank lines, etc.) - Fix nonlocal/global scope issues in main.py - Fix security.py import order (E402) - Remove f-string without placeholders - Add nosec comment for intentional exception handling - Fix test imports to match refactored DMARCParser API Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -1,21 +1,16 @@
|
||||
import asyncio
|
||||
import os
|
||||
from typing import AsyncGenerator, Generator
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from app.core.database import Base, get_db
|
||||
from app.core.security import get_password_hash
|
||||
from app.models.user import User
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
from httpx import AsyncClient
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from app.core.config import get_settings
|
||||
from app.core.database import Base, get_db
|
||||
from app.core.security import get_password_hash
|
||||
from app.models.user import User
|
||||
|
||||
# Use in-memory SQLite database for tests
|
||||
TEST_DATABASE_URL = "sqlite:///./test.db"
|
||||
|
||||
@@ -32,7 +27,7 @@ def event_loop():
|
||||
def test_app() -> FastAPI:
|
||||
# Avoid circular import
|
||||
from app.main import create_app
|
||||
|
||||
|
||||
app = create_app()
|
||||
return app
|
||||
|
||||
@@ -41,14 +36,14 @@ def test_app() -> FastAPI:
|
||||
def db_session():
|
||||
# Create the SQLite database engine
|
||||
engine = create_engine(TEST_DATABASE_URL)
|
||||
|
||||
|
||||
# Create all tables
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
|
||||
# Create a new session
|
||||
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
db = TestingSessionLocal()
|
||||
|
||||
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
@@ -65,9 +60,9 @@ def client(test_app: FastAPI, db_session):
|
||||
yield db_session
|
||||
finally:
|
||||
pass
|
||||
|
||||
|
||||
test_app.dependency_overrides[get_db] = override_get_db
|
||||
|
||||
|
||||
# Use the FastAPI TestClient
|
||||
with TestClient(test_app) as test_client:
|
||||
yield test_client
|
||||
@@ -81,9 +76,9 @@ async def async_client(test_app: FastAPI, db_session):
|
||||
yield db_session
|
||||
finally:
|
||||
pass
|
||||
|
||||
|
||||
test_app.dependency_overrides[get_db] = override_get_db
|
||||
|
||||
|
||||
async with AsyncClient(app=test_app, base_url="http://testserver") as ac:
|
||||
yield ac
|
||||
|
||||
@@ -96,9 +91,9 @@ def test_user(db_session):
|
||||
hashed_password=get_password_hash("password"),
|
||||
is_active=True,
|
||||
is_superuser=False,
|
||||
is_verified=True
|
||||
is_verified=True,
|
||||
)
|
||||
db_session.add(user)
|
||||
db_session.commit()
|
||||
db_session.refresh(user)
|
||||
return user
|
||||
return user
|
||||
|
||||
Reference in New Issue
Block a user