55from django .test import SimpleTestCase , TestCase
66from django .urls import reverse , set_urlconf
77from django .utils .translation import activate , gettext as _
8- from django_hosts .resolvers import reverse as reverse_with_host
8+ from django_hosts .resolvers import reverse as reverse_with_host , reverse_host
99
1010from djangoproject .urls import www as www_urls
1111from releases .models import Release
@@ -31,7 +31,7 @@ def test_team_url(self):
3131 def test_internals_team (self ):
3232 response = self .client .get (
3333 "/en/dev/internals/team/" ,
34- headers = {"host" : "docs.djangoproject.localhost:8000" },
34+ headers = {"host" : reverse_host ( "docs" ) },
3535 )
3636 self .assertRedirects (
3737 response ,
@@ -82,7 +82,7 @@ def tearDownClass(cls):
8282
8383 def test_empty_get (self ):
8484 response = self .client .get (
85- "/en/dev/search/" , headers = {"host" : "docs.djangoproject.localhost:8000" }
85+ "/en/dev/search/" , headers = {"host" : reverse_host ( "docs" ) }
8686 )
8787 self .assertEqual (response .status_code , 200 )
8888 # No header item is active.
@@ -93,7 +93,7 @@ def test_empty_get(self):
9393 def test_search_type_filter_all (self ):
9494 response = self .client .get (
9595 "/en/5.1/search/?q=generic" ,
96- headers = {"host" : "docs.djangoproject.localhost:8000" },
96+ headers = {"host" : reverse_host ( "docs" ) },
9797 )
9898 self .assertEqual (response .status_code , 200 )
9999 self .assertContains (response , "5 results for <em>generic</em>" , html = True )
@@ -105,7 +105,7 @@ def test_search_type_filter_by_doc_types(self):
105105 with self .subTest (category = category ):
106106 response = self .client .get (
107107 f"/en/5.1/search/?q=generic&category={ category .value } " ,
108- headers = {"host" : "docs.djangoproject.localhost:8000" },
108+ headers = {"host" : reverse_host ( "docs" ) },
109109 )
110110 self .assertEqual (response .status_code , 200 )
111111 self .assertContains (
@@ -122,7 +122,7 @@ def test_search_type_filter_by_doc_types(self):
122122 def test_search_category_filter_invalid_doc_categories (self ):
123123 response = self .client .get (
124124 "/en/5.1/search/?q=generic&category=invalid-so-ignored" ,
125- headers = {"host" : "docs.djangoproject.localhost:8000" },
125+ headers = {"host" : reverse_host ( "docs" ) },
126126 )
127127 self .assertEqual (response .status_code , 200 )
128128 self .assertContains (response , "5 results for <em>generic</em>" , html = True )
@@ -132,7 +132,7 @@ def test_search_category_filter_invalid_doc_categories(self):
132132 def test_search_category_filter_no_results (self ):
133133 response = self .client .get (
134134 "/en/5.1/search/?q=potato&category=ref" ,
135- headers = {"host" : "docs.djangoproject.localhost:8000" },
135+ headers = {"host" : reverse_host ( "docs" ) },
136136 )
137137 self .assertEqual (response .status_code , 200 )
138138 self .assertContains (response , self .active_filter , count = 1 )
@@ -267,7 +267,7 @@ def test_code_links(self):
267267 with self .subTest (query = query ):
268268 response = self .client .get (
269269 f"/en/5.1/search/?q={ query } " ,
270- headers = {"host" : "docs.djangoproject.localhost:8000" },
270+ headers = {"host" : reverse_host ( "docs" ) },
271271 )
272272 self .assertEqual (response .status_code , 200 )
273273 self .assertContains (
@@ -289,7 +289,7 @@ def tearDownClass(cls):
289289
290290 def test_sitemap_index (self ):
291291 response = self .client .get (
292- "/sitemap.xml" , headers = {"host" : "docs.djangoproject.localhost:8000" }
292+ "/sitemap.xml" , headers = {"host" : reverse_host ( "docs" ) }
293293 )
294294 self .assertContains (response , "<sitemap>" , count = 2 )
295295 en_sitemap_url = reverse_with_host (
@@ -318,7 +318,7 @@ def test_sitemap(self):
318318
319319 def test_sitemap_404 (self ):
320320 response = self .client .get (
321- "/sitemap-xx.xml" , headers = {"host" : "docs.djangoproject.localhost:8000" }
321+ "/sitemap-xx.xml" , headers = {"host" : reverse_host ( "docs" ) }
322322 )
323323 self .assertEqual (response .status_code , 404 )
324324 self .assertEqual (
0 commit comments