Skip to content

Commit 25df5d8

Browse files
committed
fixed broken test suite
1 parent 7e46b58 commit 25df5d8

File tree

8 files changed

+153
-75
lines changed

8 files changed

+153
-75
lines changed

.travis.yml

+42-30
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,48 @@
11
# Config file for automatic testing at travis-ci.org
22
dist: xenial
33
language: python
4-
4+
cache: pip
55
sudo: false
6-
python:
7-
- "3.7"
8-
- "3.6"
9-
- "3.5"
10-
- "3.4"
11-
- "2.7"
12-
env:
13-
- DJANGO="Django>=2.1,<2.2"
14-
- DJANGO="Django>=2.0,<2.1"
15-
- DJANGO="Django>=1.11,<1.12"
16-
- DJANGO="https://github.com/django/django/archive/master.tar.gz"
17-
before_install:
18-
- pip install -q $DJANGO coveralls
6+
7+
matrix:
8+
include:
9+
- env: TOXENV=py34-dj111
10+
python: 3.4
11+
- env: TOXENV=py34-dj2
12+
python: 3.4
13+
- env: TOXENV=py35-dj111
14+
python: 3.5
15+
- env: TOXENV=py35-dj2
16+
python: 3.5
17+
- env: TOXENV=py35-dj21
18+
python: 3.5
19+
- env: TOXENV=py35-dj22
20+
python: 3.5
21+
- env: TOXENV=py36-dj111
22+
python: 3.6
23+
- env: TOXENV=py36-dj2
24+
python: 3.6
25+
- env: TOXENV=py36-dj21
26+
python: 3.6
27+
- env: TOXENV=py36-dj22
28+
python: 3.6
29+
- env: TOXENV=py36-dj3
30+
python: 3.6
31+
- env: TOXENV=py37-dj2
32+
python: 3.7
33+
- env: TOXENV=py37-dj21
34+
python: 3.7
35+
- env: TOXENV=py37-dj22
36+
python: 3.7
37+
- env: TOXENV=py37-dj3
38+
python: 3.7
39+
- env: TOXENV=py38-dj22
40+
python: 3.8
41+
- env: TOXENV=py38-dj3
42+
python: 3.8
43+
1944
install:
20-
- python setup.py develop
45+
- pip install tox
46+
2147
script:
22-
- python setup.py test
23-
after_success:
24-
- coveralls
25-
matrix:
26-
exclude:
27-
- python: "3.4"
28-
env: DJANGO="Django>=2.1,<2.2"
29-
- python: "2.7"
30-
env: DJANGO="Django>=2.1,<2.2"
31-
- python: "2.7"
32-
env: DJANGO="Django>=2.0,<2.1"
33-
- python: "2.7"
34-
env: DJANGO="https://github.com/django/django/archive/master.tar.gz"
35-
allow_failures:
36-
- env: DJANGO="https://github.com/django/django/archive/master.tar.gz"
48+
- tox

maintenancemode/tests.py

+13-38
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,20 @@
22
import os.path
33

44
from django.core import management
5-
from django.http import HttpResponse
6-
from django.utils.six import StringIO
5+
try:
6+
from django.utils.six import StringIO
7+
except ImportError:
8+
from six import StringIO
79
from django.contrib.auth.models import User
810
from django.template import TemplateDoesNotExist
911

1012
from django.test import TestCase
1113
from django.test.client import Client
1214
from django.test.utils import override_settings
1315

14-
from django.conf.urls import url
15-
1616
from maintenancemode import utils
1717

18-
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
19-
20-
TEMPLATE_DIRS = [
21-
os.path.join(PROJECT_ROOT, 'test_templates'),
22-
]
23-
24-
TEMPLATES = [
25-
{
26-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
27-
'DIRS': [
28-
os.path.join(PROJECT_ROOT, 'test_templates'),
29-
],
30-
'APP_DIRS': True,
31-
}
32-
]
3318

34-
urlpatterns = [
35-
url('^$', lambda r: HttpResponse('Rendered response page'), name='test'),
36-
url('^ignored/$', lambda r: HttpResponse('Rendered response page'), name='test'),
37-
]
38-
39-
40-
@override_settings(INTERNAL_IPS=[])
41-
@override_settings(MAINTENANCE_MODE=False)
42-
@override_settings(TEMPLATE_DIRS=[], TEMPLATES=[])
43-
@override_settings(ROOT_URLCONF='maintenancemode.tests')
4419
class MaintenanceModeMiddlewareTestCase(TestCase):
4520

