Пример #1
0
    def test_embedly_return_value(self):
        with patch('embedly.Embedly.oembed') as oembed:
            oembed.return_value = {'type': 'something else',
                                   'html': '<foo>bar</foo>'}
            result = EmbedlyFinder(key='foo').find_embed('http://www.example.com')
            self.assertEqual(result, {
                'title': '',
                'author_name': '',
                'provider_name': '',
                'type': 'something else',
                'thumbnail_url': None,
                'width': None,
                'height': None,
                'html': '<foo>bar</foo>'})

            oembed.return_value = {'type': 'something else',
                                   'author_name': 'Alice',
                                   'provider_name': 'Bob',
                                   'title': 'foo',
                                   'thumbnail_url': 'http://www.example.com',
                                   'width': 100,
                                   'height': 100,
                                   'html': '<foo>bar</foo>'}
            result = EmbedlyFinder(key='foo').find_embed('http://www.example.com')
            self.assertEqual(result, {'type': 'something else',
                                      'author_name': 'Alice',
                                      'provider_name': 'Bob',
                                      'title': 'foo',
                                      'thumbnail_url': 'http://www.example.com',
                                      'width': 100,
                                      'height': 100,
                                      'html': '<foo>bar</foo>'})
Пример #2
0
    def test_embedly_oembed_called_with_correct_arguments(self):
        with patch('embedly.Embedly.oembed') as oembed:
            oembed.return_value = {'type': 'photo',
                                   'url': 'http://www.example.com'}

            EmbedlyFinder(key='foo').find_embed('http://www.example.com')
            oembed.assert_called_with('http://www.example.com', better=False)

            EmbedlyFinder(key='foo').find_embed('http://www.example.com', max_width=100)
            oembed.assert_called_with('http://www.example.com', maxwidth=100, better=False)
Пример #3
0
    def test_embedly_html_conversion(self):
        with patch('embedly.Embedly.oembed') as oembed:
            oembed.return_value = {'type': 'photo',
                                   'url': 'http://www.example.com'}
            result = EmbedlyFinder(key='foo').find_embed('http://www.example.com')
            self.assertEqual(result['html'], '<img src="http://www.example.com" />')

            oembed.return_value = {'type': 'something else',
                                   'html': '<foo>bar</foo>'}
            result = EmbedlyFinder(key='foo').find_embed('http://www.example.com')
            self.assertEqual(result['html'], '<foo>bar</foo>')
Пример #4
0
    def test_embedly_oembed_called_with_correct_arguments(self):
        with patch("embedly.Embedly.oembed") as oembed:
            oembed.return_value = {
                "type": "photo",
                "url": "http://www.example.com"
            }

            EmbedlyFinder(key="foo").find_embed("http://www.example.com")
            oembed.assert_called_with("http://www.example.com", better=False)

            EmbedlyFinder(key="foo").find_embed("http://www.example.com",
                                                max_width=100)
            oembed.assert_called_with("http://www.example.com",
                                      maxwidth=100,
                                      better=False)
Пример #5
0
    def test_embedly_return_value(self):
        with patch("embedly.Embedly.oembed") as oembed:
            oembed.return_value = {
                "type": "something else",
                "html": "<foo>bar</foo>"
            }
            result = EmbedlyFinder(
                key="foo").find_embed("http://www.example.com")
            self.assertEqual(
                result,
                {
                    "title": "",
                    "author_name": "",
                    "provider_name": "",
                    "type": "something else",
                    "thumbnail_url": None,
                    "width": None,
                    "height": None,
                    "html": "<foo>bar</foo>",
                },
            )

            oembed.return_value = {
                "type": "something else",
                "author_name": "Alice",
                "provider_name": "Bob",
                "title": "foo",
                "thumbnail_url": "http://www.example.com",
                "width": 100,
                "height": 100,
                "html": "<foo>bar</foo>",
            }
            result = EmbedlyFinder(
                key="foo").find_embed("http://www.example.com")
            self.assertEqual(
                result,
                {
                    "type": "something else",
                    "author_name": "Alice",
                    "provider_name": "Bob",
                    "title": "foo",
                    "thumbnail_url": "http://www.example.com",
                    "width": 100,
                    "height": 100,
                    "html": "<foo>bar</foo>",
                },
            )
Пример #6
0
 def test_embedly_other_error(self):
     with patch('embedly.Embedly.oembed') as oembed:
         oembed.return_value = {'type': 'photo',
                                'url': 'http://www.example.com',
                                'error': True,
                                'error_code': 999}
         self.assertRaises(EmbedlyException, EmbedlyFinder(key='foo').find_embed,
                           'http://www.example.com')
Пример #7
0
    def test_embedly_html_conversion(self):
        with patch("embedly.Embedly.oembed") as oembed:
            oembed.return_value = {
                "type": "photo",
                "url": "http://www.example.com"
            }
            result = EmbedlyFinder(
                key="foo").find_embed("http://www.example.com")
            self.assertEqual(result["html"],
                             '<img src="http://www.example.com" alt="">')

            oembed.return_value = {
                "type": "something else",
                "html": "<foo>bar</foo>"
            }
            result = EmbedlyFinder(
                key="foo").find_embed("http://www.example.com")
            self.assertEqual(result["html"], "<foo>bar</foo>")
Пример #8
0
 def test_embedly_other_error(self):
     with patch("embedly.Embedly.oembed") as oembed:
         oembed.return_value = {
             "type": "photo",
             "url": "http://www.example.com",
             "error": True,
             "error_code": 999,
         }
         self.assertRaises(
             EmbedlyException,
             EmbedlyFinder(key="foo").find_embed,
             "http://www.example.com",
         )