@@ -46,9 +46,11 @@ def _position(person, title=None):
4646 )
4747
4848
49- # On the servers DEBUG is False, so site_scheme pins https — assert against that
50- # (the test client's host is "testserver", auto-added to ALLOWED_HOSTS).
51- @override_settings (DEBUG = False )
49+ # On the servers (DJANGO_ENV TEST/PROD) site_scheme pins https — assert against
50+ # that (the test client's host is "testserver", auto-added to ALLOWED_HOSTS).
51+ # NB: DJANGO_ENV, not DEBUG — the test server runs DEBUG=True behind the proxy
52+ # (see PageMetadataSchemeTests for the regression that motivated this).
53+ @override_settings (DJANGO_ENV = 'PROD' )
5254class PageMetadataHttpsTests (DatabaseTestCase ):
5355
5456 def test_home_has_core_metadata (self ):
@@ -204,10 +206,25 @@ def test_jsonld_escapes_script_breakout(self):
204206
205207
206208class PageMetadataSchemeTests (DatabaseTestCase ):
209+ """site_scheme keys off DJANGO_ENV, not DEBUG. The test server runs DEBUG=True
210+ behind the same TLS proxy as prod, so a DEBUG-based check would emit http://
211+ there (regression for the #1236 follow-up fix)."""
207212
208- @override_settings (DEBUG = True )
213+ @override_settings (DJANGO_ENV = 'TEST' , DEBUG = True )
214+ def test_test_server_uses_https_even_with_debug_true (self ):
215+ """The crux: DJANGO_ENV=TEST + DEBUG=True must still emit https."""
216+ resp = self .client .get (reverse ("website:index" ))
217+ self .assertContains (resp , '<link rel="canonical" href="https://testserver/">' )
218+ self .assertContains (resp , '<meta property="og:url" content="https://testserver/">' )
219+
220+ @override_settings (DJANGO_ENV = 'PROD' , DEBUG = False )
221+ def test_prod_uses_https (self ):
222+ resp = self .client .get (reverse ("website:index" ))
223+ self .assertContains (resp , '<meta property="og:url" content="https://testserver/">' )
224+
225+ @override_settings (DJANGO_ENV = 'DEBUG' , DEBUG = True )
209226 def test_local_dev_uses_request_scheme (self ):
210- """In DEBUG (local dev over http) the absolute URLs follow request.scheme."""
227+ """Local dev (DJANGO_ENV=DEBUG/unset over http) follows request.scheme."""
211228 resp = self .client .get (reverse ("website:index" ))
212229 self .assertContains (resp , '<link rel="canonical" href="http://testserver/">' )
213230 self .assertContains (resp , '<meta property="og:url" content="http://testserver/">' )
0 commit comments