4621
def setUp(self):
@@ -66,13 +41,13 @@ def test_disabled_middleware(self):
6641
def test_enabled_middleware_without_template(self):
6742
# Enabling the middleware without a proper 503 template should
6843
# raise a template error
69-
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=[], TEMPLATES=[]):
44+
with self.settings(MAINTENANCE_MODE=True, TEMPLATES=[]):
7045
self.assertRaises(TemplateDoesNotExist, self.client.get, '/')
7146

7247
def test_enabled_middleware_with_template(self):
7348
# Enabling the middleware having a ``503.html`` in any of the
7449
# template locations should return the rendered template"
75-
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
50+
with self.settings(MAINTENANCE_MODE=True):
7651
response = self.client.get('/')
7752
self.assertContains(response, text='Temporary unavailable', count=1, status_code=503)
7853
self.assertContains(response, text='You requested: /', count=1, status_code=503)
@@ -81,7 +56,7 @@ def test_middleware_with_non_staff_user(self):
8156
# A logged in user that is not a staff user should see the 503 message
8257
self.client.login(username='maintenance', password='password')
8358

84-
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
59+
with self.settings(MAINTENANCE_MODE=True):
8560
response = self.client.get('/')
8661
self.assertContains(response, text='Temporary unavailable', count=1, status_code=503)
8762

@@ -92,7 +67,7 @@ def test_middleware_with_staff_user(self):
9267

9368
self.client.login(username='maintenance', password='password')
9469

95-
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
70+
with self.settings(MAINTENANCE_MODE=True):
9671
response = self.client.get('/')
9772
self.assertContains(response, text='Rendered response page', count=1, status_code=200)
9873

@@ -103,7 +78,7 @@ def test_middleware_with_staff_user_denied(self):
10378

10479
self.client.login(username='maintenance', password='password')
10580

