-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from hsmett/master
Add support Django 1.9, tests, flake8, isort and fix travis
- Loading branch information
Showing
21 changed files
with
218 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[flake8] | ||
ignore=E501 | ||
max-complexity = 100 | ||
exclude = | ||
.tox, | ||
__pycache__, | ||
.git, | ||
*.css, | ||
*.html, | ||
*.xml, | ||
*.yml, | ||
*.txt, | ||
*.md, | ||
*.js, | ||
.flake8 | ||
filename = *.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,4 @@ nosetests.xml | |
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
language: python | ||
python: | ||
- "2.7" | ||
install: pip install . --use-mirrors | ||
script: python setup.py test | ||
env: | ||
- TOXENV=py27-django18 | ||
- TOXENV=py27-django19 | ||
- TOXENV=isort | ||
- TOXENV=flake8 | ||
|
||
install: | ||
- pip install tox | ||
script: tox -e $TOXENV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
develop: | ||
python setup.py develop | ||
|
||
demo: | ||
python setup.py develop | ||
(cd demo; python setup.py develop) | ||
demo syncdb | ||
demo migrate | ||
demo runserver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pyOpenSSL | ||
python-dateutil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[tox] | ||
envlist = flake8,isort,py27-django{18,19} | ||
|
||
[testenv] | ||
usedevelop = True | ||
deps = | ||
django18: Django>=1.8,<1.9 | ||
django19: Django>=1.9,<1.10 | ||
-rrequirements.txt | ||
commands = | ||
django-admin test --settings=x509.tests.settings_for_tests | ||
|
||
[testenv:flake8] | ||
deps = | ||
flake8 | ||
commands = flake8 x509 | ||
|
||
[testenv:isort] | ||
deps = | ||
isort | ||
commands = isort --recursive --atomic --check-only ./x509/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
try: | ||
from django.db.models import UUIDField | ||
from django.db.models import UUIDField # noqa F401 | ||
except ImportError: | ||
# Django < 1.8 | ||
try: | ||
from uuidfield import UUIDField | ||
from uuidfield import UUIDField # noqa F401 | ||
except ImportError: | ||
raise ImportError("In order to use django-x509 with Django < 1.8 you " | ||
"must install django-uuidfield.") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': 'django_x509.sqlite', | ||
}, | ||
} | ||
|
||
USE_I18N = True | ||
USE_L10N = True | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'x509.django', | ||
] | ||
|
||
USE_TZ = True | ||
|
||
SECRET_KEY = '0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
|
||
from django.core.files.uploadedfile import SimpleUploadedFile | ||
from django.test import TestCase | ||
from x509.django.forms import PEMForm | ||
from x509.exceptions import CertificateAlreadyExist | ||
|
||
TEST_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
TEST_EXAMPLES_DIR = os.path.join(os.path.dirname(os.path.dirname(TEST_DIR)), "examples") | ||
|
||
|
||
class CertificateFormTestCase(TestCase): | ||
|
||
def test_when_i_post_empty_form_it_is_a_fail(self): | ||
form = PEMForm(data={}) | ||
self.assertFalse(form.is_valid()) | ||
|
||
def test_when_i_post_a_good_form_it_is_valid(self): | ||
certificat_1_path = os.path.join(TEST_EXAMPLES_DIR, 'localhost', 'client1.crt') | ||
|
||
with open(certificat_1_path, 'rb') as cert_file: | ||
form = PEMForm(data={}, files={'pem_file': SimpleUploadedFile('pem_file', cert_file.read())}) | ||
self.assertTrue(form.is_valid()) | ||
|
||
def test_when_i_post_a_good_form_once_i_got_a_certificate(self): | ||
certificat_1_path = os.path.join(TEST_EXAMPLES_DIR, 'localhost', 'client1.crt') | ||
|
||
with open(certificat_1_path, 'rb') as cert_file: | ||
form = PEMForm(data={}, files={'pem_file': SimpleUploadedFile('pem_file', cert_file.read())}) | ||
form.is_valid() | ||
certificate = form.get_certificate() | ||
self.assertEqual(certificate.serial, "34fed2e8613747cb904f935dc17f1aba") | ||
|
||
def test_when_i_post_a_good_form_twice_i_got_an_exception(self): | ||
certificat_1_path = os.path.join(TEST_EXAMPLES_DIR, 'localhost', 'client1.crt') | ||
|
||
with open(certificat_1_path, 'rb') as cert_file: | ||
form = PEMForm(data={}, files={'pem_file': SimpleUploadedFile('pem_file', cert_file.read())}) | ||
form.is_valid() | ||
form.get_certificate() | ||
|
||
with open(certificat_1_path, 'rb') as cert_file: | ||
form = PEMForm(data={}, files={'pem_file': SimpleUploadedFile('pem_file', cert_file.read())}) | ||
form.is_valid() | ||
with self.assertRaises(CertificateAlreadyExist): | ||
form.get_certificate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from django.contrib.auth.models import User | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.test import TestCase | ||
from django.utils.timezone import now, timedelta | ||
|
||
from ..django.models import Certificate, GenericCertificateM2M | ||
|
||
|
||
class ModelsTestCase(TestCase): | ||
|
||
def test_i_can_create_a_certificate_instance(self): | ||
created = now() | ||
expire = now() + timedelta(days=320) | ||
test_dn = "My Distinguished Nameeeee" | ||
cert = Certificate.objects.create(serial='{12345678-1234-5678-1234-567812345678}', | ||
dn=test_dn, | ||
created_at=created, | ||
expire_at=expire) | ||
self.assertEqual(cert.created_at, created) | ||
self.assertEqual(cert.expire_at, expire) | ||
self.assertEqual(cert.dn, test_dn) | ||
|
||
def test_i_can_create_a_generic_certificate_m2m(self): | ||
cert = Certificate.objects.create(serial='{12345678-1234-5678-1234-567812345678}', | ||
dn="My Distinguished Nameeeee", | ||
created_at=now(), | ||
expire_at=now() + timedelta(days=320)) | ||
user = User.objects.create(username="user") | ||
certif_link = GenericCertificateM2M.objects.create(certificate=cert, | ||
content_type=ContentType.objects.get_for_model(User), | ||
object_id=user.id) | ||
self.assertEqual(certif_link.content_object, user) | ||
self.assertEqual(certif_link.certificate, cert) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
|
||
from django.test import TestCase | ||
from django.test.client import RequestFactory | ||
from x509.django.models import Certificate | ||
from x509.django.views import PEMFormView | ||
from x509.exceptions import CertificateAlreadyExist | ||
|
||
TEST_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
TEST_EXAMPLES_DIR = os.path.join(os.path.dirname(os.path.dirname(TEST_DIR)), "examples") | ||
|
||
|
||
class PEMFormViewTestCase(TestCase): | ||
def setUp(self): | ||
self.factory = RequestFactory() | ||
|
||
def test_i_can_post_a_certificate(self): | ||
certificat_1_path = os.path.join(TEST_EXAMPLES_DIR, 'localhost', 'client1.crt') | ||
with open(certificat_1_path, 'rb') as cert_file: | ||
request = self.factory.post('/add_pem', {'pem_file': cert_file}) | ||
PEMFormView.as_view()(request) | ||
self.assertEqual(1, Certificate.objects.count()) | ||
|
||
def test_i_cant_post_twice_the_same_certificate(self): | ||
certificat_1_path = os.path.join(TEST_EXAMPLES_DIR, 'localhost', 'client1.crt') | ||
with open(certificat_1_path, 'rb') as cert_file: | ||
request = self.factory.post('/add_pem', {'pem_file': cert_file}) | ||
PEMFormView.as_view()(request) | ||
with self.assertRaises(CertificateAlreadyExist): | ||
PEMFormView.as_view()(request) |