reaching 100% test coverage for the middleware unit tests

This commit is contained in:
2025-11-19 22:26:45 +01:00
parent a18ad48721
commit 23cf568c82
2 changed files with 104 additions and 0 deletions

View File

@@ -435,6 +435,10 @@ class TestVendorContextManager:
"/image.jpg",
"/style.css",
"/app.webmanifest",
"/static/", # Path starting with /static/ but no extension
"/media/uploads", # Path starting with /media/ but no extension
"/subfolder/favicon.ico", # favicon.ico in subfolder
"/favicon.ico.bak", # Contains favicon.ico but doesn't end with static extension (hits line 226)
])
def test_is_static_file_request(self, path):
"""Test static file detection for various paths and extensions."""
@@ -719,3 +723,23 @@ class TestEdgeCases:
# Should detect 'shop' as subdomain since it's the first part
assert context["detection_method"] == "subdomain"
assert context["subdomain"] == "shop"
def test_get_vendor_logs_warning_when_not_found_subdomain(self):
"""Test that warning is logged when vendor is not found by subdomain."""
mock_db = Mock()
# Mock the complete query chain properly - need to mock filter twice and then first
mock_query = mock_db.query.return_value
mock_filter1 = mock_query.filter.return_value
mock_filter2 = mock_filter1.filter.return_value
mock_filter2.first.return_value = None
context = {"subdomain": "nonexistent", "detection_method": "subdomain"}
with patch('middleware.vendor_context.logger') as mock_logger:
vendor = VendorContextManager.get_vendor_from_context(mock_db, context)
assert vendor is None
# Verify warning was logged
mock_logger.warning.assert_called()
warning_message = str(mock_logger.warning.call_args)
assert "No active vendor found for subdomain" in warning_message and "nonexistent" in warning_message