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:
@@ -1,19 +1,19 @@
|
||||
# tests/unit/services/test_stats_service.py
|
||||
"""Unit tests for StatsService following the application's testing patterns."""
|
||||
|
||||
import uuid
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from app.exceptions import AdminOperationException, VendorNotFoundException
|
||||
from app.services.stats_service import StatsService
|
||||
from models.database.inventory import Inventory
|
||||
from models.database.marketplace_import_job import MarketplaceImportJob
|
||||
from models.database.marketplace_product import MarketplaceProduct
|
||||
from models.database.marketplace_product_translation import MarketplaceProductTranslation
|
||||
from models.database.product import Product
|
||||
from models.database.vendor import Vendor
|
||||
from models.database.marketplace_product_translation import (
|
||||
MarketplaceProductTranslation,
|
||||
)
|
||||
|
||||
|
||||
def create_marketplace_product_with_translation(
|
||||
@@ -21,8 +21,7 @@ def create_marketplace_product_with_translation(
|
||||
):
|
||||
"""Helper to create a MarketplaceProduct with its translation."""
|
||||
product = MarketplaceProduct(
|
||||
marketplace_product_id=marketplace_product_id,
|
||||
**kwargs
|
||||
marketplace_product_id=marketplace_product_id, **kwargs
|
||||
)
|
||||
db.add(product)
|
||||
db.flush() # Get the product ID
|
||||
@@ -275,7 +274,10 @@ class TestStatsService:
|
||||
with pytest.raises(AdminOperationException) as exc_info:
|
||||
self.service.get_marketplace_breakdown_stats(db)
|
||||
|
||||
assert exc_info.value.details.get("operation") == "get_marketplace_breakdown_stats"
|
||||
assert (
|
||||
exc_info.value.details.get("operation")
|
||||
== "get_marketplace_breakdown_stats"
|
||||
)
|
||||
|
||||
# ==================== get_vendor_stats Tests ====================
|
||||
|
||||
@@ -371,9 +373,7 @@ class TestStatsService:
|
||||
stats = self.service.get_vendor_statistics(db)
|
||||
|
||||
if stats["total_vendors"] > 0:
|
||||
expected_rate = (
|
||||
stats["verified_vendors"] / stats["total_vendors"] * 100
|
||||
)
|
||||
expected_rate = stats["verified_vendors"] / stats["total_vendors"] * 100
|
||||
assert abs(stats["verification_rate"] - expected_rate) < 0.01
|
||||
|
||||
def test_get_vendor_statistics_database_error(self, db):
|
||||
@@ -438,9 +438,7 @@ class TestStatsService:
|
||||
stats = self.service.get_import_statistics(db)
|
||||
|
||||
if stats["total_imports"] > 0:
|
||||
expected_rate = (
|
||||
stats["completed_imports"] / stats["total_imports"] * 100
|
||||
)
|
||||
expected_rate = stats["completed_imports"] / stats["total_imports"] * 100
|
||||
assert abs(stats["success_rate"] - expected_rate) < 0.01
|
||||
else:
|
||||
assert stats["success_rate"] == 0
|
||||
|
||||
Reference in New Issue
Block a user