mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-01-02 01:47:04 -05:00
feat: Implement initial schema and add various API, service, and management command enhancements across the application.
This commit is contained in:
@@ -93,9 +93,7 @@ class TestContractValidationMiddlewareFilterValidation(TestCase):
|
||||
self.middleware.enabled = True
|
||||
|
||||
@patch.object(ContractValidationMiddleware, "_log_contract_violation")
|
||||
def test__validate_filter_metadata__valid_categorical_filters__no_violation(
|
||||
self, mock_log
|
||||
):
|
||||
def test__validate_filter_metadata__valid_categorical_filters__no_violation(self, mock_log):
|
||||
"""Test valid categorical filter format doesn't log violation."""
|
||||
request = self.factory.get("/api/v1/parks/filter-options/")
|
||||
valid_data = {
|
||||
@@ -118,11 +116,7 @@ class TestContractValidationMiddlewareFilterValidation(TestCase):
|
||||
def test__validate_filter_metadata__string_options__logs_violation(self, mock_log):
|
||||
"""Test string filter options logs contract violation."""
|
||||
request = self.factory.get("/api/v1/parks/filter-options/")
|
||||
invalid_data = {
|
||||
"categorical": {
|
||||
"status": ["OPERATING", "CLOSED"] # Strings instead of objects
|
||||
}
|
||||
}
|
||||
invalid_data = {"categorical": {"status": ["OPERATING", "CLOSED"]}} # Strings instead of objects
|
||||
response = JsonResponse(invalid_data)
|
||||
|
||||
self.middleware.process_response(request, response)
|
||||
@@ -133,18 +127,10 @@ class TestContractValidationMiddlewareFilterValidation(TestCase):
|
||||
assert any("CATEGORICAL_OPTION_IS_STRING" in arg for arg in call_args)
|
||||
|
||||
@patch.object(ContractValidationMiddleware, "_log_contract_violation")
|
||||
def test__validate_filter_metadata__missing_value_property__logs_violation(
|
||||
self, mock_log
|
||||
):
|
||||
def test__validate_filter_metadata__missing_value_property__logs_violation(self, mock_log):
|
||||
"""Test filter option missing 'value' property logs violation."""
|
||||
request = self.factory.get("/api/v1/parks/filter-options/")
|
||||
invalid_data = {
|
||||
"categorical": {
|
||||
"status": [
|
||||
{"label": "Operating", "count": 10} # Missing 'value'
|
||||
]
|
||||
}
|
||||
}
|
||||
invalid_data = {"categorical": {"status": [{"label": "Operating", "count": 10}]}} # Missing 'value'
|
||||
response = JsonResponse(invalid_data)
|
||||
|
||||
self.middleware.process_response(request, response)
|
||||
@@ -154,18 +140,10 @@ class TestContractValidationMiddlewareFilterValidation(TestCase):
|
||||
assert any("MISSING_VALUE_PROPERTY" in arg for arg in call_args)
|
||||
|
||||
@patch.object(ContractValidationMiddleware, "_log_contract_violation")
|
||||
def test__validate_filter_metadata__missing_label_property__logs_violation(
|
||||
self, mock_log
|
||||
):
|
||||
def test__validate_filter_metadata__missing_label_property__logs_violation(self, mock_log):
|
||||
"""Test filter option missing 'label' property logs violation."""
|
||||
request = self.factory.get("/api/v1/parks/filter-options/")
|
||||
invalid_data = {
|
||||
"categorical": {
|
||||
"status": [
|
||||
{"value": "OPERATING", "count": 10} # Missing 'label'
|
||||
]
|
||||
}
|
||||
}
|
||||
invalid_data = {"categorical": {"status": [{"value": "OPERATING", "count": 10}]}} # Missing 'label'
|
||||
response = JsonResponse(invalid_data)
|
||||
|
||||
self.middleware.process_response(request, response)
|
||||
@@ -188,11 +166,7 @@ class TestContractValidationMiddlewareRangeValidation(TestCase):
|
||||
def test__validate_range_filter__valid_range__no_violation(self, mock_log):
|
||||
"""Test valid range filter format doesn't log violation."""
|
||||
request = self.factory.get("/api/v1/rides/filter-options/")
|
||||
valid_data = {
|
||||
"ranges": {
|
||||
"height": {"min": 0, "max": 500, "step": 10, "unit": "ft"}
|
||||
}
|
||||
}
|
||||
valid_data = {"ranges": {"height": {"min": 0, "max": 500, "step": 10, "unit": "ft"}}}
|
||||
response = JsonResponse(valid_data)
|
||||
|
||||
self.middleware.process_response(request, response)
|
||||
@@ -205,11 +179,7 @@ class TestContractValidationMiddlewareRangeValidation(TestCase):
|
||||
def test__validate_range_filter__missing_min_max__logs_violation(self, mock_log):
|
||||
"""Test range filter missing min/max logs violation."""
|
||||
request = self.factory.get("/api/v1/rides/filter-options/")
|
||||
invalid_data = {
|
||||
"ranges": {
|
||||
"height": {"step": 10} # Missing 'min' and 'max'
|
||||
}
|
||||
}
|
||||
invalid_data = {"ranges": {"height": {"step": 10}}} # Missing 'min' and 'max'
|
||||
response = JsonResponse(invalid_data)
|
||||
|
||||
self.middleware.process_response(request, response)
|
||||
@@ -232,11 +202,7 @@ class TestContractValidationMiddlewareHybridValidation(TestCase):
|
||||
def test__validate_hybrid_response__valid_strategy__no_violation(self, mock_log):
|
||||
"""Test valid hybrid response strategy doesn't log violation."""
|
||||
request = self.factory.get("/api/v1/parks/hybrid/")
|
||||
valid_data = {
|
||||
"strategy": "client_side",
|
||||
"data": [],
|
||||
"filter_metadata": {}
|
||||
}
|
||||
valid_data = {"strategy": "client_side", "data": [], "filter_metadata": {}}
|
||||
response = JsonResponse(valid_data)
|
||||
|
||||
self.middleware.process_response(request, response)
|
||||
@@ -246,15 +212,10 @@ class TestContractValidationMiddlewareHybridValidation(TestCase):
|
||||
assert "INVALID_STRATEGY_VALUE" not in str(call)
|
||||
|
||||
@patch.object(ContractValidationMiddleware, "_log_contract_violation")
|
||||
def test__validate_hybrid_response__invalid_strategy__logs_violation(
|
||||
self, mock_log
|
||||
):
|
||||
def test__validate_hybrid_response__invalid_strategy__logs_violation(self, mock_log):
|
||||
"""Test invalid hybrid strategy logs violation."""
|
||||
request = self.factory.get("/api/v1/parks/hybrid/")
|
||||
invalid_data = {
|
||||
"strategy": "invalid_strategy", # Not 'client_side' or 'server_side'
|
||||
"data": []
|
||||
}
|
||||
invalid_data = {"strategy": "invalid_strategy", "data": []} # Not 'client_side' or 'server_side'
|
||||
response = JsonResponse(invalid_data)
|
||||
|
||||
self.middleware.process_response(request, response)
|
||||
@@ -277,12 +238,7 @@ class TestContractValidationMiddlewarePaginationValidation(TestCase):
|
||||
def test__validate_pagination__valid_response__no_violation(self, mock_log):
|
||||
"""Test valid pagination response doesn't log violation."""
|
||||
request = self.factory.get("/api/v1/parks/")
|
||||
valid_data = {
|
||||
"count": 10,
|
||||
"next": None,
|
||||
"previous": None,
|
||||
"results": [{"id": 1}, {"id": 2}]
|
||||
}
|
||||
valid_data = {"count": 10, "next": None, "previous": None, "results": [{"id": 1}, {"id": 2}]}
|
||||
response = JsonResponse(valid_data)
|
||||
|
||||
self.middleware.process_response(request, response)
|
||||
@@ -296,10 +252,7 @@ class TestContractValidationMiddlewarePaginationValidation(TestCase):
|
||||
def test__validate_pagination__results_not_array__logs_violation(self, mock_log):
|
||||
"""Test pagination with non-array results logs violation."""
|
||||
request = self.factory.get("/api/v1/parks/")
|
||||
invalid_data = {
|
||||
"count": 10,
|
||||
"results": "not an array" # Should be array
|
||||
}
|
||||
invalid_data = {"count": 10, "results": "not an array"} # Should be array
|
||||
response = JsonResponse(invalid_data)
|
||||
|
||||
self.middleware.process_response(request, response)
|
||||
@@ -346,9 +299,7 @@ class TestContractValidationMiddlewareViolationSuggestions(TestCase):
|
||||
|
||||
def test__get_violation_suggestion__categorical_string__returns_suggestion(self):
|
||||
"""Test get_violation_suggestion returns suggestion for CATEGORICAL_OPTION_IS_STRING."""
|
||||
suggestion = self.middleware._get_violation_suggestion(
|
||||
"CATEGORICAL_OPTION_IS_STRING"
|
||||
)
|
||||
suggestion = self.middleware._get_violation_suggestion("CATEGORICAL_OPTION_IS_STRING")
|
||||
|
||||
assert "ensure_filter_option_format" in suggestion
|
||||
assert "object arrays" in suggestion
|
||||
|
||||
Reference in New Issue
Block a user