#21361 Expand unit tests for ObjectChange and testing asserts#21905
#21361 Expand unit tests for ObjectChange and testing asserts#21905jeremystretch merged 8 commits intomainfrom
Conversation
|
@claude /review |
|
Claude finished @arthanson's task in 1m 14s —— View job Code Review
OverviewThis PR adds assertions to verify The changes are correct, useful, and well-scoped. A few observations below: Findings1. Inconsistent use of the helper method (style) The new Single-object tests — uses helper ( self.assertObjectChangeData(objectchange, prechange_data=None, postchange_data=True)Bulk operation tests — uses direct assertions ( self.assertIsNone(oc.prechange_data)
self.assertIsNotNone(oc.postchange_data)For consistency and maintainability, the helper should be used uniformly. This would also mean a single failure message format ("Expected prechange_data to be None") rather than the default assertion messages. 2. Unintuitive parameter convention in The method signature accepts def assertObjectChangeData(self, objectchange, prechange_data, postchange_data):Passing def assertObjectChangeData(self, objectchange, *, prechange_populated: bool, postchange_populated: bool):Or using 3. The For update operations, there's an extra assertion outside the helper: # api.py:373
self.assertObjectChangeData(objectchange, prechange_data=True, postchange_data=True)
self.assertNotEqual(objectchange.prechange_data, objectchange.postchange_data)This is reasonable as-is, but if the helper were ever extended to support this (e.g., a 4. Potential flakiness: This assertion could fail if SummaryThe PR is well-targeted and adds meaningful coverage for a real bug class. The logic is correct. The main actionable feedback is using |
jeremystretch
left a comment
There was a problem hiding this comment.
This feels like a half-measure IMO: It's odd that we'd have a dedicated method solely to evaluate pre-/post-change data and not other commonly tested attributes of a change record. Have you considered expanding the method to also facilitate testing e.g. the action and changelog message?
Personally, I'd prefer we either implement a convenience method to test all of the prudent attributes, or skip it and test each individually with the built-in assertions as we do currently for action and message.
Fixes: #21361
Adds a new assert
assertObjectChangeDataand checks this in the standard API/View test cases. It is just extra assert so the overhead is minimal. The new assertions added to every ObjectChange verification block across views.py and api.py check:This applies to single-object operations (create, edit, delete) and bulk operations (bulk import, bulk edit, bulk delete) in both the UI view tests and API tests.
The primary bug class caught: any code path where snapshot() is not called before a modification, which would leave prechange_data = None on an UPDATE or DELETE record.