Skip to content

Commit 050e409

Browse files
committed
fixed tests for django 1.10
1 parent 1df5fef commit 050e409

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

maintenancemode/tests.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
os.path.join(PROJECT_ROOT, 'test_templates'),
2424
]
2525

26+
TEMPLATES = [
27+
{
28+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
29+
'DIRS': [
30+
os.path.join(PROJECT_ROOT, 'test_templates'),
31+
],
32+
'APP_DIRS': True,
33+
}
34+
]
2635

2736
urlpatterns = [
2837
url('^$', lambda r: HttpResponse('Rendered response page'), name='test'),
@@ -65,7 +74,7 @@ def test_enabled_middleware_without_template(self):
6574
def test_enabled_middleware_with_template(self):
6675
# Enabling the middleware having a ``503.html`` in any of the
6776
# template locations should return the rendered template"
68-
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=TEMPLATE_DIRS):
77+
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
6978
response = self.client.get('/')
7079
self.assertContains(response, text='Temporary unavailable', count=1, status_code=503)
7180
self.assertContains(response, text='You requested: /', count=1, status_code=503)
@@ -74,7 +83,7 @@ def test_middleware_with_non_staff_user(self):
7483
# A logged in user that is not a staff user should see the 503 message
7584
self.client.login(username='maintenance', password='password')
7685

77-
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=TEMPLATE_DIRS):
86+
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
7887
response = self.client.get('/')
7988
self.assertContains(response, text='Temporary unavailable', count=1, status_code=503)
8089

@@ -85,7 +94,7 @@ def test_middleware_with_staff_user(self):
8594

8695
self.client.login(username='maintenance', password='password')
8796

88-
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=TEMPLATE_DIRS):
97+
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
8998
response = self.client.get('/')
9099
self.assertContains(response, text='Rendered response page', count=1, status_code=200)
91100

@@ -110,15 +119,15 @@ def test_middleware_with_internal_ips_range(self):
110119
def test_ignored_path(self):
111120
# A path is ignored when applying the maintanance mode and
112121
# should be reachable normally
113-
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=TEMPLATE_DIRS):
122+
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
114123
with self.settings(IGNORE_URLS=(re.compile(r'^/ignored.*'),)):
115124
response = self.client.get('/ignored/')
116125
self.assertContains(response, text='Rendered response page', count=1, status_code=200)
117126

118127
def test_management_command(self):
119128
out = StringIO()
120129
# Explicitly disabling the ``MAINTENANCE_MODE``
121-
with self.settings(MAINTENANCE_MODE=False, TEMPLATE_DIRS=TEMPLATE_DIRS):
130+
with self.settings(MAINTENANCE_MODE=False, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
122131
management.call_command('maintenance', 'on', stdout=out)
123132
self.assertContains(self.client.get('/'), text='Temporary unavailable', count=1, status_code=503)
124133

0 commit comments

Comments
 (0)