Skip to content

Commit b1f566e

Browse files
committed
Fixed tests when 'PARENT_HOST' setting is set
A number of used the hardcoded host 'djangoproject.localhost:8000'. Setting the 'PARENT_HOST' setting to a different value, e.g. if running Django on another machine, would result in tests failing. This commit changes the tests to use the 'PARENT_HOST' setting in URLs where relevant.
1 parent 65b2438 commit b1f566e

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

Diff for: README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ The secrets file may contain the following fields:
411411
* ``trac_db_password``: must match the value of ``POSTGRES_PASSWORD`` for the ``tracdb`` service.
412412
* ``allowed_hosts``: an array that will be appended to Django's ``ALLOWED_HOSTS`` setting.
413413
* ``internal_ips``: an array of IPs assigned to the ``INTERNAL_IPS`` Django Debug Toolbar setting. Defaults to ``["127.0.0.1"]``.
414-
* ``parent_host``: the django-hosts ``PARENT_HOST`` setting. Useful if you run docker on a machine other than ``localhost``, but setting it breaks some tests. Defaults to ``djangoproject.localhost:8000``.
414+
* ``parent_host``: the django-hosts ``PARENT_HOST`` setting. Useful if you run docker on a machine other than ``localhost``. Defaults to ``djangoproject.localhost:8000``.
415415

416416
Pre-commit checks
417417
-----------------

Diff for: docs/tests.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_team_url(self):
166166
def test_internals_team(self):
167167
response = self.client.get(
168168
"/en/dev/internals/team/",
169-
headers={"host": "docs.djangoproject.localhost:8000"},
169+
headers={"host": f"docs.{settings.PARENT_HOST}"},
170170
)
171171
self.assertRedirects(
172172
response,
@@ -191,7 +191,7 @@ def tearDownClass(cls):
191191

192192
def test_empty_get(self):
193193
response = self.client.get(
194-
"/en/dev/search/", headers={"host": "docs.djangoproject.localhost:8000"}
194+
"/en/dev/search/", headers={"host": f"docs.{settings.PARENT_HOST}"}
195195
)
196196
self.assertEqual(response.status_code, 200)
197197

@@ -376,12 +376,12 @@ def tearDownClass(cls):
376376

377377
def test_sitemap_index(self):
378378
response = self.client.get(
379-
"/sitemap.xml", headers={"host": "docs.djangoproject.localhost:8000"}
379+
"/sitemap.xml", headers={"host": f"docs.{settings.PARENT_HOST}"}
380380
)
381381
self.assertContains(response, "<sitemap>", count=2)
382382
self.assertContains(
383383
response,
384-
"<loc>http://docs.djangoproject.localhost:8000/sitemap-en.xml</loc>",
384+
f"<loc>http://docs.{settings.PARENT_HOST}/sitemap-en.xml</loc>",
385385
)
386386

387387
def test_sitemap(self):
@@ -395,7 +395,7 @@ def test_sitemap(self):
395395

396396
def test_sitemap_404(self):
397397
response = self.client.get(
398-
"/sitemap-xx.xml", headers={"host": "docs.djangoproject.localhost:8000"}
398+
"/sitemap-xx.xml", headers={"host": f"docs.{settings.PARENT_HOST}"}
399399
)
400400
self.assertEqual(response.status_code, 404)
401401
self.assertEqual(

Diff for: members/test_admin.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import date, timedelta
22

3+
from django.conf import settings
34
from django.contrib import admin
45
from django.test import TestCase
56

@@ -43,7 +44,7 @@ def test_membership_expires(self):
4344

4445
def test_renewal_link(self):
4546
expected_str = (
46-
'<a href="http://www.djangoproject.localhost:8000/foundation/'
47+
f'<a href="http://www.{settings.PARENT_HOST}/foundation/'
4748
"corporate-membership/renew/"
4849
)
4950
modeladmin = CorporateMemberAdmin(CorporateMember, admin.site)

Diff for: members/test_management.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_mail(self):
5151
msg.body,
5252
)
5353
self.assertIn(
54-
"http://www.djangoproject.localhost:8000/foundation/"
54+
f"http://www.{settings.PARENT_HOST}/foundation/"
5555
"corporate-membership/renew/",
5656
msg.body,
5757
)

Diff for: releases/tests.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22

3+
from django.conf import settings
34
from django.contrib.redirects.models import Redirect
45
from django.test import TestCase, override_settings
56
from django.urls import reverse
@@ -43,12 +44,12 @@ def test_release_notes(self):
4344
self.assertIsInstance(output, SafeString)
4445
self.assertEqual(
4546
output,
46-
'<a href="http://docs.djangoproject.localhost:8000/en/1.8/releases/1.8/">'
47+
f'<a href="http://docs.{settings.PARENT_HOST}/en/1.8/releases/1.8/">'
4748
"Online documentation</a>",
4849
)
4950
self.assertEqual(
5051
release_notes("1.8", show_version=True),
51-
'<a href="http://docs.djangoproject.localhost:8000/en/1.8/releases/1.8/">'
52+
f'<a href="http://docs.{settings.PARENT_HOST}/en/1.8/releases/1.8/">'
5253
"1.8 release notes</a>",
5354
)
5455

@@ -57,12 +58,12 @@ def test_release_notes_1_10(self):
5758
self.assertIsInstance(output, SafeString)
5859
self.assertEqual(
5960
output,
60-
'<a href="http://docs.djangoproject.localhost:8000/en/1.10/releases/1.10/">'
61+
f'<a href="http://docs.{settings.PARENT_HOST}/en/1.10/releases/1.10/">'
6162
"Online documentation</a>",
6263
)
6364
self.assertEqual(
6465
release_notes("1.10", show_version=True),
65-
'<a href="http://docs.djangoproject.localhost:8000/en/1.10/releases/1.10/">'
66+
f'<a href="http://docs.{settings.PARENT_HOST}/en/1.10/releases/1.10/">'
6667
"1.10 release notes</a>",
6768
)
6869

0 commit comments

Comments
 (0)