Skip to content

Commit 8070afa

Browse files
committed
add boolean field
1 parent 3d9112a commit 8070afa

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

encrypted_fields/fields.py

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class EncryptedEmailField(EncryptedFieldMixin, models.EmailField):
6969
pass
7070

7171

72+
class EncryptedBooleanField(EncryptedFieldMixin, models.BooleanField):
73+
pass
74+
75+
7276
try:
7377
from south.modelsinspector import add_introspection_rules
7478
add_introspection_rules([], ['^encrypted_fields\.fields\.\w+Field'])

encrypted_fields/tests.py

+22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
EncryptedIntegerField,
1313
EncryptedFloatField,
1414
EncryptedEmailField,
15+
EncryptedBooleanField,
1516
)
1617

1718

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

2628

2729
class FieldTest(TestCase):
@@ -124,3 +126,23 @@ def test_email_field_encrypted(self):
124126

125127
fresh_model = TestModel.objects.get(id=model.id)
126128
self.assertEqual(fresh_model.email, plaintext)
129+
130+
def test_boolean_field_encrypted(self):
131+
plaintext = True
132+
133+
model = TestModel()
134+
model.boolean = plaintext
135+
model.save()
136+
137+
ciphertext = self.get_db_value('boolean', model.id)
138+
139+
self.assertNotEqual(plaintext, ciphertext)
140+
self.assertNotEqual(True, ciphertext)
141+
self.assertNotEqual('True', ciphertext)
142+
self.assertNotEqual('true', ciphertext)
143+
self.assertNotEqual('1', ciphertext)
144+
self.assertNotEqual(1, ciphertext)
145+
self.assertTrue(not isinstance(ciphertext, bool))
146+
147+
fresh_model = TestModel.objects.get(id=model.id)
148+
self.assertEqual(fresh_model.boolean, plaintext)

0 commit comments

Comments
 (0)