Exemple #1
0
    def test_formatDisplayURL(self):
        self.status.text = (u'#Photos on Twitter: taking flight '
                            'http://t.co/qbJx26r http://t.co/123456')

        self.status.entities = Entities()
        media = Media()
        media.url = "http://t.co/qbJx26r"
        media.display_url = "pic.twitter.com/qbJx26r"
        media.indices = Indices()
        media.indices.start = 34
        media.indices.end = 53
        self.status.entities.media = [media]
        url = URL()
        url.url = "http://t.co/123456"
        url.display_url = u"pic.twitter.com/12345\u2026"
        url.indices = Indices()
        url.indices.start = 54
        url.indices.end = 73
        self.status.entities.urls = [url]

        notification = self.source.format(self.status)
        self.assertEquals(u'#Photos on Twitter: taking flight '
                            u'pic.twitter.com/qbJx26r '
                            u'pic.twitter.com/12345\u2026',
                          notification['subtitle'])
        self.assertEquals(u'#Photos on Twitter: taking flight '
                            u"<a href='http://t.co/qbJx26r'>"
                              u"pic.twitter.com/qbJx26r</a> "
                            u"<a href='http://t.co/123456'>"
                              u"pic.twitter.com/12345\u2026</a>",
                          notification['html'])
Exemple #2
0
    def test_augmentStatusWithImageURLEntitiesException(self):
        """
        If an exception is raised while trying to resolve entities, log it.

        This overrides L{twitter.extractImage} so that it always returns
        the given URL, as if it was successfully extracted.
        """
        def cb(entry):
            self.assertIdentical(None, entry.image_url)
            self.assertEqual(1, len(self.flushLoggedErrors()))

        url = URL()
        url.url = 'http://t.co/qbJx26r'
        url.expanded_url = 'http://twitter.com/twitter/status/' \
                               '76360760606986241/photo/1'
        status = Status()
        status.entities = Entities()
        status.entities.urls = [url]

        self.patch(self.embedder, 'extractImage',
                   lambda url: defer.fail(Exception()))

        d = self.embedder.augmentStatusWithImage(status)
        d.addCallback(cb)
        return d
Exemple #3
0
    def test_formatDisplayURLRetweeted(self):
        """
        Retweets with links are rendered properly.
        """
        self.status.user.id = 1
        self.status.user.screen_name = u'test'
        status = self.status.retweeted_status = Status()
        status.text = (u'Today, many XMPP servers switch to mandatory '
                         u'encryption. Happy Open Discussion Day! '
                         u'http://t.co/MNH87vwe4T http://t.co/DbKFDlV9M8')

        user = User()
        user.id = 2426271
        user.screen_name = u'ralphm'
        status.user = user

        status.entities = Entities()

        urls = []

        url = URL()
        url.url = "http://t.co/MNH87vwe4T"
        url.display_url = "opendiscussionday.org"
        url.indices = Indices()
        url.indices.start = 84
        url.indices.end = 106
        urls.append(url)

        url = URL()
        url.url = "http://t.co/DbKFDlV9M8"
        url.display_url = u"stpeter.im/journal/1496.h\u2026"
        url.indices = Indices()
        url.indices.start = 107
        url.indices.end = 129
        urls.append(url)

        status.entities.urls = urls

        notification = self.source.format(self.status)
        self.assertEquals(u'RT @ralphm: '
                            u'Today, many XMPP servers switch to mandatory '
                            u'encryption. Happy Open Discussion Day! '
                            u'opendiscussionday.org '
                            u'stpeter.im/journal/1496.h\u2026',
                          notification['subtitle'])
        self.assertEquals(u'RT @ralphm: '
                            u'Today, many XMPP servers switch to mandatory '
                            u'encryption. Happy Open Discussion Day! '
                            u"<a href='http://t.co/MNH87vwe4T'>"
                              u'opendiscussionday.org</a> '
                            u"<a href='http://t.co/DbKFDlV9M8'>"
                              u'stpeter.im/journal/1496.h\u2026</a>',
                          notification['html'])
Exemple #4
0
    def test_augmentStatusWithImageURLEntitiesURLNoSchema(self):
        """
        If the extracted URL doesn't have a schema, add it.
        """
        def extractImage(url):
            return defer.succeed(url)

        def cb(entry):
            self.assertEqual('http://' + url.url, entry.image_url)

        url = URL()
        url.url = 't.co/qbJx26r'
        status = Status()
        status.entities = Entities()
        status.entities.urls = [url]

        self.patch(self.embedder, 'extractImage', defer.succeed)

        d = self.embedder.augmentStatusWithImage(status)
        d.addCallback(cb)
        return d
Exemple #5
0
    def test_augmentStatusWithImageURLEntitiesURL(self):
        """
        If there is no expanded URL, try the extracted URL.
        """
        def extractImage(url):
            return defer.succeed(url)

        def cb(entry):
            self.assertEqual(url.url, entry.image_url)

        url = URL()
        url.url = 'http://t.co/qbJx26r'
        status = Status()
        status.entities = Entities()
        status.entities.urls = [url]

        self.patch(self.embedder, 'extractImage', defer.succeed)

        d = self.embedder.augmentStatusWithImage(status)
        d.addCallback(cb)
        return d
Exemple #6
0
    def test_augmentStatusWithImageURLEntities(self):
        """
        If there is no media entity, try expanded extracted URLs.

        This overrides L{twitter.extractImage} so that it always returns
        the given URL, as if it was successfully extracted.
        """
        def cb(entry):
            self.assertEqual(url.expanded_url, entry.image_url)

        url = URL()
        url.url = 'http://t.co/qbJx26r'
        url.expanded_url = 'http://twitter.com/twitter/status/' \
                               '76360760606986241/photo/1'
        status = Status()
        status.entities = Entities()
        status.entities.urls = [url]

        self.patch(self.embedder, 'extractImage', defer.succeed)

        d = self.embedder.augmentStatusWithImage(status)
        d.addCallback(cb)
        return d
Exemple #7
0
    def test_augmentStatusWithImageURLEntitiesNoImage(self):
        """
        If the embedded URLs don't resolve to an image, set it to None.

        This overrides L{twitter.extractImage} so that it always returns
        the given URL, as if it was successfully extracted.
        """
        def cb(entry):
            self.assertIdentical(None, entry.image_url)

        url = URL()
        url.url = 'http://t.co/qbJx26r'
        url.expanded_url = 'http://twitter.com/twitter/status/' \
                               '76360760606986241/photo/1'
        status = Status()
        status.entities = Entities()
        status.entities.urls = [url]

        self.patch(self.embedder, 'extractImage',
                   lambda url: defer.succeed(None))

        d = self.embedder.augmentStatusWithImage(status)
        d.addCallback(cb)
        return d