106-
with self.settings(MAINTENANCE_MODE=True, MAINTENANCE_ALLOW_STAFF=False, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
81+
with self.settings(MAINTENANCE_MODE=True, MAINTENANCE_ALLOW_STAFF=False):
10782
response = self.client.get('/')
10883
self.assertContains(response, text='Temporary unavailable', count=1, status_code=503)
10984

@@ -114,7 +89,7 @@ def test_middleware_with_superuser_user_denied(self):
11489

11590
self.client.login(username='maintenance', password='password')
11691

117-
with self.settings(MAINTENANCE_MODE=True, MAINTENANCE_ALLOW_SUPERUSER=False, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
92+
with self.settings(MAINTENANCE_MODE=True, MAINTENANCE_ALLOW_SUPERUSER=False):
11893
response = self.client.get('/')
11994
self.assertContains(response, text='Temporary unavailable', count=1, status_code=503)
12095

@@ -125,7 +100,7 @@ def test_middleware_with_superuser_user_allowed(self):
125100

126101
self.client.login(username='maintenance', password='password')
127102

128-
with self.settings(MAINTENANCE_MODE=True, MAINTENANCE_ALLOW_STAFF=False, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
103+
with self.settings(MAINTENANCE_MODE=True, MAINTENANCE_ALLOW_STAFF=False):
129104
response = self.client.get('/')
130105
self.assertContains(response, text='Rendered response page', count=1, status_code=200)
131106

@@ -150,15 +125,15 @@ def test_middleware_with_internal_ips_range(self):
150125
def test_ignored_path(self):
151126
# A path is ignored when applying the maintanance mode and
152127
# should be reachable normally
153-
with self.settings(MAINTENANCE_MODE=True, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
128+
with self.settings(MAINTENANCE_MODE=True):
154129
with self.settings(IGNORE_URLS=(re.compile(r'^/ignored.*'),)):
155130
response = self.client.get('/ignored/')
156131
self.assertContains(response, text='Rendered response page', count=1, status_code=200)
157132

158133
def test_management_command(self):
159134
out = StringIO()
160135
# Explicitly disabling the ``MAINTENANCE_MODE``
161-
with self.settings(MAINTENANCE_MODE=False, TEMPLATE_DIRS=TEMPLATE_DIRS, TEMPLATES=TEMPLATES):
136+
with self.settings(MAINTENANCE_MODE=False):
162137
management.call_command('maintenance', 'on', stdout=out)
163138
self.assertContains(self.client.get('/'), text='Temporary unavailable', count=1, status_code=503)
164139

runtests.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!test/usr/bin/env python
2+
import os
3+
import sys
4+
5+
from django.core.management import execute_from_command_line
6+
7+
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_settings'
8+
9+
10+
def runtests():
11+
12+
argv = [sys.argv[0], 'test']
13+
return execute_from_command_line(argv)
14+
15+
16+
if __name__ == '__main__':
17+
sys.exit(runtests())

setup.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def find_version(*parts):
2828

2929
install_requires=[
3030
'django-appconf',
31+
'six>=1.9.0',
3132
'ipy',
3233
],
3334

@@ -46,11 +47,6 @@ def find_version(*parts):
4647
packages=find_packages(exclude=('example*', '*.tests*')),
4748
include_package_data=True,
4849

49-
tests_require=[
50-
'django-setuptest',
51-
],
52-
test_suite='setuptest.setuptest.SetupTestSuite',
53-
5450
zip_safe=False,
5551
classifiers=[
5652
'Development Status :: 5 - Production/Stable',

test_settings.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
import os, re
22

3+
SECRET_KEY = 'DUMMY_SECRET_KEY'
4+
5+
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
6+
7+
INTERNAL_IPS = []
8+
9+
TEMPLATES = [
10+
{
11+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
12+
'DIRS': [
13+
os.path.join(PROJECT_ROOT, 'test_templates'),
14+
],
15+
'APP_DIRS': True,
16+
'OPTIONS': {
17+
'context_processors': [
18+
'django.contrib.auth.context_processors.auth',
19+
'django.template.context_processors.debug',
20+
'django.template.context_processors.i18n',
21+
'django.template.context_processors.media',
22+
'django.template.context_processors.static',
23+
'django.template.context_processors.tz',
24+
'django.contrib.messages.context_processors.messages',
25+
],
26+
},
27+
},
28+
]
29+
330
DATABASES = {
431
'default': {
532
'ENGINE': 'django.db.backends.sqlite3',
@@ -12,6 +39,7 @@
1239
'django.contrib.admin',
1340
'django.contrib.sessions',
1441
'django.contrib.contenttypes',
42+
'django.contrib.messages',
1543
'django.contrib.sites',
1644

1745
'maintenancemode',
@@ -20,15 +48,16 @@
2048
MIDDLEWARE = (
2149
'django.contrib.sessions.middleware.SessionMiddleware',
2250
'django.contrib.auth.middleware.AuthenticationMiddleware',
51+
'django.contrib.messages.middleware.MessageMiddleware',
2352

2453
'maintenancemode.middleware.MaintenanceModeMiddleware',
2554
)
2655

27-
ROOT_URLCONF = 'maintenancemode.tests'
56+
ROOT_URLCONF = 'test_urls'
2857

2958
SITE_ID = 1
3059

31-
MAINTENANCE_MODE = True # or ``False`` and use ``maintenance`` command
60+
MAINTENANCE_MODE = False # or ``True`` and use ``maintenance`` command
3261
MAINTENANCE_IGNORE_URLS = (
3362
re.compile(r'^/ignored.*'),
3463
)
File renamed without changes.

test_urls.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
try:
2+
from django.conf.urls import include, url
3+
except ImportError:
4+
from django.conf.urls.defaults import include, url
5+
6+
from django.http import HttpResponse
7+
8+
# URL test patterns for popularity. Use this file to ensure a consistent
9+
# set of URL patterns are used when running unit tests. This test_urls
10+
# module should be referred to by your test class.
11+
12+
urlpatterns = [
13+
url('^$', lambda r: HttpResponse('Rendered response page'), name='test'),
14+
url('^ignored/$', lambda r: HttpResponse('Rendered response page'), name='test'),
15+
]

tox.ini

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[tox]
2+
skipsdist = True
3+
usedevelop = True
4+
toxworkdir = ../toxworkdir/django-maintenance/.tox
5+
6+
envlist =
7+
; py34
8+
py34-dj{111,2}
9+
; py35
10+
py35-dj{111,2,21,22}
11+
; py36
12+
py36-dj{111,2,21,22,3}
13+
; py37
14+
py37-dj{111,2,21,22,3}
15+
; py38
16+
py38-dj{22,3}
17+
18+
[testenv]
19+
install_command = pip install -e . -U {opts} {packages}
20+
commands = python runtests.py
21+
22+
basepython =
23+
py34: python3.4
24+
py35: python3.5
25+
py36: python3.6
26+
py37: python3.7
27+
py38: python3.8
28+
29+
deps =
30+
dj111: Django>=1.11,<2.0
31+
dj2: Django>=2.0,<2.1
32+
dj21: Django>=2.1,<2.2
33+
dj22: Django>=2.2,<3.0
34+
dj3: Django>=3.0,<3.1

0 commit comments

Comments
 (0)