diff --git a/.gitignore b/.gitignore index 9b5c98f..b62e3c5 100644 --- a/.gitignore +++ b/.gitignore @@ -200,6 +200,7 @@ var/ sdist/ develop-eggs/ .installed.cfg +.eggs/ # Installer logs pip-log.txt diff --git a/.travis.yml b/.travis.yml index 161c398..a4727a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: false language: python python: - '2.7' diff --git a/pyembed/mustache/test/fixtures/cassettes/embed_template.yml b/pyembed/mustache/test/fixtures/cassettes/embed_template.yml new file mode 100644 index 0000000..1eefe38 --- /dev/null +++ b/pyembed/mustache/test/fixtures/cassettes/embed_template.yml @@ -0,0 +1,1248 @@ +interactions: +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + User-Agent: [python-requests/2.7.0 CPython/2.7.9 Linux/3.19.0-25-generic] + method: GET + uri: http://www.youtube.com/watch?v=qrO4YZeyl0I + response: + body: {string: !!python/unicode ''} + headers: + cache-control: [no-cache] + content-length: ['0'] + content-type: [text/html; charset=utf-8] + date: ['Sat, 15 Aug 2015 15:23:41 GMT'] + expires: ['Tue, 27 Apr 1971 19:44:06 EST'] + location: ['https://www.youtube.com/watch?v=qrO4YZeyl0I'] + p3p: ['CP="This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=en + for more info."'] + server: [gwiseguy/2.0] + set-cookie: ['VISITOR_INFO1_LIVE=mmER-mfGMTw; path=/; domain=.youtube.com; expires=Fri, + 15-Apr-2016 03:16:41 GMT; httponly', YSC=wK_ko7Yrzkw; path=/; domain=.youtube.com; + httponly] + x-content-type-options: [nosniff] + x-frame-options: [SAMEORIGIN] + x-xss-protection: ['1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube'] + status: {code: 301, message: Moved Permanently} +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + Cookie: [YSC=wK_ko7Yrzkw; VISITOR_INFO1_LIVE=mmER-mfGMTw] + User-Agent: [python-requests/2.7.0 CPython/2.7.9 Linux/3.19.0-25-generic] + method: GET + uri: https://www.youtube.com/watch?v=qrO4YZeyl0I + response: + body: {string: " \n \n\n\n\n\n + \ \n\n \n\n\n \n \n\n\n \n\n\n\n + \ \n \n\n \n \n \n\n\n\nLady + Gaga - Bad Romance - YouTube \n\n \n\n + \ \n\n \n + \ \n\n + \ \n \n\n \n \n + \ \n \n\n + \ \n\n \n \n \n\n + \ \n + \ \n \n + \ \n\n + \ \n \n \n \n \n + \ \n \n + \ \n + \ \n + \ \n \n\n \n \n + \ \n\n \n\n \n + \ \n \n \n \n \n + \ \n \n \n \n + \ \n + \ \n + \ \n \n + \ \n + \ \n + \ \n \n\n \n \n
\n\n\n
\n + \ \n
\n
\n Cookies help + us deliver our services. By using our services, you agree to our use of cookies.\n + \ Learn more\n\n
\n
+ \ \n
\n\n
\n
GB\n + \
\n \n + \
\n + \ \n + \
\n
\n
\n
Upload
\n
\n\n
\n + \
\n
\n

\n \n\n \nLoading...\n \n

\n\n
\n + \
\n
\n\n
\n \n
\n
\n Choose your + language.\n\n
\n
\n
\n + \ Learn + more
\n
\n
\nYou're + viewing YouTube in English (UK).\nYou can change this preference below.\n + \
\n
\n + \ You're viewing YouTube in English (United Kingdom).\n + \ You can change + this preference below.\n
\n
\n
\n \n
\n
\n + \ \n
\n
\n\n
\n
\n + \ \n
\n
\n
\n
\n \n
\n\n\n\n
+ \
\n
\n \"\"\n
\n

\n + \ This video is unavailable.\n\n

\n
\n
\n
\n\n\n
\n\n
\n + \ \n + \ \n\n\n

Watch Queue

TV + Queue

