Esempio n. 1
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
Esempio n. 2
0
    def test_augmentStatusWithImageNoEntities(self):
        def cb(entry):
            self.assertIdentical(None, entry.image_url)

        status = Status()
        status.entities = Entities()

        d = self.embedder.augmentStatusWithImage(status)
        d.addCallback(cb)
        return d
Esempio n. 3
0
    def test_augmentStatusWithImageMediaEntities(self):
        def cb(entry):
            self.assertEqual(media.media_url, entry.image_url)

        media = Media()
        media.media_url = 'http://p.twimg.com/AQ9JtQsCEAA7dEN.jpg'
        status = Status()
        status.entities = Entities()
        status.entities.media = [media]

        d = self.embedder.augmentStatusWithImage(status)
        d.addCallback(cb)
        return d
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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