コード例 #1
0
ファイル: test_twitter.py プロジェクト: mediamatic/ikdisplay
    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
コード例 #2
0
ファイル: test_twitter.py プロジェクト: mediamatic/ikdisplay
    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
コード例 #3
0
ファイル: test_twitter.py プロジェクト: mediamatic/ikdisplay
    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