def test_submsissions_and_withdrawals_do_not_appear_in_node_digest( self, digest_type, registration, admin, moderator, daily_moderator): notify_submit(registration, admin) notify_moderator_registration_requests_withdrawal(registration, admin) assert not list(tasks.get_users_emails(digest_type))
def notify_submit(self, ev): user = ev.kwargs.get('user') notify.notify_submit(self.machineable, user) auth = Auth(user) self.machineable.add_log( action=PreprintLog.PUBLISHED, params={'preprint': self.machineable._id}, auth=auth, save=False, )
def test_branded_provider_notification_renders(self, registration, admin, moderator): # Set brand details to be checked in notify_base.mako provider = registration.provider provider.brand = Brand.objects.create(hero_logo_image='not-a-url', primary_color='#FFA500') provider.name = 'Test Provider' provider.save() # Implicitly check that all of our uses of notify_base.mako render with branded details: # # notify_submit renders reviews_submission_confirmation using context from # osf.utils.notifications and stores emails to be picked up in the moderator digest # # _send_Reviews_moderator_emails renders digest_reviews_moderators using context from # website.notifications.tasks notify_submit(registration, admin) tasks._send_reviews_moderator_emails('email_transactional') assert True # everything rendered!
def test_submissions_and_withdrawals_both_appear_in_moderator_digest(self, digest_type, expected_recipient, registration, admin, provider): # Invoke the fixture function to get the recipient because parametrize expected_recipient = expected_recipient(provider) with mock.patch('website.reviews.listeners.mails.send_mail'): notify_submit(registration, admin) notify_moderator_registration_requests_withdrawal(registration, admin) # One user, one provider => one email grouped_notifications = list(tasks.get_moderators_emails(digest_type)) assert len(grouped_notifications) == 1 moderator_message = grouped_notifications[0] assert moderator_message['user_id'] == expected_recipient._id assert moderator_message['provider_id'] == provider.id # No fixed ordering of the entires, so just make sure that # keywords for each action type are in some message updates = moderator_message['info'] assert len(updates) == 2 assert any('submitted' in entry['message'] for entry in updates) assert any('requested withdrawal' in entry['message'] for entry in updates)
def test_submit_notifications(self, registration, moderator, admin, contrib, provider): """ [REQS-96] "As moderator of branded registry, I receive email notification upon admin author(s) submission approval" :param mock_email: :param draft_registration: :return: """ # Set up mock_send_mail as a pass-through to the original function. # This lets us assert on the call/args and also implicitly ensures # that the email acutally renders as normal in send_mail. send_mail = mails.send_mail with mock.patch.object(listeners.mails, 'send_mail', side_effect=send_mail) as mock_send_mail: notify_submit(registration, admin) assert len(mock_send_mail.call_args_list) == 2 admin_message, contrib_message = mock_send_mail.call_args_list assert admin_message == call( admin.email, mails.REVIEWS_SUBMISSION_CONFIRMATION, document_type='registration', domain='http://localhost:5000/', draft_registration=registration.draft_registration.get(), is_creator=True, logo='osf_registries', no_future_emails=[], provider_contact_email=settings.OSF_CONTACT_EMAIL, provider_support_email=settings.OSF_SUPPORT_EMAIL, provider_name=provider.name, provider_url='http://localhost:5000/', referrer=admin, reviewable=registration, user=admin, workflow=None ) assert contrib_message == call( contrib.email, mails.REVIEWS_SUBMISSION_CONFIRMATION, document_type='registration', domain='http://localhost:5000/', draft_registration=registration.draft_registration.get(), is_creator=False, logo='osf_registries', no_future_emails=[], provider_contact_email=settings.OSF_CONTACT_EMAIL, provider_support_email=settings.OSF_SUPPORT_EMAIL, provider_name=provider.name, provider_url='http://localhost:5000/', referrer=admin, reviewable=registration, user=contrib, workflow=None ) assert NotificationDigest.objects.count() == 1 digest = NotificationDigest.objects.last() assert digest.user == moderator assert digest.send_type == 'email_transactional' assert digest.event == 'new_pending_submissions'