Skip to content

Commit 3c9a2be

Browse files
ENH: Adds support for django 1.9
1 parent 4daa500 commit 3c9a2be

File tree

5 files changed

+80
-44
lines changed

5 files changed

+80
-44
lines changed

django_pph/management/commands/initialize_pph_context.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from django_pph.shamirsecret import ShamirSecret
77
from django_pph.settings import SETTINGS
8-
from django_pph.utils import cache, bin64enc, binary_type
8+
from django_pph.utils import bin64enc, binary_type
99

1010

1111
class Command(BaseCommand):

django_pph/tests.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
from copy import deepcopy
88

9-
from django_pph.utils import get_cache, constant_time_compare
10-
from django_pph.management.commands.initialize_pph_context import Command as \
11-
pph_init
9+
from django_pph.utils import cache, constant_time_compare
10+
from django_pph.management.commands.initialize_pph_context import \
11+
Command as pph_init
1212

13-
cache = get_cache('pph')
1413

1514

1615
def make(password):
@@ -35,8 +34,8 @@ def reset_hasher_state(hasher, backup):
3534

3635

3736
class PolyPasswordHasherTestCase(TestCase):
38-
hasher = get_hasher('pph')
3937

38+
hasher = get_hasher('pph')
4039
# we'll backup everything to avoid some tests from interfering with
4140
# another
4241
hasher.load()
@@ -76,6 +75,8 @@ def test_total_shares(self):
7675
# We create a brand new store, lock it and unlock it. We expect to have
7776
# the secret back at the end of this function.
7877
def test_unlock_store(self):
78+
79+
reset_hasher_state(self.hasher, self.hasherbackup)
7980

8081
password1 = make_share('password1')
8182
password2 = make_share('password2')

django_pph/utils.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
from base64 import b64encode, b64decode
2+
from distutils.version import StrictVersion
3+
4+
import django
5+
if StrictVersion(django.get_version()) < StrictVersion('1.9.0'):
6+
from django.core.cache import get_cache
7+
else:
8+
from django.core.cache import caches
29

3-
from django.core.cache import get_cache
410
from django.utils import six
511
from django.utils import crypto
612

@@ -41,5 +47,10 @@ def constant_time_compare(val1, val2):
4147
b64enc = lambda s: b64encode(s).decode('ascii').strip()
4248
bin64enc = lambda s: b64enc(binary_type(s))
4349
bin64dec = lambda s: binary_type(b64decode(s))
44-
cache = get_cache(SETTINGS['CACHE_ALIAS'])
45-
share_cache = get_cache('share_cache')
50+
51+
if StrictVersion(django.get_version()) < StrictVersion('1.9'):
52+
cache = get_cache(SETTINGS['CACHE_ALIAS'])
53+
share_cache = get_cache('share_cache')
54+
else:
55+
cache = caches[SETTINGS['CACHE_ALIAS']]
56+
share_cache = caches['share_cache']

runtests.py

+36-34
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,47 @@
44
import django
55
from django.conf import settings
66

7+
urlpatterns = []
8+
79

810
DIRNAME = os.path.dirname(__file__)
911

10-
settings.configure(
11-
DEBUG=True,
12-
DATABASES={
13-
'default': {
14-
'ENGINE': 'django.db.backends.sqlite3',
15-
'NAME': 'test.db'
16-
}
17-
},
18-
MIDDLEWARE_CLASSES=(),
19-
INSTALLED_APPS=(
20-
'django.contrib.auth',
21-
'django.contrib.contenttypes',
22-
'django.contrib.sessions',
23-
'django.contrib.admin',
24-
'django_pph',
25-
),
26-
ROOT_URLCONF='runtests',
27-
PASSWORD_HASHERS=(
28-
'django_pph.hashers.PolyPasswordHasher',
29-
),
30-
CACHES={
31-
'default': {
32-
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
12+
if not settings.configured:
13+
settings.configure(
14+
DEBUG=True,
15+
DATABASES={
16+
'default': {
17+
'ENGINE': 'django.db.backends.sqlite3',
18+
'NAME': 'test.db'
19+
}
3320
},
34-
'pph': {
35-
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
36-
'LOCATION': 'pph_cache',
37-
'TIMEOUT': None,
21+
MIDDLEWARE_CLASSES=(),
22+
INSTALLED_APPS=(
23+
'django.contrib.auth',
24+
'django.contrib.contenttypes',
25+
'django.contrib.sessions',
26+
'django.contrib.admin',
27+
'django_pph',
28+
),
29+
ROOT_URLCONF='runtests',
30+
PASSWORD_HASHERS=(
31+
'django_pph.hashers.PolyPasswordHasher',
32+
),
33+
CACHES={
34+
'default': {
35+
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
36+
},
37+
'pph': {
38+
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
39+
'LOCATION': 'pph_cache',
40+
'TIMEOUT': None,
41+
},
42+
'share_cache': {
43+
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
44+
'LOCATION': 'share_table',
45+
}
3846
},
39-
'share_cache': {
40-
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
41-
'LOCATION': 'share_table',
42-
}
43-
},
44-
)
45-
47+
)
4648

4749
if hasattr(django, 'setup'):
4850
django.setup()

tox.ini

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
[tox]
22
envlist =
3+
# Django 1.9
4+
py3.5-dj1.9,
5+
py3.4-dj1.9,
6+
py2.7-dj1.9,
7+
38
# Django 1.8
49
py3.4-dj1.8,
510
py3.3-dj1.8,
@@ -37,6 +42,9 @@ commands =
3742
{envpython} runtests.py initialize_pph_context
3843
{envpython} runtests.py
3944

45+
deps-1.9=
46+
Django>=1.9
47+
4048
deps-1.8=
4149
Django>=1.8,<1.9
4250

@@ -52,7 +60,21 @@ deps-1.5 =
5260
deps-1.4 =
5361
Django>=1.4,<1.5
5462

55-
# Django 1.7
63+
# Django 1.9
64+
[testenv:py3.5-dj1.9]
65+
basepython = python3.5
66+
deps = {[testenv]deps-1.9}
67+
68+
[testenv:py3.4-dj1.9]
69+
basepython = python3.4
70+
deps = {[testenv]deps-1.9}
71+
72+
[testenv:py2.7-dj1.9]
73+
basepython = python2.7
74+
deps = {[testenv]deps-1.9}
75+
76+
77+
# Django 1.8
5678
[testenv:py3.4-dj1.8]
5779
basepython = python3.4
5880
deps = {[testenv]deps-1.8}

0 commit comments

Comments
 (0)