fix: correct tojson|safe usage in templates and update validator

- 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>
This commit is contained in:
2025-12-13 22:59:51 +01:00
parent 94d268f330
commit 9920430b9e
123 changed files with 1408 additions and 840 deletions

View File

@@ -1,5 +1,6 @@
# tests/unit/models/database/test_customer.py
"""Unit tests for Customer and CustomerAddress database models."""
import pytest
from models.database.customer import Customer, CustomerAddress

View File

@@ -1,5 +1,6 @@
# tests/unit/models/database/test_inventory.py
"""Unit tests for Inventory database model."""
import pytest
from sqlalchemy.exc import IntegrityError
@@ -56,7 +57,9 @@ class TestInventoryModel:
db.add(inventory2)
db.commit()
def test_inventory_same_product_different_location(self, db, test_vendor, test_product):
def test_inventory_same_product_different_location(
self, db, test_vendor, test_product
):
"""Test same product can have inventory in different locations."""
inventory1 = Inventory(
product_id=test_product.id,

View File

@@ -1,5 +1,6 @@
# tests/unit/models/database/test_marketplace_import_job.py
"""Unit tests for MarketplaceImportJob database model."""
import pytest
from models.database.marketplace_import_job import MarketplaceImportJob
@@ -58,7 +59,13 @@ class TestMarketplaceImportJobModel:
def test_import_job_status_values(self, db, test_user, test_vendor):
"""Test MarketplaceImportJob with different status values."""
statuses = ["pending", "processing", "completed", "failed", "completed_with_errors"]
statuses = [
"pending",
"processing",
"completed",
"failed",
"completed_with_errors",
]
for i, status in enumerate(statuses):
import_job = MarketplaceImportJob(

View File

@@ -1,10 +1,13 @@
# tests/unit/models/database/test_marketplace_product.py
"""Unit tests for MarketplaceProduct database model."""
import pytest
from sqlalchemy.exc import IntegrityError
from models.database.marketplace_product import MarketplaceProduct
from models.database.marketplace_product_translation import MarketplaceProductTranslation
from models.database.marketplace_product_translation import (
MarketplaceProductTranslation,
)
def _create_with_translation(db, marketplace_product_id, title, **kwargs):

View File

@@ -1,5 +1,6 @@
# tests/unit/models/database/test_order.py
"""Unit tests for Order and OrderItem database models."""
import pytest
from sqlalchemy.exc import IntegrityError
@@ -74,7 +75,14 @@ class TestOrderModel:
self, db, test_vendor, test_customer, test_customer_address
):
"""Test Order with different status values."""
statuses = ["pending", "confirmed", "processing", "shipped", "delivered", "cancelled"]
statuses = [
"pending",
"confirmed",
"processing",
"shipped",
"delivered",
"cancelled",
]
for i, status in enumerate(statuses):
order = Order(
@@ -93,9 +101,7 @@ class TestOrderModel:
assert order.status == status
def test_order_amounts(
self, db, test_vendor, test_customer, test_customer_address
):
def test_order_amounts(self, db, test_vendor, test_customer, test_customer_address):
"""Test Order amount fields."""
order = Order(
vendor_id=test_vendor.id,

View File

@@ -1,5 +1,6 @@
# tests/unit/models/database/test_product.py
"""Unit tests for Product (vendor catalog) database model."""
import pytest
from sqlalchemy.exc import IntegrityError
@@ -35,10 +36,9 @@ class TestProductModel:
assert product.is_featured is True
assert product.vendor.vendor_code == test_vendor.vendor_code
# Use get_title() method instead of .title attribute
assert (
product.marketplace_product.get_title("en")
== test_marketplace_product.get_title("en")
)
assert product.marketplace_product.get_title(
"en"
) == test_marketplace_product.get_title("en")
def test_product_unique_per_vendor(self, db, test_vendor, test_marketplace_product):
"""Test that same marketplace product can't be added twice to vendor catalog."""
@@ -75,7 +75,9 @@ class TestProductModel:
assert product.min_quantity == 1 # Default
assert product.display_order == 0 # Default
def test_product_vendor_override_fields(self, db, test_vendor, test_marketplace_product):
def test_product_vendor_override_fields(
self, db, test_vendor, test_marketplace_product
):
"""Test Product model vendor-specific override fields."""
product = Product(
vendor_id=test_vendor.id,
@@ -97,7 +99,9 @@ class TestProductModel:
assert product.currency == "USD"
assert product.availability == "limited"
def test_product_inventory_settings(self, db, test_vendor, test_marketplace_product):
def test_product_inventory_settings(
self, db, test_vendor, test_marketplace_product
):
"""Test Product model inventory settings."""
product = Product(
vendor_id=test_vendor.id,
@@ -126,7 +130,9 @@ class TestProductModel:
assert product.marketplace_product is not None
assert product.inventory_entries == [] # No inventory yet
def test_product_effective_properties(self, db, test_vendor, test_marketplace_product):
def test_product_effective_properties(
self, db, test_vendor, test_marketplace_product
):
"""Test Product effective properties with override pattern."""
# First, set some values on the marketplace product
test_marketplace_product.price_numeric = 100.00

View File

@@ -1,5 +1,6 @@
# tests/unit/models/database/test_team.py
"""Unit tests for VendorUser and Role database models."""
import pytest
from models.database.vendor import Role, Vendor, VendorUser
@@ -87,7 +88,9 @@ class TestVendorUserModel:
assert vendor_user.role.name == "Manager"
assert "products.create" in vendor_user.role.permissions
def test_vendor_user_multiple_vendors(self, db, test_vendor, test_user, other_company):
def test_vendor_user_multiple_vendors(
self, db, test_vendor, test_user, other_company
):
"""Test same user can be added to multiple vendors."""
# Create another vendor
other_vendor = Vendor(

View File

@@ -1,5 +1,6 @@
# tests/unit/models/database/test_user.py
"""Unit tests for User database model."""
import pytest
from sqlalchemy.exc import IntegrityError

View File

@@ -1,5 +1,6 @@
# tests/unit/models/database/test_vendor.py
"""Unit tests for Vendor database model."""
import pytest
from sqlalchemy.exc import IntegrityError