Add tests that ensure keys are retained, update default arg for json TestModel field

This commit is contained in:
Friday Godswill 2023-07-18 07:15:47 +02:00
parent 1ac8deb229
commit bbc9b0f768
2 changed files with 15 additions and 2 deletions

View file

@ -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)

View file

@ -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):