Example #1
0
    def test_jinja_templates_render(self, notification, pyramid_config,
                                    pyramid_request):
        """Ensure that the jinja templates don't contain syntax errors"""
        pyramid_config.include('pyramid_jinja2')
        pyramid_config.add_jinja2_extension('h.jinja_extensions.Filters')

        generate(pyramid_request, notification)
Example #2
0
    def test_falls_back_to_individual_page_if_no_bouncer(self,
                                                         notification,
                                                         parent_user,
                                                         pyramid_request,
                                                         reply_user,
                                                         html_renderer,
                                                         text_renderer,
                                                         links):
        """
        It link to individual pages if bouncer isn't available.

        If bouncer isn't enabled direct links in reply notification emails
        should fall back to linking to the reply's individual page, instead of
        the bouncer direct link.

        """
        # incontext_link() returns None if bouncer isn't available.
        links.incontext_link.return_value = None

        generate(pyramid_request, notification)

        expected_context = {
            'document_title': 'My fascinating page',
            'document_url': 'http://example.org/',
            'parent': notification.parent,
            'parent_user': parent_user,
            'reply_user_url': 'http://example.com/stream/user/patricia',
            'reply': notification.reply,
            'reply_url': 'http://example.com/ann/bar456',
            'reply_user': reply_user,
            'reply_user_url': 'http://example.com/stream/user/ron',
            'unsubscribe_url': 'http://example.com/unsub/FAKETOKEN',
        }
        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #3
0
    def test_jinja_templates_render(self, notification, pyramid_config,
                                    pyramid_request):
        """Ensure that the jinja templates don't contain syntax errors."""
        pyramid_config.include("pyramid_jinja2")
        pyramid_config.include("h.jinja_extensions")

        generate(pyramid_request, notification)
Example #4
0
    def test_falls_back_to_individual_page_if_no_bouncer(
            self, notification, parent_user, pyramid_request, reply_user,
            html_renderer, text_renderer, links):
        """
        It link to individual pages if bouncer isn't available.

        If bouncer isn't enabled direct links in reply notification emails
        should fall back to linking to the reply's individual page, instead of
        the bouncer direct link.

        """
        # incontext_link() returns None if bouncer isn't available.
        links.incontext_link.return_value = None

        generate(pyramid_request, notification)

        expected_context = {
            'document_title': 'My fascinating page',
            'document_url': 'http://example.org/',
            'parent': notification.parent,
            'parent_user_display_name': parent_user.display_name,
            'parent_user_url': 'http://example.com/stream/user/patricia',
            'reply': notification.reply,
            'reply_url': 'http://example.com/ann/bar456',
            'reply_user_display_name': reply_user.display_name,
            'reply_user_url': 'http://example.com/stream/user/ron',
            'unsubscribe_url': 'http://example.com/unsub/FAKETOKEN',
        }
        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #5
0
    def test_calls_renderers_with_appropriate_context(
        self,
        notification,
        parent_user,
        pyramid_request,
        reply_user,
        html_renderer,
        text_renderer,
        links,
    ):
        generate(pyramid_request, notification)

        expected_context = {
            "document_title": "My fascinating page",
            "document_url": "http://example.org/",
            "parent": notification.parent,
            "parent_user_display_name": parent_user.display_name,
            "parent_user_url": "http://example.com/stream/user/patricia",
            "reply": notification.reply,
            "reply_url": links.incontext_link.return_value,
            "reply_user_display_name": reply_user.display_name,
            "reply_user_url": "http://example.com/stream/user/ron",
            "unsubscribe_url": "http://example.com/unsub/FAKETOKEN",
        }
        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #6
0
    def test_calls_token_serializer_with_correct_arguments(
        self, notification, pyramid_request, token_serializer
    ):
        generate(pyramid_request, notification)

        token_serializer.dumps.assert_called_once_with(
            {"type": "reply", "uri": "acct:[email protected]"}
        )
Example #7
0
    def test_falls_back_to_target_uri_for_document_title(
            self, notification, pyramid_request, html_renderer, text_renderer):
        notification.document.title = None

        generate(pyramid_request, notification)

        html_renderer.assert_(document_title='http://example.org/')
        text_renderer.assert_(document_title='http://example.org/')
