mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Added tests for include_fields and exclude_fields
This commit is contained in:
parent
4ae09eb8b4
commit
3a4509b200
3 changed files with 64 additions and 2 deletions
|
|
@ -38,7 +38,6 @@ class AuditLogModelRegistry(object):
|
|||
self._connect_signals(model)
|
||||
else:
|
||||
raise TypeError('Supplied model is not a valid model.')
|
||||
print self._registry
|
||||
|
||||
def contains(self, model):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -60,6 +60,30 @@ class ManyRelatedModel(models.Model):
|
|||
history = AuditlogHistoryField()
|
||||
|
||||
|
||||
class SimpleIncludeModel(models.Model):
|
||||
"""
|
||||
A simple model used for register's include_fields kwarg
|
||||
"""
|
||||
|
||||
label = models.CharField(max_length=100)
|
||||
text = models.TextField(blank=True)
|
||||
|
||||
history = AuditlogHistoryField()
|
||||
|
||||
|
||||
class SimpleExcludeModel(models.Model):
|
||||
"""
|
||||
A simple model used for register's exclude_fields kwarg
|
||||
"""
|
||||
|
||||
label = models.CharField(max_length=100)
|
||||
text = models.TextField(blank=True)
|
||||
|
||||
history = AuditlogHistoryField()
|
||||
|
||||
|
||||
auditlog.register(SimpleModel)
|
||||
auditlog.register(AltPrimaryKeyModel)
|
||||
auditlog.register(ProxyModel)
|
||||
auditlog.register(SimpleIncludeModel, include_fields=['label', ])
|
||||
auditlog.register(SimpleExcludeModel, exclude_fields=['label', ])
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ from django.http import HttpResponse
|
|||
from django.test import TestCase, RequestFactory
|
||||
from auditlog.middleware import AuditlogMiddleware
|
||||
from auditlog.models import LogEntry
|
||||
from testapp.models import SimpleModel, AltPrimaryKeyModel, ProxyModel
|
||||
from testapp.models import SimpleModel, AltPrimaryKeyModel, ProxyModel, \
|
||||
SimpleIncludeModel, SimpleExcludeModel
|
||||
|
||||
|
||||
class SimpleModelTest(TestCase):
|
||||
|
|
@ -139,3 +140,41 @@ class MiddlewareTest(TestCase):
|
|||
|
||||
# Validate result
|
||||
self.assertFalse(pre_save.has_listeners(LogEntry))
|
||||
|
||||
|
||||
class SimpeIncludeModelTest(TestCase):
|
||||
"""Log only changes in include_fields"""
|
||||
|
||||
def test_register_include_fields(self):
|
||||
sim = SimpleIncludeModel(label='Include model', text='Looong text')
|
||||
sim.save()
|
||||
self.assertTrue(sim.history.count() == 1, msg="There is one log entry")
|
||||
|
||||
# Change label, record
|
||||
sim.label = 'Changed label'
|
||||
sim.save()
|
||||
self.assertTrue(sim.history.count() == 2, msg="There are two log entries")
|
||||
|
||||
# Change text, ignore
|
||||
sim.text = 'Short text'
|
||||
sim.save()
|
||||
self.assertTrue(sim.history.count() == 2, msg="There are two log entries")
|
||||
|
||||
|
||||
class SimpeExcludeModelTest(TestCase):
|
||||
"""Log only changes that are not in exclude_fields"""
|
||||
|
||||
def test_register_exclude_fields(self):
|
||||
sem = SimpleIncludeModel(label='Exclude model', text='Looong text')
|
||||
sem.save()
|
||||
self.assertTrue(sem.history.count() == 1, msg="There is one log entry")
|
||||
|
||||
# Change label, ignore
|
||||
sem.label = 'Changed label'
|
||||
sem.save()
|
||||
self.assertTrue(sem.history.count() == 2, msg="There are two log entries")
|
||||
|
||||
# Change text, record
|
||||
sem.text = 'Short text'
|
||||
sem.save()
|
||||
self.assertTrue(sem.history.count() == 2, msg="There are two log entries")
|
||||
|
|
|
|||
Loading…
Reference in a new issue