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 test_notify_moderator_registration_requests_withdrawal_notifications(
            self, moderator, daily_moderator, registration, admin, provider):
        """
         [REQS-106] "As moderator, I receive registration withdrawal request notification email"

        :param mock_email:
        :param draft_registration:
        :param contrib:
        :return:
        """
        assert NotificationDigest.objects.count() == 0
        notify_moderator_registration_requests_withdrawal(registration, admin)

        assert NotificationDigest.objects.count() == 2

        daily_digest = NotificationDigest.objects.get(send_type='email_digest')
        transactional_digest = NotificationDigest.objects.get(
            send_type='email_transactional')
        assert daily_digest.user == daily_moderator
        assert transactional_digest.user == moderator

        for digest in (daily_digest, transactional_digest):
            assert 'requested withdrawal' in digest.message
            assert digest.event == 'new_pending_withdraw_requests'
            assert digest.provider == provider
    def test_moderator_digest_emails_render(self, registration, admin, moderator):
        notify_moderator_registration_requests_withdrawal(registration, admin)
        # Set up mock_send_mail as a pass-through to the original function.
        # This lets us assert on the call count/args and also implicitly
        # ensures that the email acutally renders as normal in send_mail.
        send_mail = mails.send_mail
        with mock.patch.object(tasks.mails, 'send_mail', side_effect=send_mail) as mock_send_mail:
            tasks._send_reviews_moderator_emails('email_transactional')

        mock_send_mail.assert_called()
    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)