Example #8
0
    def test_jinja_templates_render(self,
                                    notification,
                                    pyramid_config,
                                    pyramid_request):
        """Ensure that the jinja templates don't contain syntax errors"""
        pyramid_config.include('pyramid_jinja2')
        pyramid_config.add_jinja2_extension('h.jinja_extensions.Filters')

        generate(pyramid_request, notification)
Example #9
0
    def test_calls_token_serializer_with_correct_arguments(
            self, notification, pyramid_request, token_serializer):
        generate(pyramid_request, notification)

        token_serializer.dumps.assert_called_once_with({
            'type':
            'reply',
            'uri':
            'acct:[email protected]',
        })
Example #10
0
    def test_urls_not_set_for_third_party_users(
        self, notification, pyramid_request, html_renderer, text_renderer
    ):
        pyramid_request.default_authority = "foo.org"
        expected_context = {"parent_user_url": None, "reply_user_url": None}

        generate(pyramid_request, notification)

        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #11
0
    def test_calls_token_serializer_with_correct_arguments(self,
                                                           notification,
                                                           pyramid_request,
                                                           token_serializer):
        generate(pyramid_request, notification)

        token_serializer.dumps.assert_called_once_with({
            'type': 'reply',
            'uri': 'acct:[email protected]',
        })
Example #12
0
    def test_falls_back_to_target_uri_for_document_title(self,
                                                         notification,
                                                         pyramid_request,
                                                         html_renderer,
                                                         text_renderer):
        notification.document.title = None

        generate(pyramid_request, notification)

        html_renderer.assert_(document_title='http://example.org/')
        text_renderer.assert_(document_title='http://example.org/')
Example #13
0
    def test_falls_back_to_target_uri_for_document_title(
            self, req, notification, storage_driver, html_renderer,
            text_renderer):
        if storage_driver == 'elastic':
            notification.document['title'] = []
        else:
            notification.document.meta[0].value = []

        generate(req, notification)

        html_renderer.assert_(document_title='http://example.org/')
        text_renderer.assert_(document_title='http://example.org/')
Example #14
0
    def test_urls_set_for_first_party_users(
        self, notification, pyramid_request, html_renderer, text_renderer
    ):
        expected_context = {
            "parent_user_url": "http://example.com/stream/user/patricia",
            "reply_user_url": "http://example.com/stream/user/ron",
        }

        generate(pyramid_request, notification)

        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #15
0
    def test_urls_not_set_for_third_party_users(self, notification,
                                                pyramid_request, html_renderer,
                                                text_renderer):
        pyramid_request.authority = 'foo.org'
        expected_context = {
            'parent_user_url': None,
            'reply_user_url': None,
        }

        generate(pyramid_request, notification)

        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #16
0
    def test_urls_set_for_first_party_users(self,
                                            notification,
                                            pyramid_request,
                                            html_renderer,
                                            text_renderer):
        expected_context = {
            'parent_user_url': 'http://example.com/stream/user/patricia',
            'reply_user_url': 'http://example.com/stream/user/ron',
        }

        generate(pyramid_request, notification)

        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #17
0
    def test_falls_back_to_target_uri_for_document_title(self,
                                                         notification,
                                                         pyramid_request,
                                                         storage_driver,
                                                         html_renderer,
                                                         text_renderer):
        if storage_driver == 'elastic':
            notification.document['title'] = []
        else:
            notification.document.meta[0].value = []

        generate(pyramid_request, notification)

        html_renderer.assert_(document_title='http://example.org/')
        text_renderer.assert_(document_title='http://example.org/')
Example #18
0
    def test_urls_not_set_for_third_party_users(self,
                                                notification,
                                                pyramid_request,
                                                html_renderer,
                                                text_renderer):
        pyramid_request.authority = 'foo.org'
        expected_context = {
            'parent_user_url': None,
            'reply_user_url': None,
        }

        generate(pyramid_request, notification)

        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #19
