[ENG-8410] Refactor Notifications Phase 1#11176
Conversation
ccfc523 to
afc3815
Compare
| view_category = 'files' | ||
| view_name = 'file-detail' | ||
|
|
||
| def get_serializer_class(self): |
There was a problem hiding this comment.
removed for being extraneous
afc3815 to
b6bbeed
Compare
brianjgeiger
left a comment
There was a problem hiding this comment.
Drive by: a good ratio of deleted to added lines. I have a couple of questions around logs and migrations. Expect a more thorough review from @cslzchen.
15289a0 to
4c50c6c
Compare
| boa_support_email=boa_settings.BOA_SUPPORT_EMAIL, | ||
| osf_support_email=osf_settings.OSF_SUPPORT_EMAIL, | ||
| ) | ||
| self.mock_send_grid.assert_called() |
There was a problem hiding this comment.
A bit lazy just to assert this but asserting every single thing in a template is unmaintainable.
There was a problem hiding this comment.
hmm ... why is it unmaintainable? Did the test fail and we can't figure out how to fix it? The reason why we assert the details for send_mail is because we want to make sure we send the email with correct information.
911befe to
e2a16ac
Compare
removes notifications for OSF Meetings
removes notifications for OSF Comments
removes OSF Quickfiles code
add mailhog integration to improve email tests
e2a16ac to
a2dd86a
Compare
brianjgeiger
left a comment
There was a problem hiding this comment.
One last historical migration change to revert.
| migrations.RunSQL( | ||
| [ | ||
| """ | ||
| CREATE UNIQUE INDEX one_quickfiles_per_user ON public.osf_abstractnode USING btree (creator_id, type, is_deleted) WHERE (((type)::text = 'osf.quickfilesnode'::text) AND (is_deleted = false)); |
There was a problem hiding this comment.
Shouldn't this be reverted as well?
cslzchen
left a comment
There was a problem hiding this comment.
The review is for future references in phase 2, some of the comments may have been outdated when I submit the review. In addition, some issues are too repetitive to comment on every occurrence.
- My major concern is the way how we test
send_mail. With your change, it no longer tests the correctness of the mail (i.e. the arguments that are passed in to build the template). Some even only test thatsend_mailis called while some test limited info such as the subject. This is something that needs to be fixed in phase 2. - One suggestion (for future work like this) is to avoid one big PR. Removing group, removing notifications, removing quickfile and the mailhog work seem to be independent of each other (maybe I am wrong). I think 4 small phases/releases would have been better.
| - Needed for quickfiles feature: | ||
| ```bash | ||
| docker compose up -d ember_osf_web | ||
| ``` | ||
| - Needed for ember app: | ||
| - `docker-compose up -d ember_osf_web` |
There was a problem hiding this comment.
- keep the format consistent (i.e. use ``` instead of `)
docker compose
| boa_support_email=boa_settings.BOA_SUPPORT_EMAIL, | ||
| osf_support_email=osf_settings.OSF_SUPPORT_EMAIL, | ||
| ) | ||
| self.mock_send_grid.assert_called() |
There was a problem hiding this comment.
hmm ... why is it unmaintainable? Did the test fail and we can't figure out how to fix it? The reason why we assert the details for send_mail is because we want to make sure we send the email with correct information.
|
|
||
| # overrides GenericAPIView | ||
| def get_queryset(self): | ||
| def get_queryset(self, *args, **kwargs): |
There was a problem hiding this comment.
GenericAPIView has get_queryset(self). Why do we have to change the signature?
| with mock.patch('framework.auth.views.mails.send_mail') as mock_send_mail: | ||
| context_data = self.make_mailgun_payload(crossref_response=error_xml) | ||
| app.post(url, context_data) | ||
| assert mock_send_mail.called | ||
| context_data = self.make_mailgun_payload(crossref_response=error_xml) | ||
| app.post(url, context_data) | ||
| assert mock_send_grid.called |
There was a problem hiding this comment.
For myself, same question on why we can't assert sent_mail but switched to test send_grid (many occurrences), maybe related to one of the changes?
add mailhog integration to improve email tests
| # Python 3.6 does not support mock.call_args.args/kwargs | ||
| # Instead, mock.call_args[0] is positional args, mock.call_args[1] is kwargs | ||
| # (note, this is compatible with later versions) |
There was a problem hiding this comment.
Unrelated to your changes but since we are on python 3.12, should we remote this comment and optionally update the code too?
| forgot_password = 'forgotpassword' if settings.DOMAIN.endswith('/') else '/forgotpassword' | ||
| mock_send_mail.assert_called_with( | ||
| to_addr=user.username, | ||
| mail=mails.INSTITUTION_DEACTIVATION, | ||
| user=user, | ||
| forgot_password_link=f'{settings.DOMAIN}{forgot_password}', | ||
| osf_support_email=settings.OSF_SUPPORT_EMAIL | ||
| ) | ||
| mock_send_grid.assert_called() |
There was a problem hiding this comment.
same here, we no longer test the correctness of the email content, which beats the goal of the test.
| @mock.patch('website.project.views.contributor.mails.send_mail') | ||
| def test_add_contributors_sends_contributor_added_signal(self, mock_send_mail, node, auth): | ||
| def test_add_contributors_sends_contributor_added_signal(self, node, auth): |
There was a problem hiding this comment.
If I understand this correctly, we no longer need to mock send mail because we have mail hog running to actually send the mail during testing.
There was a problem hiding this comment.
That's not accurate mailhog isn't used here.
| def test_set_permissions_raises_error_if_only_admins_permissions_are_reduced(self, node): | ||
| # creator is the only admin | ||
| with pytest.raises(NodeStateError) as excinfo: | ||
| node.set_permissions(node.creator, permissions=WRITE) | ||
| assert excinfo.value.args[0] == 'Must have at least one registered admin contributor' |
There was a problem hiding this comment.
Should this part be kept?
| users, auth=auth, save=True, | ||
| ) | ||
|
|
||
| def test_manage_contributors_no_registered_admins(self, node, auth): |
There was a problem hiding this comment.
Not sure if possible, can this be changed to test without using group?
| assert len(mock_send_grid.call_args_list) == 2 | ||
| admin_message, contrib_message = mock_send_grid.call_args_list | ||
|
|
||
| assert admin_message == call( |
There was a problem hiding this comment.
Same concern in this file on email correctness test
There was a problem hiding this comment.
Yeah I actually was basing my feeling on this off @jwalz said about "Change detection tests" basically the tests shouldn't check for template variables because wording changes could break tests, so I wasn't just being lazy something here, by not checking.
Purpose
This is the first phase of the notifications refactor project, that will update and improve the notifications model. Theis first phase is to remove all the code assassinated with notifications no longer being sent.
Changes
QA Notes
Please make verification statements inspired by your code and what your code touches.
What are the areas of risk?
Any concerns/considerations/questions that development raised?
Documentation
Side Effects
Ticket