Skip to content

Commit

Permalink
add boolean field
Browse files Browse the repository at this point in the history
  • Loading branch information
defrex committed Jul 29, 2013
1 parent 3d9112a commit 8070afa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions encrypted_fields/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class EncryptedEmailField(EncryptedFieldMixin, models.EmailField):
pass


class EncryptedBooleanField(EncryptedFieldMixin, models.BooleanField):
pass


try:
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ['^encrypted_fields\.fields\.\w+Field'])
Expand Down
22 changes: 22 additions & 0 deletions encrypted_fields/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
EncryptedIntegerField,
EncryptedFloatField,
EncryptedEmailField,
EncryptedBooleanField,
)


Expand All @@ -22,6 +23,7 @@ class TestModel(models.Model):
integer = EncryptedIntegerField(null=True)
floating = EncryptedFloatField(null=True)
email = EncryptedEmailField(null=True)
boolean = EncryptedBooleanField(default=False)


class FieldTest(TestCase):
Expand Down Expand Up @@ -124,3 +126,23 @@ def test_email_field_encrypted(self):

fresh_model = TestModel.objects.get(id=model.id)
self.assertEqual(fresh_model.email, plaintext)

def test_boolean_field_encrypted(self):
plaintext = True

model = TestModel()
model.boolean = plaintext
model.save()

ciphertext = self.get_db_value('boolean', model.id)

self.assertNotEqual(plaintext, ciphertext)
self.assertNotEqual(True, ciphertext)
self.assertNotEqual('True', ciphertext)
self.assertNotEqual('true', ciphertext)
self.assertNotEqual('1', ciphertext)
self.assertNotEqual(1, ciphertext)
self.assertTrue(not isinstance(ciphertext, bool))

fresh_model = TestModel.objects.get(id=model.id)
self.assertEqual(fresh_model.boolean, plaintext)

0 comments on commit 8070afa

Please sign in to comment.