0
    def test_returns_usernames_if_no_display_names(self, notification,
                                                   pyramid_request,
                                                   html_renderer,
                                                   text_renderer, parent_user,
                                                   reply_user):
        parent_user.display_name = None
        reply_user.display_name = None

        generate(pyramid_request, notification)

        expected_context = {
            'parent_user_display_name': parent_user.username,
            'reply_user_display_name': reply_user.username
        }
        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #20
0
    def test_returns_usernames_if_no_display_names(self,
                                                   notification,
                                                   pyramid_request,
                                                   html_renderer,
                                                   text_renderer,
                                                   parent_user,
                                                   reply_user):
        parent_user.display_name = None
        reply_user.display_name = None

        generate(pyramid_request, notification)

        expected_context = {'parent_user_display_name': parent_user.username,
                            'reply_user_display_name': reply_user.username}
        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #21
0
    def test_returns_subject_with_reply_username(
        self, notification, pyramid_request, reply_user
    ):
        reply_user.display_name = None
        _, subject, _, _ = generate(pyramid_request, notification)

        assert subject == "ron has replied to your annotation"
Example #22
0
    def test_returns_text_and_body_results_from_renderers(
            self, notification, pyramid_request, html_renderer, text_renderer):
        html_renderer.string_response = 'HTML output'
        text_renderer.string_response = 'Text output'

        _, _, text, html = generate(pyramid_request, notification)

        assert html == 'HTML output'
        assert text == 'Text output'
Example #23
0
    def test_supports_non_ascii_display_names(self, notification,
                                              pyramid_request, html_renderer,
                                              text_renderer, parent_user,
                                              reply_user):
        parent_user.display_name = 'Parent 👩'
        reply_user.display_name = 'Child 👧'

        (_, subject, _, _) = generate(pyramid_request, notification)

        assert subject == 'Child 👧 has replied to your annotation'
Example #24
0
    def test_calls_renderers_with_appropriate_context(
            self, notification, parent_user, pyramid_request, reply_user,
            html_renderer, text_renderer, links):
        generate(pyramid_request, notification)

        expected_context = {
            'document_title': 'My fascinating page',
            'document_url': 'http://example.org/',
            'parent': notification.parent,
            'parent_user_display_name': parent_user.display_name,
            'parent_user_url': 'http://example.com/stream/user/patricia',
            'reply': notification.reply,
            'reply_url': links.incontext_link.return_value,
            'reply_user_display_name': reply_user.display_name,
            'reply_user_url': 'http://example.com/stream/user/ron',
            'unsubscribe_url': 'http://example.com/unsub/FAKETOKEN',
        }
        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #25
0
    def test_calls_renderers_with_appropriate_context(self, req, notification,
                                                      parent_user, reply_user,
                                                      html_renderer,
                                                      text_renderer):
        generate(req, notification)

        expected_context = {
            'document_title': 'My fascinating page',
            'document_url': 'http://example.org/',
            'parent': notification.parent,
            'parent_url': 'http://example.com/ann/foo123',
            'parent_user': parent_user,
            'reply': notification.reply,
            'reply_url': 'http://example.com/ann/bar456',
            'reply_user': reply_user,
            'reply_user_url': 'http://example.com/stream/user/ron',
            'unsubscribe_url': 'http://example.com/unsub/FAKETOKEN',
        }
        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #26
0
    def test_returns_text_and_body_results_from_renderers(self,
                                                          notification,
                                                          pyramid_request,
                                                          html_renderer,
                                                          text_renderer):
        html_renderer.string_response = 'HTML output'
        text_renderer.string_response = 'Text output'

        _, _, text, html = generate(pyramid_request, notification)

        assert html == 'HTML output'
        assert text == 'Text output'
Example #27
0
    def test_supports_non_ascii_display_names(self,
                                              notification,
                                              pyramid_request,
                                              html_renderer,
                                              text_renderer,
                                              parent_user,
                                              reply_user):
        parent_user.display_name = 'Parent 👩'
        reply_user.display_name = 'Child 👧'

        (_, subject, _, _) = generate(pyramid_request, notification)

        assert subject == 'Child 👧 has replied to your annotation'
