Mercurial > silorider
comparison tests/test_silos_mastodon.py @ 2:27543b2e73b9
Add Twitter silo.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 29 Jul 2018 10:40:05 -0700 |
parents | a1b7a459326a |
children | a921cc2306bc |
comparison
equal
deleted
inserted
replaced
1:169aa24a8442 | 2:27543b2e73b9 |
---|---|
1 import pytest | 1 import pytest |
2 from .mockutil import mock_urllib | |
2 | 3 |
3 | 4 |
4 def test_one_article(cli, feedutil, mastmock): | 5 def test_one_article(cli, feedutil, mastmock): |
5 feed = cli.createTempFeed(feedutil.makeFeed( | 6 feed = cli.createTempFeed(feedutil.makeFeed( |
6 """<h1 class="p-name">A new article</h1> | 7 """<h1 class="p-name">A new article</h1> |
47 | 48 |
48 cli.appendSiloConfig('test', 'mastodon', url='/blah') | 49 cli.appendSiloConfig('test', 'mastodon', url='/blah') |
49 mastmock.installTokens(cli, 'test') | 50 mastmock.installTokens(cli, 'test') |
50 | 51 |
51 with monkeypatch.context() as m: | 52 with monkeypatch.context() as m: |
52 import urllib.request | 53 import silorider.silos.mastodon |
53 m.setattr(urllib.request, 'urlretrieve', _patched_urlretrieve) | 54 mock_urllib(m) |
54 m.setattr(urllib.request, 'urlcleanup', _patched_urlcleanup) | 55 m.setattr(silorider.silos.mastodon.MastodonSilo, '_media_callback', |
56 _patched_media_callback) | |
55 ctx, _ = cli.run('process', feed) | 57 ctx, _ = cli.run('process', feed) |
58 | |
56 assert ctx.cache.wasPosted('test', '/01234.html') | 59 assert ctx.cache.wasPosted('test', '/01234.html') |
57 media = ctx.silos[0].client.media[0] | 60 media = ctx.silos[0].client.media[0] |
58 assert media == ('/retrived/fullimg.jpg', 'image/jpeg', 1) | 61 assert media == ('/retrieved/fullimg.jpg', 'image/jpeg', 1) |
59 toot = ctx.silos[0].client.toots[0] | 62 toot = ctx.silos[0].client.toots[0] |
60 assert toot == ("This is a quick photo update.", [1], 'public') | 63 assert toot == ("This is a quick photo update.", [1], 'public') |
61 | 64 |
62 | 65 |
63 def test_one_micropost_with_two_photos(cli, feedutil, mastmock, monkeypatch): | 66 def test_one_micropost_with_two_photos(cli, feedutil, mastmock, monkeypatch): |
72 | 75 |
73 cli.appendSiloConfig('test', 'mastodon', url='/blah') | 76 cli.appendSiloConfig('test', 'mastodon', url='/blah') |
74 mastmock.installTokens(cli, 'test') | 77 mastmock.installTokens(cli, 'test') |
75 | 78 |
76 with monkeypatch.context() as m: | 79 with monkeypatch.context() as m: |
77 import urllib.request | 80 import silorider.silos.mastodon |
78 m.setattr(urllib.request, 'urlretrieve', _patched_urlretrieve) | 81 mock_urllib(m) |
79 m.setattr(urllib.request, 'urlcleanup', _patched_urlcleanup) | 82 m.setattr(silorider.silos.mastodon.MastodonSilo, '_media_callback', |
83 _patched_media_callback) | |
80 ctx, _ = cli.run('process', feed) | 84 ctx, _ = cli.run('process', feed) |
85 | |
81 assert ctx.cache.wasPosted('test', '/01234.html') | 86 assert ctx.cache.wasPosted('test', '/01234.html') |
82 media = ctx.silos[0].client.media[0] | 87 media = ctx.silos[0].client.media[0] |
83 assert media == ('/retrived/fullimg1.jpg', 'image/jpeg', 1) | 88 assert media == ('/retrieved/fullimg1.jpg', 'image/jpeg', 1) |
84 media = ctx.silos[0].client.media[1] | 89 media = ctx.silos[0].client.media[1] |
85 assert media == ('/retrived/fullimg2.jpg', 'image/jpeg', 2) | 90 assert media == ('/retrieved/fullimg2.jpg', 'image/jpeg', 2) |
86 toot = ctx.silos[0].client.toots[0] | 91 toot = ctx.silos[0].client.toots[0] |
87 assert toot == ("This is a photo update with 2 photos.", [1, 2], 'public') | 92 assert toot == ("This is a photo update with 2 photos.", [1, 2], 'public') |
88 | 93 |
89 | 94 |
90 def _patched_urlretrieve(url): | 95 def _patched_media_callback(self, tmpfile, mt): |
91 return ('/retrived/' + url.lstrip('/'), None) | 96 return self.client.media_post(tmpfile, mt) |
92 | |
93 | |
94 def _patched_urlcleanup(): | |
95 pass | |
96 | 97 |
97 | 98 |
98 @pytest.fixture(scope='session') | 99 @pytest.fixture(scope='session') |
99 def mastmock(): | 100 def mastmock(): |
100 from silorider.silos.mastodon import MastodonSilo | 101 from silorider.silos.mastodon import MastodonSilo |