Skip to content

Commit

Permalink
Added support for Django 2.x+ (#50)
Browse files Browse the repository at this point in the history
* Added support for Django 2.x+
* Updated requirements for testing
* Updated travis config with Python 3.6 and additional environments
* Updated CHANGELOG and README
  • Loading branch information
peterfarrell authored Aug 31, 2018
1 parent 6281aaa commit 643c87f
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
python:
- 3.4
- 3.6
script: make test
notifications:
email: false
Expand All @@ -13,6 +13,8 @@ env:
- DJANGO='django>=1.8,<1.9'
- DJANGO='django>=1.9,<1.10'
- DJANGO='django>=1.10,<1.11'
- DJANGO='django>=2.0,<2.1'
- DJANGO='django>=2.1,<2.2'
- DJANGO='--upgrade --pre django'
matrix:
fast_finish: true
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.1.1

* Added support for Django 2.x+
* Updated requirements for testing
* Updated travis config with Python 3.6 and additional environments

## 2.1.0

Thanks to @peterfarrell:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ PGP symmetric fields are:
## Requirements

- postgres with `pgcrypto`
- Supports Django 1.8 to 2.1
- Compatible with Python 3 only


## Installation

Expand Down
4 changes: 2 additions & 2 deletions pgcrypto/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DateField(forms.DateField):
def __init__(self, input_formats=None, *args, **kwargs):
"""Init that pops off the max_length attribute."""
kwargs.pop('max_length', None)
super().__init__(input_formats, *args, **kwargs)
super().__init__(input_formats=input_formats, **kwargs)


class DateTimeField(forms.DateTimeField):
Expand All @@ -24,4 +24,4 @@ class DateTimeField(forms.DateTimeField):
def __init__(self, input_formats=None, *args, **kwargs):
"""Init that pops off the max_length attribute."""
kwargs.pop('max_length', None)
super().__init__(input_formats, *args, **kwargs)
super().__init__(input_formats=input_formats, **kwargs)
2 changes: 1 addition & 1 deletion pgcrypto/lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DateLookupBase(Lookup):
operator = None # Set in subclasses

def __init__(self, lhs, rhs):
"""Implementing an abstract class."""
"""Implement an abstract class."""
super(DateLookupBase, self).__init__(lhs, rhs) # pragma: no cover

def as_sql(self, qn, connection):
Expand Down
2 changes: 2 additions & 0 deletions pgcrypto/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class HashMixin:
`HashMixin` uses 'pgcrypto' to encrypt data in a postgres database.
"""
def __init__(self, original=None, *args, **kwargs):
"""Tells the init the original attr."""
self.original = original

super(HashMixin, self).__init__(*args, **kwargs)

def pre_save(self, model_instance, add):
"""Save the original_value."""
if self.original:
original_value = getattr(model_instance, self.original)
setattr(model_instance, self.attname, original_value)
Expand Down
11 changes: 6 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
colour-runner==0.0.5
coverage==4.3.1
dj-database-url==0.4.2
django>=1.10,<1.11
django>=1.10,<2.2
factory-boy==2.8.1
flake8-docstrings==1.0.2
flake8-docstrings==1.3.0
flake8-import-order==0.11
flake8==3.2.1
flake8==3.5.0
incuna-test-utils==6.6.0
psycopg2==2.6.2
pyflakes==1.4.0
psycopg2-binary==2.7.5
pyflakes==1.6.0
pycodestyle==2.3.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import find_packages, setup


version = '2.1.0'
version = '2.1.1'


setup(
Expand Down
6 changes: 4 additions & 2 deletions tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

class EncryptedModelFactory(factory.DjangoModelFactory):
"""Factory to generate hashed and encrypted data."""
class Meta:
model = EncryptedModel

digest_field = factory.Sequence('Text digest {}'.format)
hmac_field = factory.Sequence('Text hmac {}'.format)
Expand All @@ -22,3 +20,7 @@ class Meta:
pgp_sym_field = factory.Sequence('Text with symmetric key {}'.format)

date_pgp_sym_field = date.today()

class Meta:
"""Sets up meta for test factory."""
model = EncryptedModel
8 changes: 6 additions & 2 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ class EncryptedModelManager(managers.PGPManager):
class EncryptedModel(models.Model):
"""Dummy model used for tests to check the fields."""
digest_field = fields.TextDigestField(blank=True, null=True)
digest_with_original_field = fields.TextDigestField(blank=True, null=True, original='pgp_sym_field')
digest_with_original_field = fields.TextDigestField(blank=True, null=True,
original='pgp_sym_field')
hmac_field = fields.TextHMACField(blank=True, null=True)
hmac_with_original_field = fields.TextHMACField(blank=True, null=True, original='pgp_sym_field')
hmac_with_original_field = fields.TextHMACField(blank=True, null=True,
original='pgp_sym_field')

email_pgp_pub_field = fields.EmailPGPPublicKeyField(blank=True, null=True)
integer_pgp_pub_field = fields.IntegerPGPPublicKeyField(blank=True, null=True)
Expand All @@ -25,6 +27,7 @@ class EncryptedModel(models.Model):
datetime_pgp_sym_field = fields.DateTimePGPSymmetricKeyField(blank=True, null=True)

class Meta:
"""Sets up the meta for the test model."""
app_label = 'tests'


Expand All @@ -33,4 +36,5 @@ class EncryptedModelWithManager(EncryptedModel):
objects = EncryptedModelManager()

class Meta:
"""Sets up the meta for the test manager."""
proxy = True
4 changes: 3 additions & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ def test_digest_with_original_lookup(self):
expected = EncryptedModelFactory.create(pgp_sym_field=value)
EncryptedModelFactory.create()

queryset = EncryptedModel.objects.filter(digest_with_original_field__hash_of=value)
queryset = EncryptedModel.objects.filter(
digest_with_original_field__hash_of=value
)
self.assertCountEqual(queryset, [expected])

def test_hmac_lookup(self):
Expand Down

0 comments on commit 643c87f

Please sign in to comment.