fix: update tests for current API structure and model changes
- Fix middleware fixtures: vendor_code instead of code, add owner_user_id to company
- Fix performance tests: MarketplaceProduct uses translations for title/description
- Fix security tests: use correct API endpoints (/api/v1/admin/*, /api/v1/vendor/*)
- Fix workflow tests: use actual admin API endpoints
- Fix background task tests: remove invalid vendor_name field, add language
Note: Many middleware integration tests still fail due to dynamic routes
being caught by the /{slug} catch-all route. These tests need further
refactoring to use /api/* prefixed routes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,7 +38,7 @@ class TestVendorContextFlow:
|
||||
else None
|
||||
),
|
||||
"vendor_code": (
|
||||
request.state.vendor.code
|
||||
request.state.vendor.vendor_code
|
||||
if hasattr(request.state, "vendor") and request.state.vendor
|
||||
else None
|
||||
),
|
||||
@@ -61,7 +61,7 @@ class TestVendorContextFlow:
|
||||
data = response.json()
|
||||
assert data["vendor_detected"] is True
|
||||
assert data["vendor_id"] == vendor_with_subdomain.id
|
||||
assert data["vendor_code"] == vendor_with_subdomain.code
|
||||
assert data["vendor_code"] == vendor_with_subdomain.vendor_code
|
||||
assert data["vendor_name"] == vendor_with_subdomain.name
|
||||
|
||||
def test_subdomain_with_port_detection(self, client, vendor_with_subdomain):
|
||||
@@ -76,7 +76,7 @@ class TestVendorContextFlow:
|
||||
"vendor_detected": hasattr(request.state, "vendor")
|
||||
and request.state.vendor is not None,
|
||||
"vendor_code": (
|
||||
request.state.vendor.code
|
||||
request.state.vendor.vendor_code
|
||||
if hasattr(request.state, "vendor") and request.state.vendor
|
||||
else None
|
||||
),
|
||||
@@ -94,7 +94,7 @@ class TestVendorContextFlow:
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["vendor_detected"] is True
|
||||
assert data["vendor_code"] == vendor_with_subdomain.code
|
||||
assert data["vendor_code"] == vendor_with_subdomain.vendor_code
|
||||
|
||||
def test_nonexistent_subdomain_returns_no_vendor(self, client):
|
||||
"""Test that nonexistent subdomain doesn't crash and returns no vendor."""
|
||||
@@ -144,7 +144,7 @@ class TestVendorContextFlow:
|
||||
else None
|
||||
),
|
||||
"vendor_code": (
|
||||
request.state.vendor.code
|
||||
request.state.vendor.vendor_code
|
||||
if hasattr(request.state, "vendor") and request.state.vendor
|
||||
else None
|
||||
),
|
||||
@@ -161,7 +161,7 @@ class TestVendorContextFlow:
|
||||
data = response.json()
|
||||
assert data["vendor_detected"] is True
|
||||
assert data["vendor_id"] == vendor_with_custom_domain.id
|
||||
assert data["vendor_code"] == vendor_with_custom_domain.code
|
||||
assert data["vendor_code"] == vendor_with_custom_domain.vendor_code
|
||||
|
||||
def test_custom_domain_with_www_detection(self, client, vendor_with_custom_domain):
|
||||
"""Test vendor detection via custom domain with www prefix."""
|
||||
@@ -175,7 +175,7 @@ class TestVendorContextFlow:
|
||||
"vendor_detected": hasattr(request.state, "vendor")
|
||||
and request.state.vendor is not None,
|
||||
"vendor_code": (
|
||||
request.state.vendor.code
|
||||
request.state.vendor.vendor_code
|
||||
if hasattr(request.state, "vendor") and request.state.vendor
|
||||
else None
|
||||
),
|
||||
@@ -211,7 +211,7 @@ class TestVendorContextFlow:
|
||||
and request.state.vendor is not None,
|
||||
"vendor_code_param": vendor_code,
|
||||
"vendor_code_state": (
|
||||
request.state.vendor.code
|
||||
request.state.vendor.vendor_code
|
||||
if hasattr(request.state, "vendor") and request.state.vendor
|
||||
else None
|
||||
),
|
||||
@@ -225,15 +225,15 @@ class TestVendorContextFlow:
|
||||
with patch("app.core.config.settings") as mock_settings:
|
||||
mock_settings.platform_domain = "platform.com"
|
||||
response = client.get(
|
||||
f"/vendors/{vendor_with_subdomain.code}/test-path",
|
||||
f"/vendors/{vendor_with_subdomain.vendor_code}/test-path",
|
||||
headers={"host": "localhost:8000"},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["vendor_detected"] is True
|
||||
assert data["vendor_code_param"] == vendor_with_subdomain.code
|
||||
assert data["vendor_code_state"] == vendor_with_subdomain.code
|
||||
assert data["vendor_code_param"] == vendor_with_subdomain.vendor_code
|
||||
assert data["vendor_code_state"] == vendor_with_subdomain.vendor_code
|
||||
|
||||
def test_path_based_vendor_detection_vendor_prefix(
|
||||
self, client, vendor_with_subdomain
|
||||
@@ -249,7 +249,7 @@ class TestVendorContextFlow:
|
||||
"vendor_detected": hasattr(request.state, "vendor")
|
||||
and request.state.vendor is not None,
|
||||
"vendor_code": (
|
||||
request.state.vendor.code
|
||||
request.state.vendor.vendor_code
|
||||
if hasattr(request.state, "vendor") and request.state.vendor
|
||||
else None
|
||||
),
|
||||
@@ -258,14 +258,14 @@ class TestVendorContextFlow:
|
||||
with patch("app.core.config.settings") as mock_settings:
|
||||
mock_settings.platform_domain = "platform.com"
|
||||
response = client.get(
|
||||
f"/vendor/{vendor_with_subdomain.code}/test",
|
||||
f"/vendor/{vendor_with_subdomain.vendor_code}/test",
|
||||
headers={"host": "localhost:8000"},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["vendor_detected"] is True
|
||||
assert data["vendor_code"] == vendor_with_subdomain.code
|
||||
assert data["vendor_code"] == vendor_with_subdomain.vendor_code
|
||||
|
||||
# ========================================================================
|
||||
# Clean Path Extraction Tests
|
||||
@@ -293,7 +293,7 @@ class TestVendorContextFlow:
|
||||
with patch("app.core.config.settings") as mock_settings:
|
||||
mock_settings.platform_domain = "platform.com"
|
||||
response = client.get(
|
||||
f"/vendors/{vendor_with_subdomain.code}/shop/products",
|
||||
f"/vendors/{vendor_with_subdomain.vendor_code}/shop/products",
|
||||
headers={"host": "localhost:8000"},
|
||||
)
|
||||
|
||||
@@ -302,7 +302,7 @@ class TestVendorContextFlow:
|
||||
# Clean path should have vendor prefix removed
|
||||
assert data["clean_path"] == "/shop/products"
|
||||
assert (
|
||||
f"/vendors/{vendor_with_subdomain.code}/shop/products"
|
||||
f"/vendors/{vendor_with_subdomain.vendor_code}/shop/products"
|
||||
in data["original_path"]
|
||||
)
|
||||
|
||||
@@ -396,7 +396,7 @@ class TestVendorContextFlow:
|
||||
{
|
||||
"id": vendor.id if vendor else None,
|
||||
"name": vendor.name if vendor else None,
|
||||
"code": vendor.code if vendor else None,
|
||||
"code": vendor.vendor_code if vendor else None,
|
||||
"subdomain": vendor.subdomain if vendor else None,
|
||||
"is_active": vendor.is_active if vendor else None,
|
||||
}
|
||||
@@ -417,14 +417,14 @@ class TestVendorContextFlow:
|
||||
assert data["has_vendor"] is True
|
||||
assert data["vendor_attributes"]["id"] == vendor_with_subdomain.id
|
||||
assert data["vendor_attributes"]["name"] == vendor_with_subdomain.name
|
||||
assert data["vendor_attributes"]["code"] == vendor_with_subdomain.code
|
||||
assert data["vendor_attributes"]["code"] == vendor_with_subdomain.vendor_code
|
||||
assert data["vendor_attributes"]["is_active"] is True
|
||||
|
||||
# ========================================================================
|
||||
# Edge Cases and Error Handling
|
||||
# ========================================================================
|
||||
|
||||
def test_inactive_vendor_not_detected(self, client, inactive_vendor):
|
||||
def test_inactive_vendor_not_detected(self, client, middleware_inactive_vendor):
|
||||
"""Test that inactive vendors are not detected."""
|
||||
from fastapi import Request
|
||||
|
||||
@@ -441,7 +441,7 @@ class TestVendorContextFlow:
|
||||
mock_settings.platform_domain = "platform.com"
|
||||
response = client.get(
|
||||
"/test-inactive-vendor-detection",
|
||||
headers={"host": f"{inactive_vendor.subdomain}.platform.com"},
|
||||
headers={"host": f"{middleware_inactive_vendor.subdomain}.platform.com"},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user