コード例 #1
0
 def test_a_unsuccessful_send_to_pub_sub_with_exception(self):
     with self.app.app_context():
         future = MagicMock()
         future.result.side_effect = Exception("bad")
         publisher = MagicMock()
         publisher.publish.return_value = future
         notify = NotifyController()
         notify.publisher = publisher
         with self.assertRaises(NotifyError):
             notify.request_to_notify(
                 email="*****@*****.**",
                 template_name="request_password_change",
                 personalisation=None)
コード例 #2
0
    def test_a_successful_send_to_pub_sub(self):
        with self.app.app_context():
            publisher = MagicMock()
            publisher.topic_path.return_value = 'projects/test-project-id/topics/ras-rm-notify-test'
            notify = NotifyController()
            notify.publisher = publisher
            result = notify.request_to_notify(
                email='*****@*****.**',
                template_name='request_password_change',
                personalisation=None)
            data = b'{"notify": {"email_address": "*****@*****.**", ' \
                   b'"template_id": "request_password_change_id", "personalisation": {}}}'

            publisher.publish.assert_called()
            publisher.publish.assert_called_with(
                'projects/test-project-id/topics/ras-rm-notify-test',
                data=data)
            self.assertIsNone(result)
コード例 #3
0
    def test_a_successful_send_to_pub_sub_with_personalisation(self):
        with self.app.app_context():
            publisher = MagicMock()
            publisher.topic_path.return_value = "projects/test-project-id/topics/ras-rm-notify-test"
            notify = NotifyController()
            notify.publisher = publisher
            personalisation = {
                "first_name": "firstname",
                "last_name": "surname"
            }
            result = notify.request_to_notify(
                email="*****@*****.**",
                template_name="request_password_change",
                personalisation=personalisation)
            data = (
                b'{"notify": {"email_address": "*****@*****.**", '
                b'"template_id": "request_password_change_id", "personalisation": {"first_name": "firstname", '
                b'"last_name": "surname"}}}')

            publisher.publish.assert_called()
            publisher.publish.assert_called_with(
                "projects/test-project-id/topics/ras-rm-notify-test",
                data=data)
            self.assertIsNone(result)