Skip to content

Commit

Permalink
added snapshot_of to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Stoerkel committed May 20, 2024
1 parent 32ddc3c commit cd12499
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion history/backends/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _json_snapshot(self, fields, trigger_type):
"""
if not conf.SNAPSHOTS:
return "NULL"
return self._json_object(fields, "NEW")
return self._json_object(fields, trigger_type.snapshot_of)

def _json_changes(self, fields, trigger_type):
"""
Expand Down
4 changes: 4 additions & 0 deletions history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class TriggerType(models.TextChoices):
DELETE = "D", _("Delete")
UPDATE = "U", _("Update")

@property
def snapshot_of(self):
return "OLD" if self == TriggerType.DELETE else "NEW"

@property
def changes(self):
return self == TriggerType.UPDATE
Expand Down
5 changes: 3 additions & 2 deletions tests/custom/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_basics(self):
# Check delete history.
self.assertEqual(delete.session_id, session.session_id)
self.assertEqual(delete.get_user(), "nobody")
self.assertIsNone(delete.snapshot)
self.assertEqual(delete.snapshot, {"id": pk, "name": "Somebody"})
self.assertIsNone(delete.changes)

def test_no_session(self):
Expand Down Expand Up @@ -137,7 +137,8 @@ def test_data_types(self):
self.assertEqual(update.changes["data"][0], data)
self.assertEqual(update.changes["data"][1], replace(data, answer=420))
self.assertEqual(uuid.UUID(update.snapshot["ident"]), obj.ident)
self.assertIsNone(delete.snapshot)
self.assertEqual(delete.snapshot["data"], replace(data, answer=420))
self.assertEqual(uuid.UUID(delete.snapshot["ident"]), obj.ident)
self.assertIsNone(delete.changes)

def test_change_pk(self):
Expand Down

0 comments on commit cd12499

Please sign in to comment.