Example #28
0
    def test_supports_non_ascii_display_names(
        self,
        notification,
        pyramid_request,
        parent_user,
        reply_user,
    ):
        parent_user.display_name = "Parent 👩"
        reply_user.display_name = "Child 👧"

        (_, subject, _, _) = generate(pyramid_request, notification)

        assert subject == "Child 👧 has replied to your annotation"
Example #29
0
    def test_calls_renderers_with_appropriate_context(self,
                                                      notification,
                                                      parent_user,
                                                      pyramid_request,
                                                      reply_user,
                                                      html_renderer,
                                                      text_renderer):
        generate(pyramid_request, notification)

        expected_context = {
            'document_title': 'My fascinating page',
            'document_url': 'http://example.org/',
            'parent': notification.parent,
            'parent_url': 'http://example.com/ann/foo123',
            'parent_user': parent_user,
            'reply': notification.reply,
            'reply_url': 'http://example.com/ann/bar456',
            'reply_user': reply_user,
            'reply_user_url': 'http://example.com/stream/user/ron',
            'unsubscribe_url': 'http://example.com/unsub/FAKETOKEN',
        }
        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #30
0
    def test_calls_renderers_with_appropriate_context(self,
                                                      notification,
                                                      parent_user,
                                                      pyramid_request,
                                                      reply_user,
                                                      html_renderer,
                                                      text_renderer,
                                                      links):
        generate(pyramid_request, notification)

        expected_context = {
            'document_title': 'My fascinating page',
            'document_url': 'http://example.org/',
            'parent': notification.parent,
            'parent_user_display_name': parent_user.display_name,
            'parent_user_url': 'http://example.com/stream/user/patricia',
            'reply': notification.reply,
            'reply_url': links.incontext_link.return_value,
            'reply_user_display_name': reply_user.display_name,
            'reply_user_url': 'http://example.com/stream/user/ron',
            'unsubscribe_url': 'http://example.com/unsub/FAKETOKEN',
        }
        html_renderer.assert_(**expected_context)
        text_renderer.assert_(**expected_context)
Example #31
0
    def test_returns_parent_email_as_recipients(self, req, notification):
        recipients, _, _, _ = generate(req, notification)

        assert recipients == ['*****@*****.**']
Example #32
0
    def test_gets_in_context_link(self, notification, links, pyramid_request):
        generate(pyramid_request, notification)

        links.incontext_link.assert_called_once_with(pyramid_request,
                                                     notification.reply)
Example #33
0
    def test_returns_subject_with_reply_display_name(self, notification, pyramid_request, reply_user):
        _, subject, _, _ = generate(pyramid_request, notification)

        assert subject == 'Ron Burgundy has replied to your annotation'
Example #34
0
    def test_returns_parent_email_as_recipients(self, notification, pyramid_request):
        recipients, _, _, _ = generate(pyramid_request, notification)

        assert recipients == ['*****@*****.**']
Example #35
0
    def test_returns_subject_with_reply_username(self, notification, pyramid_request):
        _, subject, _, _ = generate(pyramid_request, notification)

        assert subject == 'ron has replied to your annotation'
Example #36
0
    def test_returns_subject_with_reply_username(self, req, notification):
        _, subject, _, _ = generate(req, notification)

        assert subject == 'ron has replied to your annotation'
Example #37
0
    def test_returns_parent_email_as_recipients(self, req, notification):
        recipients, _, _, _ = generate(req, notification)

        assert recipients == ['*****@*****.**']
Example #38
0
    def test_gets_in_context_link(self, notification, links, pyramid_request):
        generate(pyramid_request, notification)

        links.incontext_link.assert_called_once_with(
            pyramid_request, notification.reply
        )
Example #39
0
    def test_returns_parent_email_as_recipients(self, notification, pyramid_request):
        recipients, _, _, _ = generate(pyramid_request, notification)

        assert recipients == ["*****@*****.**"]
Example #40
0
    def test_returns_subject_with_reply_display_name(
        self, notification, pyramid_request, reply_user
    ):
        _, subject, _, _ = generate(pyramid_request, notification)

        assert subject == "Ron Burgundy has replied to your annotation"