Watch + QueueTV Queue
\n \n \n \n + \ \n
\n \n\n \n\n + \ \n\n + \ \n + \
\n

    \n \n\n + \ \nLoading...\n \n

    \n
+ \
\n
\nWatch Queue\n + \
\n\n
\nTV Queue\n
\n\n + \
\n__count__/__total__\n
\n\n + \
\n \n
\n
\n
\n
\n \n\n + \
\n\n
\n\n
\n
\n
\n
\n\n + \
\n
\n + \
\n
\n
\n
\n \n + \ \n \n \n\n \n \n\n \n \n\n + \ \n + \ \n + \ \n \n + \ \n + \ \n\n \n + \ \n + \ \n + \ \n \n \n\n \n + \ \n \n \n\n + \ \n \n + \ \n \n \n\n \n
\n
\n + \
\n

\n \n\n \n Lady Gaga - Bad Romance\n \n\n + \

\n
\n
\n\n
\n \n \n \n + \ \"LadyGagaVEVO\"\n + \ \n \n \n + \ \n\n \n
\n LadyGagaVEVO\n \n \n
\n6,051,936 + \ \n
\n + \ \n
\n
\n + \ \n
\n
\n
\n
\n + \

\n \n\n \nLoading...\n + \ \n

\n\n
\n\n
\n
\n + \
\n + \
\n

\n \n\n \nLoading...\n + \ \n

\n\n
\n
\n + \
\n
\n\n
\n
\n + \
\n
\n + \
\n

\n \n\n + \ \n Working...\n \n + \

\n\n
\n
\n\n
\n
\n
\n
\n
\n + \
\n\n\n
\n\n
\n
+ \ \n \n + \
\n

Want to watch this again later?

\n
\n Sign in to add this video to a + playlist.\n
\n Sign in\n
\n\n
\n + \ \n
\n
  • \n \n \n\n
    \n + \

    Need to report the video?

    \n + \
    \n Sign in to report inappropriate + content.\n
    \n Sign in\n
    \n\n
    \n + \
  • \n
  • \n \n\n
  • \n
633,206,593
\n + \
\n
\n
\n
\n
\n\n\n\n\n\n \n + \ \n \n + \
\n

Like this video?

\n
\n + \ Sign in to make your opinion count.\n
\n Sign in\n
\n\n
\n + \ \n \n + \ \n \n \n + \
\n

Don't like this video?

\n
\n + \ Sign in to make your opinion count.\n
\n Sign in\n
\n\n
\n + \ \n \n + \ \n
\n
\n
\n\n\n\n
\n + \
\n + \
\n
\n + \

\n \n\n \nLoading...\n + \ \n

\n\n
\n
\n
\n\n + \
\n\n
\n
\n

\n \n\n + \ \nLoading...\n \n

\n\n + \
\n
\n\n
\n
\n + \

\n \n\n \nLoading...\n + \ \n

\n\n
\n
\n\n \n
\n
\n + \ Rating is available when the video has been rented.\n + \
\n\n
\n\n
\n
\n This feature is not + available right now. Please try again later.\n
\n
\n\n \n
\n\n
Uploaded on 23 Nov 2009

Music video by Lady Gaga performing + Bad Romance. (C) 2009 Interscope Records
#VEVOCertified on January 31, + 2010. http://www.vevo.com/certified + http://www.youtube.com/vevocertified

+ \
\n
    \n + \
  • \n

    \n Music\n + \

    \n \n
  • \n\n
  • \n

    \n Category\n

    \n + \ \n
  • \n\n + \
  • \n

    \n + \ Licence\n

    \n
      \n + \
    • Standard YouTube Licence
    • \n
    \n
  • \n\n
\n + \
\n
\n \n
\n\n
\n\n
\n \n \n
\n + \
\n
\n

\n \n\n \nLoading...\n \n

\n\n
\n + \
\n\n\n
\n\n\n
\n
\n + \
\n
\n\n\n + \
\n
\n \n
\n\n
\n + \
\n
\nAdvertisement\n
\n
\n
\n
\n\n\n
\n + \
\n
\n + \
\n
\n + \ \n \n \nWhen autoplay is enabled, a suggested video + will automatically play next. \n \n\n + \ \n \n\n
\n + \

