Skip to content

Commit

Permalink
added Django 2.0 and Python 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jamstooks committed Apr 2, 2018
1 parent 7c27b6a commit 661dee5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
language: python
python:
- "2.7"
- "3.6"

env:
- DJANGO_VERSION=">=1.8,<1.9"
- DJANGO_VERSION=">=1.9,<1.10"
- DJANGO_VERSION=">=1.10,<2.0"
- DJANGO_VERSION=">=2.0"

install:
- pip install -q Django$DJANGO_VERSION
Expand Down
21 changes: 21 additions & 0 deletions acme_challenge/tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
SECRET_KEY = "secret!"

ROOT_URLCONF='acme_challenge.urls'

DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
}
}

INSTALLED_APPS=(
'acme_challenge',
)

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
}
]

12 changes: 8 additions & 4 deletions acme_challenge/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
'ViewTest',
)

SLUG = 'test'
CONTENT = 'test content'


class ViewTest(TestCase):

def setUp(self):
"""
Set the settings variables
"""
settings.ACME_CHALLENGE_URL_SLUG = "test"
settings.ACME_CHALLENGE_TEMPLATE_CONTENT = "test content"
settings.ACME_CHALLENGE_URL_SLUG = SLUG
settings.ACME_CHALLENGE_TEMPLATE_CONTENT = CONTENT

def testView(self):
c = Client()
response = c.get("/test")
self.assertEqual(response.content, "test content")
response = c.get("/%s" % SLUG)
self.assertEqual(response.content.decode(), CONTENT)
response = c.get("/test2")
self.assertEqual(response.status_code, 404)
2 changes: 1 addition & 1 deletion acme_challenge/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def get_context_data(self, **kwargs):
context = super(ACMEChallengeView, self).get_context_data(**kwargs)
context['ACME_CHALLENGE_TEMPLATE_CONTENT'] = settings.ACME_CHALLENGE_TEMPLATE_CONTENT
return context
raise Http404
raise Http404
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ def read(fname):
author_email='ben.stookey@gmail.com',
url='https://github.com/jamstooks/django-acme-challenge',
long_description=read("README.md"),
packages=[
'acme_challenge',
'acme_challenge.tests'
],
packages=find_packages(),
include_package_data=True,
classifiers=[
'Environment :: Web Environment',
Expand Down
43 changes: 11 additions & 32 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
#!/usr/bin/env python
import os
import sys

import django
from django.conf import settings
from django.test.utils import get_runner


def main():
settings.configure(
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
}
},
ROOT_URLCONF='acme_challenge.urls',
INSTALLED_APPS=(
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'acme_challenge',)
)

if __name__ == "__main__":
os.environ['DJANGO_SETTINGS_MODULE'] = 'acme_challenge.tests.test_settings'
django.setup()
try:
# Django <= 1.8
from django.test.simple import DjangoTestSuiteRunner
test_runner = DjangoTestSuiteRunner(verbosity=1)
except ImportError:
# Django >= 1.8
from django.test.runner import DiscoverRunner
test_runner = DiscoverRunner(verbosity=1)

failures = test_runner.run_tests(['acme_challenge'])
if failures:
sys.exit(failures)

if __name__ == '__main__':
main()
TestRunner = get_runner(settings)
test_runner = TestRunner()
failures = test_runner.run_tests(["acme_challenge"])
sys.exit(bool(failures))

0 comments on commit 661dee5

Please sign in to comment.