Skip to content

Commit 2d69087

Browse files
committed
Address PR feedback with correct decorator ordring see HEA-872
1 parent e3960d3 commit 2d69087

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

apps/baseline/tests/test_viewsets.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,19 +600,24 @@ def test_filter_by_wealth_characteristic(self):
600600
self.assertEqual(len(response.json()), 1)
601601

602602
def test_conditional_request_headers(self):
603-
604603
cache.clear() # Clear cache to ensure clean state
605-
# Test that response includes ETag and Last-Modified headers
604+
605+
# Test that 200 response includes ETag, Last-Modified, Cache-Control, and Expires headers
606606
response = self.client.get(self.url)
607607
self.assertEqual(response.status_code, 200)
608608
self.assertIn("ETag", response.headers)
609609
self.assertIn("Last-Modified", response.headers)
610+
self.assertIn("Cache-Control", response.headers)
611+
self.assertIn("Expires", response.headers)
610612
self.assertTrue(response.headers["ETag"].startswith('W/"')) # Weak ETag format
611613

612614
# Test If-None-Match returns 304 when not modified
613615
etag = response.headers["ETag"]
616+
cache.clear()
614617
response = self.client.get(self.url, HTTP_IF_NONE_MATCH=etag)
615618
self.assertEqual(response.status_code, 304)
619+
self.assertIn("Cache-Control", response.headers)
620+
self.assertIn("Expires", response.headers)
616621

617622
# Test If-None-Match returns 200 when data is modified
618623
cache.clear() # Clear cache before testing modified data
@@ -624,9 +629,12 @@ def test_conditional_request_headers(self):
624629
self.assertNotEqual(response.headers["ETag"], etag)
625630

626631
# Test If-Modified-Since with future date returns 304
632+
cache.clear()
627633
future_date = http_date((now() + timedelta(days=1)).timestamp())
628634
response = self.client.get(self.url, HTTP_IF_MODIFIED_SINCE=future_date)
629635
self.assertEqual(response.status_code, 304)
636+
self.assertIn("Cache-Control", response.headers)
637+
self.assertIn("Expires", response.headers)
630638

631639

632640
class LivelihoodZoneBaselineFacetedSearchViewTestCase(APITestCase):

apps/baseline/viewsets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ def get_serializer_class(self):
278278
return LivelihoodZoneBaselineGeoSerializer # Use GeoFeatureModelSerializer for GeoJSON
279279
return LivelihoodZoneBaselineSerializer
280280

281+
@method_decorator(cache_page(60 * 60 * 24)) # Cache on server for 24 hours - must be above condition per RFC 9110
281282
@method_decorator(condition(etag_func=get_baseline_etag, last_modified_func=get_baseline_last_modified))
282-
@method_decorator(cache_page(60 * 60 * 24)) # Cache on server for 24 hours
283283
def list(self, request, *args, **kwargs):
284284
return super().list(request, *args, **kwargs)
285285

0 commit comments

Comments
 (0)