\n Up next\n

\n + \ \n\n
\n
\n\n + \ \n
\n
\n + \
\n \n + \
\n
\n\n
\n
\n\n
\n
\n + \
\n\n
\n
\n
\n\n
\n\n + \
\n\n
+ \
    \n + \
  • \n \n\n\n + \
  • \n
  • \n \n\n\n + \
  • \n
  • \n \n\n\n + \
  • \n
\nHistory \n
\n

\n \n\n + \ \nLoading...\n \n

\n\n + \
\n\n
\n

\n \n\n \nLoading...\n + \ \n

\n\n
\n\n
\n

\n \n\n + \ \nLoading...\n \n

\n\n + \
\n\n
\n\n\n + \
\n
\n + \ \n
\n
\n
\n
\n + \

\n \n\n \nLoading...\n + \ \n

\n\n
\n\n
\n
\n + \
\n
\n\n
\n + \
\n
\n + \
\n
\n + \

\n \n\n \n Working...\n + \ \n

\n\n
\n
\n\n
\n
\n + \
\n
\n + \
\n
\n\n\n
+ \
\n Sign in to add this to Watch Later\n\n
\n + \
\n + \
\n

\nAdd to\n

\n + \
\n
\n

\n + \ \n\n + \ \n Loading playlists...\n \n + \

