Skip to content

Commit af7aade

Browse files
committed
Add tests and changelog for auditlog sortkey columns
1 parent d554364 commit af7aade

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

changelog.d/3757.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Auditlog entries now store sortable display names for actor, object, and target, enabling sorting and searching on these columns. Links to detail pages are shown when the referenced object still exists.

tests/integration/auditlog_test.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,51 @@ def test_find_name(self):
8686
name = find_modelname(self.justification)
8787
self.assertEqual(name, 'blocked_reason')
8888

89+
def test_when_log_entry_created_then_actor_sortkey_is_set(self):
90+
LogEntry.add_log_entry(
91+
self.justification, 'sortkey test', '{actor} did something'
92+
)
93+
log_entry = LogEntry.objects.filter(verb='sortkey test').get()
94+
self.assertEqual(log_entry.actor_sortkey, str(self.justification))
95+
96+
def test_when_log_entry_has_object_then_object_sortkey_is_set(self):
97+
other = Justification.objects.create(name='object_test')
98+
LogEntry.add_log_entry(
99+
self.justification,
100+
'object sortkey test',
101+
'{actor} edited {object}',
102+
object=other,
103+
)
104+
log_entry = LogEntry.objects.filter(verb='object sortkey test').get()
105+
self.assertEqual(log_entry.object_sortkey, str(other))
106+
107+
def test_when_log_entry_has_no_object_then_object_sortkey_is_null(self):
108+
LogEntry.add_log_entry(
109+
self.justification, 'no object test', '{actor} did something'
110+
)
111+
log_entry = LogEntry.objects.filter(verb='no object test').get()
112+
self.assertIsNone(log_entry.object_sortkey)
113+
114+
def test_when_log_entry_has_target_then_target_sortkey_is_set(self):
115+
obj = Justification.objects.create(name='target_obj')
116+
target = Justification.objects.create(name='target_test')
117+
LogEntry.add_log_entry(
118+
self.justification,
119+
'target sortkey test',
120+
'{actor} sent {object} to {target}',
121+
object=obj,
122+
target=target,
123+
)
124+
log_entry = LogEntry.objects.filter(verb='target sortkey test').get()
125+
self.assertEqual(log_entry.target_sortkey, str(target))
126+
127+
def test_when_log_entry_has_no_target_then_target_sortkey_is_null(self):
128+
LogEntry.add_log_entry(
129+
self.justification, 'no target test', '{actor} did something'
130+
)
131+
log_entry = LogEntry.objects.filter(verb='no target test').get()
132+
self.assertIsNone(log_entry.target_sortkey)
133+
89134

90135
class AuditlogUtilsTestCase(TestCase):
91136
def setUp(self):

0 commit comments

Comments
 (0)