-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Custom Pre- and Post- Log Hooks #483
Conversation
34881ee
to
38e166b
Compare
Codecov Report
@@ Coverage Diff @@
## master #483 +/- ##
==========================================
+ Coverage 93.24% 93.55% +0.30%
==========================================
Files 29 29
Lines 859 869 +10
==========================================
+ Hits 801 813 +12
+ Misses 58 56 -2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
2effdc6
to
aead47f
Compare
auditlog/diff.py
Outdated
@@ -98,7 +99,9 @@ def mask_str(value: str) -> str: | |||
return "*" * mask_limit + value[mask_limit:] | |||
|
|||
|
|||
def model_instance_diff(old, new, fields_to_check=None): | |||
def model_instance_diff( | |||
old: Union[Model, None], new: Union[Model, None], fields_to_check=None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use Optional
instead of Union
here
self.assertSignals(LogEntry.Action.UPDATE) | ||
|
||
@patch("auditlog.receivers.LogEntry.objects") | ||
def test_signals_errors(self, log_entry_objects_mock): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be great to test also the post_log
signal here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're all tested already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the error in post_log. Did I miss it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see what you mean. Tbh, initially, I just copied the tests as-is from the other PR. I just went over it now and updated a few things and added the test you suggested.
Thanks @aqeelat for this patch. |
aead47f
to
496a8e6
Compare
I’m not sure that I follow. post_log doesn’t raise errors. The error could be raised in getting the diff or in creating the log entry, not from the signals.Sent from my iPhoneOn Dec 24, 2022, at 3:06 PM, Hasan Ramezani ***@***.***> wrote:
@hramezani commented on this pull request.
In auditlog_tests/tests.py:
+ self.my_post_log_data["is_called"] = True
+ self.my_post_log_data["my_sender"] = sender
+ self.my_post_log_data["my_instance"] = instance
+ self.my_post_log_data["my_action"] = action
+ self.my_post_log_data["my_error"] = error
+
+ pre_log.connect(pre_log_receiver)
+ post_log.connect(post_log_receiver)
+
+ self.obj.text = "Changed Text"
+ self.obj.save()
+
+ self.assertSignals(LogEntry.Action.UPDATE)
+
+ @patch("auditlog.receivers.LogEntry.objects")
+ def test_signals_errors(self, log_entry_objects_mock):
I mean the error in post_log. Did I miss it?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
You will send the error to signal handler, I mean testing the error that is sent to the signal handler. |
Thanks @aqeelat |
Rebase of #275