- Remove |safe from |tojson in HTML attributes (x-data) - quotes must become " for browsers to parse correctly - Update LANG-002 and LANG-003 architecture rules to document correct |tojson usage patterns: - HTML attributes: |tojson (no |safe) - Script blocks: |tojson|safe - Fix validator to warn when |tojson|safe is used in x-data (breaks HTML attribute parsing) - Improve code quality across services, APIs, and tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
72 lines
1.8 KiB
Python
72 lines
1.8 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.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from models.database.customer import Customer, CustomerAddress
|
|
from models.database.order import Order
|
|
|
|
|
|
@pytest.fixture
|
|
def test_customer(db, test_vendor):
|
|
"""Create a test customer."""
|
|
customer = Customer(
|
|
vendor_id=test_vendor.id,
|
|
email="testcustomer@example.com",
|
|
hashed_password="hashed_password",
|
|
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_vendor, test_customer):
|
|
"""Create a test customer address."""
|
|
address = CustomerAddress(
|
|
vendor_id=test_vendor.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="Luxembourg",
|
|
is_default=True,
|
|
)
|
|
db.add(address)
|
|
db.commit()
|
|
db.refresh(address)
|
|
return address
|
|
|
|
|
|
@pytest.fixture
|
|
def test_order(db, test_vendor, test_customer, test_customer_address):
|
|
"""Create a test order."""
|
|
order = Order(
|
|
vendor_id=test_vendor.id,
|
|
customer_id=test_customer.id,
|
|
order_number="TEST-ORD-001",
|
|
status="pending",
|
|
subtotal=99.99,
|
|
total_amount=99.99,
|
|
currency="EUR",
|
|
shipping_address_id=test_customer_address.id,
|
|
billing_address_id=test_customer_address.id,
|
|
)
|
|
db.add(order)
|
|
db.commit()
|
|
db.refresh(order)
|
|
return order
|