All checks were successful
- Add centralized _is_noqa_suppressed() to BaseValidator with normalization (accepts both SEC001 and SEC-001 formats for ruff compatibility) - Wire noqa support into all 21 security and 18 performance check functions - Add ruff external config for SEC/PERF/MOD/EXC codes in pyproject.toml - Convert all 280 Python noqa comments to dashless format (ruff-compatible) - Add site/ to IGNORE_PATTERNS (excludes mkdocs build output) - Suppress 152 false positive findings (test passwords, seed data, validator self-references, Apple Wallet SHA1, etc.) - Security: 79 errors → 0, 60 warnings → 0 - Performance: 80 warnings → 77 (3 test script suppressions) - Add proposal doc with noqa inventory and remaining findings recommendations Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
# tests/fixtures/testing_fixtures.py
|
|
"""
|
|
Testing utility fixtures for edge cases and error handling.
|
|
|
|
This module provides fixtures for:
|
|
- Empty database sessions for edge case testing
|
|
- Mock database sessions for error simulation
|
|
- Additional testing utilities
|
|
"""
|
|
|
|
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
from sqlalchemy.exc import SQLAlchemyError
|
|
|
|
|
|
@pytest.fixture
|
|
def empty_db(db):
|
|
"""Empty database session for edge case testing"""
|
|
from sqlalchemy import text
|
|
|
|
# Clear only the tables that are relevant for admin service testing
|
|
# In order to respect foreign key constraints
|
|
tables_to_clear = [
|
|
"marketplace_import_jobs", # Has foreign keys to stores and users
|
|
"products", # Has foreign keys to stores and products
|
|
"inventory", # Fixed: singular not plural
|
|
"products", # Referenced by products
|
|
"stores", # Has foreign key to users
|
|
"users", # Base table
|
|
]
|
|
|
|
for table in tables_to_clear:
|
|
try:
|
|
db.execute(text(f"DELETE FROM {table}")) # noqa: SEC011
|
|
except Exception:
|
|
# If table doesn't exist or delete fails, continue
|
|
pass
|
|
|
|
db.commit()
|
|
return db
|
|
|
|
|
|
@pytest.fixture
|
|
def db_with_error():
|
|
"""Database session that raises errors for testing error handling"""
|
|
mock_db = Mock()
|
|
|
|
# Configure the mock to raise SQLAlchemy errors on query operations
|
|
mock_db.query.side_effect = SQLAlchemyError("Database connection failed")
|
|
mock_db.add.side_effect = SQLAlchemyError("Database insert failed")
|
|
mock_db.commit.side_effect = SQLAlchemyError("Database commit failed")
|
|
mock_db.rollback.return_value = None
|
|
|
|
return mock_db
|