mirror of
https://github.com/jazzband/django-fernet-encrypted-fields.git
synced 2026-03-16 22:40:27 +00:00
Add tests that ensure keys are retained, update default arg for json TestModel field
This commit is contained in:
parent
1ac8deb229
commit
bbc9b0f768
2 changed files with 15 additions and 2 deletions
|
|
@ -10,4 +10,4 @@ class TestModel(models.Model):
|
|||
floating = EncryptedFloatField(null=True, blank=True)
|
||||
email = EncryptedEmailField(null=True, blank=True)
|
||||
boolean = EncryptedBooleanField(default=False, null=True)
|
||||
json = EncryptedJSONField(default={}, null=True, blank=True)
|
||||
json = EncryptedJSONField(default=dict, null=True, blank=True)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import json
|
||||
import re
|
||||
|
||||
from django.db import connection
|
||||
|
|
@ -207,13 +208,25 @@ class FieldTest(TestCase):
|
|||
model.full_clean()
|
||||
model.save()
|
||||
|
||||
ciphertext = self.get_db_value("json", model.id)
|
||||
ciphertext = json.loads(self.get_db_value("json", model.id))
|
||||
|
||||
|
||||
self.assertNotEqual(dict_values, ciphertext)
|
||||
|
||||
fresh_model = TestModel.objects.get(id=model.id)
|
||||
self.assertEqual(fresh_model.json, dict_values)
|
||||
|
||||
def test_json_field_retains_keys(self):
|
||||
plain_value = {"key": "value", "another_key": "some value"}
|
||||
|
||||
model = TestModel()
|
||||
model.json = plain_value
|
||||
model.full_clean()
|
||||
model.save()
|
||||
|
||||
ciphertext = json.loads(self.get_db_value("json", model.id))
|
||||
|
||||
self.assertEqual(plain_value.keys(), ciphertext.keys())
|
||||
|
||||
|
||||
class RotatedSaltTestCase(TestCase):
|
||||
|
|
|
|||
Loading…
Reference in a new issue