\n\n
\n\n
\n
\n \n \n \n\n\n\n"} + headers: + accept-ranges: [none] + alt-svc: ['quic=":443"; p="1"; ma=604800'] + alternate-protocol: ['443:quic,p=1'] + cache-control: [no-cache] + content-type: [text/html; charset=utf-8] + date: ['Sat, 15 Aug 2015 15:23:41 GMT'] + expires: ['Tue, 27 Apr 1971 19:44:06 EST'] + p3p: ['CP="This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=en-GB + for more info."'] + server: [gwiseguy/2.0] + set-cookie: ['PREF=f1=50000000; path=/; domain=.youtube.com; expires=Fri, 15-Apr-2016 + 03:16:41 GMT', 'GEUP=d2667d3b1cb6912f5dd443b65e1287c6aQEAAAA=; path=/; domain=.youtube.com; + expires=Mon, 14-Aug-2017 15:23:41 GMT'] + vary: [Accept-Encoding] + x-content-type-options: [nosniff] + x-frame-options: [SAMEORIGIN] + x-xss-protection: ['1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube'] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + User-Agent: [python-requests/2.7.0 CPython/2.7.9 Linux/3.19.0-25-generic] + method: GET + uri: http://www.youtube.com/oembed?format=json&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqrO4YZeyl0I + response: + body: {string: !!python/unicode '{"title": "Lady Gaga - Bad Romance", "author_name": + "LadyGagaVEVO", "html": "\u003ciframe width=\"480\" height=\"270\" src=\"https:\/\/www.youtube.com\/embed\/qrO4YZeyl0I?feature=oembed\" + frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e", "provider_name": + "YouTube", "height": 270, "type": "video", "thumbnail_height": 360, "provider_url": + "https:\/\/www.youtube.com\/", "thumbnail_url": "https:\/\/i.ytimg.com\/vi\/qrO4YZeyl0I\/hqdefault.jpg", + "thumbnail_width": 480, "width": 480, "author_url": "https:\/\/www.youtube.com\/user\/LadyGagaVEVO", + "version": "1.0"}'} + headers: + accept-ranges: [none] + cache-control: [no-cache] + content-type: [application/json] + date: ['Sat, 15 Aug 2015 15:23:41 GMT'] + expires: ['Tue, 27 Apr 1971 19:44:06 EST'] + p3p: ['CP="This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=en + for more info."'] + server: [gwiseguy/2.0] + vary: [Accept-Encoding] + x-content-type-options: [nosniff] + x-xss-protection: ['1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube'] + status: {code: 200, message: OK} +version: 1 diff --git a/pyembed/mustache/test/integration_test.py b/pyembed/mustache/test/integration_test.py index 3250ac1..d7d5e28 100644 --- a/pyembed/mustache/test/integration_test.py +++ b/pyembed/mustache/test/integration_test.py @@ -21,15 +21,16 @@ # THE SOFTWARE. from pyembed.core import PyEmbed -from hamcrest import assert_that, equal_to - from pyembed.mustache import MustacheRenderer +import vcr + +@vcr.use_cassette('pyembed/mustache/test/fixtures/cassettes/embed_template.yml') def test_should_embed_with_mustache_template(): renderer = MustacheRenderer('pyembed/mustache/test/fixtures') embedding = PyEmbed(renderer=renderer).embed( 'http://www.youtube.com/watch?v=qrO4YZeyl0I') - assert_that(embedding, equal_to( - 'Lady Gaga - Bad Romance by LadyGagaVEVO from ' + - 'http://www.youtube.com/watch?v=qrO4YZeyl0I')) + assert embedding == \ + 'Lady Gaga - Bad Romance by LadyGagaVEVO from ' + \ + 'http://www.youtube.com/watch?v=qrO4YZeyl0I' diff --git a/pyembed/mustache/test/mustache_test.py b/pyembed/mustache/test/mustache_test.py index 5655f90..7d412ff 100644 --- a/pyembed/mustache/test/mustache_test.py +++ b/pyembed/mustache/test/mustache_test.py @@ -22,8 +22,6 @@ from pyembed.core import response -from hamcrest import assert_that, equal_to - from pyembed.mustache import MustacheRenderer @@ -36,10 +34,8 @@ def test_default_embed_photo(): oembed_response = response.OEmbedPhotoResponse( create_value_function(values)) - assert_that( - MustacheRenderer('.').render('http://example.com', oembed_response), - equal_to('')) + assert MustacheRenderer('.').render('http://example.com', oembed_response) == \ + '' def test_default_embed_video(): @@ -50,9 +46,7 @@ def test_default_embed_video(): oembed_response = response.OEmbedVideoResponse( create_value_function(values)) - assert_that( - MustacheRenderer('.').render('http://example.com', oembed_response), - equal_to(embedding)) + assert MustacheRenderer('.').render('http://example.com', oembed_response) == embedding def test_default_embed_rich(): @@ -63,9 +57,7 @@ def test_default_embed_rich(): oembed_response = response.OEmbedRichResponse( create_value_function(values)) - assert_that( - MustacheRenderer('.').render('http://example.com', oembed_response), - equal_to(embedding)) + assert MustacheRenderer('.').render('http://example.com', oembed_response) == embedding def test_default_embed_link(): @@ -74,9 +66,8 @@ def test_default_embed_link(): oembed_response = response.OEmbedLinkResponse( create_value_function(values)) - assert_that( - MustacheRenderer('.').render('http://example.com', oembed_response), - equal_to('Bees!')) + assert MustacheRenderer('.').render('http://example.com', oembed_response) == \ + 'Bees!' def test_should_embed_with_template(): @@ -91,8 +82,7 @@ def test_should_embed_with_template(): renderer = MustacheRenderer('pyembed/mustache/test/fixtures') embedding = renderer.render('http://example.com', oembed_response) - assert_that(embedding, equal_to( - 'Bees by Ian Bees from http://example.com')) + assert embedding == 'Bees by Ian Bees from http://example.com' def test_should_use_default_embedding_if_no_template(): @@ -105,9 +95,7 @@ def test_should_use_default_embedding_if_no_template(): create_value_function(values)) renderer = MustacheRenderer('pyembed/mustache/test/fixtures') - assert_that( - renderer.render('http://example.com', oembed_response), - equal_to(embedding)) + assert renderer.render('http://example.com', oembed_response) == embedding def create_value_function(values): diff --git a/setup.py b/setup.py index 98e3464..49a526f 100644 --- a/setup.py +++ b/setup.py @@ -65,9 +65,9 @@ def run_tests(self): 'pystache' ], tests_require=[ - 'PyHamcrest', 'mock', - 'pytest' + 'pytest', + 'vcrpy' ], cmdclass={'test': PyTest}, diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..71d5a5c --- /dev/null +++ b/tox.ini @@ -0,0 +1,7 @@ +[tox] +envlist = py27, py34 + +[testenv] +commands = python setup.py test +deps = + setuptools>=17.1