mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Write first two tests
This commit is contained in:
parent
496c91441b
commit
9ab3ca8db7
1 changed files with 28 additions and 4 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from django.test import TestCase
|
||||
from auditlog.models import LogEntry
|
||||
from testapp.models import SimpleModel
|
||||
|
||||
|
||||
|
|
@ -6,11 +7,34 @@ class ModelTest(TestCase):
|
|||
def setUp(self):
|
||||
self.obj_simple = SimpleModel.objects.create(text='I am not difficult.')
|
||||
|
||||
def test_simple_create(self):
|
||||
"""Mutations on simple models are logged correctly."""
|
||||
# Create the object to work with
|
||||
def test_create(self):
|
||||
"""Creation is logged correctly."""
|
||||
# Get the object to work with
|
||||
obj = self.obj_simple
|
||||
|
||||
# Check for log entries
|
||||
self.assertTrue(obj.history.count() == 1, msg="There is one log entry")
|
||||
|
||||
try:
|
||||
history = obj.history.get()
|
||||
except LogEntry.DoesNotExist:
|
||||
self.assertTrue(False, "Log entry exists")
|
||||
else:
|
||||
self.assertEqual(history.action, LogEntry.Action.CREATE, msg="Action is 'CREATE'")
|
||||
self.assertEqual(history.object_repr, str(obj), msg="Representation is equal")
|
||||
|
||||
def test_update(self):
|
||||
"""Updates are logged correctly."""
|
||||
# Get the object to work with
|
||||
obj = self.obj_simple
|
||||
|
||||
# Change something
|
||||
obj.boolean = True
|
||||
obj.save()
|
||||
|
||||
# Check for log entries
|
||||
self.assertTrue(obj.history)
|
||||
self.assertTrue(obj.history.filter(action=LogEntry.Action.UPDATE).count() == 1, msg="There is one log entry for 'UPDATE'")
|
||||
|
||||
history = obj.history.get(action=LogEntry.Action.UPDATE)
|
||||
|
||||
self.assertJSONEqual(history.changes, '{"boolean": ["False", "True"]}', msg="The change is correctly logged")
|
||||
|
|
|
|||
Loading…
Reference in a new issue