Files
orion/tests/fixtures/customer_fixtures.py
Samir Boulahtit 1b8a40f1ff
All checks were successful
CI / dependency-scanning (push) Successful in 27s
CI / docs (push) Successful in 35s
CI / ruff (push) Successful in 8s
CI / pytest (push) Successful in 34m22s
CI / validate (push) Successful in 19s
CI / deploy (push) Successful in 2m25s
feat(validators): add noqa suppression support to security and performance validators
- 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>
2026-02-14 22:56:56 +01:00

165 lines
4.7 KiB
Python

# tests/fixtures/customer_fixtures.py
"""
Customer-related test fixtures.
Note: Fixtures should NOT use db.expunge() as it breaks lazy loading.
See tests/conftest.py for details on fixture best practices.
"""
from datetime import UTC
import pytest
from app.modules.customers.models.customer import Customer, CustomerAddress
from app.modules.orders.models import Order
@pytest.fixture
def test_customer(db, test_store):
"""Create a test customer."""
customer = Customer(
store_id=test_store.id,
email="testcustomer@example.com",
hashed_password="hashed_password", # noqa: SEC001
first_name="John",
last_name="Doe",
customer_number="TEST001",
is_active=True,
)
db.add(customer)
db.commit()
db.refresh(customer)
return customer
@pytest.fixture
def test_customer_address(db, test_store, test_customer):
"""Create a test customer shipping address."""
address = CustomerAddress(
store_id=test_store.id,
customer_id=test_customer.id,
address_type="shipping",
first_name="John",
last_name="Doe",
address_line_1="123 Main St",
city="Luxembourg",
postal_code="L-1234",
country_name="Luxembourg",
country_iso="LU",
is_default=True,
)
db.add(address)
db.commit()
db.refresh(address)
return address
@pytest.fixture
def test_customer_billing_address(db, test_store, test_customer):
"""Create a test customer billing address."""
address = CustomerAddress(
store_id=test_store.id,
customer_id=test_customer.id,
address_type="billing",
first_name="John",
last_name="Doe",
merchant="Test Merchant S.A.",
address_line_1="456 Business Ave",
city="Luxembourg",
postal_code="L-5678",
country_name="Luxembourg",
country_iso="LU",
is_default=True,
)
db.add(address)
db.commit()
db.refresh(address)
return address
@pytest.fixture
def test_customer_multiple_addresses(db, test_store, test_customer):
"""Create multiple addresses for testing limits and listing."""
addresses = []
for i in range(3):
address = CustomerAddress(
store_id=test_store.id,
customer_id=test_customer.id,
address_type="shipping" if i % 2 == 0 else "billing",
first_name=f"Name{i}",
last_name="Test",
address_line_1=f"{i}00 Test Street",
city="Luxembourg",
postal_code=f"L-{1000+i}",
country_name="Luxembourg",
country_iso="LU",
is_default=(i == 0),
)
db.add(address)
addresses.append(address)
db.commit()
for addr in addresses:
db.refresh(addr)
return addresses
@pytest.fixture
def test_order(db, test_store, test_customer, test_customer_address):
"""Create a test order with customer/address snapshots."""
from datetime import datetime
order = Order(
store_id=test_store.id,
customer_id=test_customer.id,
order_number="TEST-ORD-001",
status="pending",
channel="direct",
subtotal=99.99,
total_amount=99.99,
currency="EUR",
order_date=datetime.now(UTC),
# Customer snapshot
customer_first_name=test_customer.first_name,
customer_last_name=test_customer.last_name,
customer_email=test_customer.email,
customer_phone=None,
# Shipping address snapshot
ship_first_name=test_customer_address.first_name,
ship_last_name=test_customer_address.last_name,
ship_address_line_1=test_customer_address.address_line_1,
ship_city=test_customer_address.city,
ship_postal_code=test_customer_address.postal_code,
ship_country_iso="LU",
# Billing address snapshot
bill_first_name=test_customer_address.first_name,
bill_last_name=test_customer_address.last_name,
bill_address_line_1=test_customer_address.address_line_1,
bill_city=test_customer_address.city,
bill_postal_code=test_customer_address.postal_code,
bill_country_iso="LU",
)
db.add(order)
db.commit()
db.refresh(order)
return order
@pytest.fixture
def test_order_item(db, test_order, test_product):
"""Create a test order item."""
from app.modules.orders.models import OrderItem
order_item = OrderItem(
order_id=test_order.id,
product_id=test_product.id,
product_name="Test Product",
product_sku="TEST-SKU-001",
quantity=1,
unit_price=49.99,
total_price=49.99,
)
db.add(order_item)
db.commit()
db.refresh(order_item)
return order_item