Mercurial > silorider
annotate tests/test_silos_twitter.py @ 78:932aa9922d98
Add hashtag facets to Bluesky silo
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 28 Aug 2024 09:38:33 -0700 |
parents | dafbbf25bfc8 |
children |
rev | line source |
---|---|
69
dafbbf25bfc8
Upgrade bluesky silo to atproto 0.0.35 and unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1 import os.path |
2 | 2 import pytest |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
3 from .mockutil import mock_urllib |
2 | 4 |
5 | |
6 def test_one_article(cli, feedutil, tweetmock): | |
7 feed = cli.createTempFeed(feedutil.makeFeed( | |
8 """<h1 class="p-name">A new article</h1> | |
9 <div class="e-content"> | |
10 <p>This is the text of the article.</p> | |
11 <p>It has 2 paragraphs.</p> | |
12 </div> | |
13 <a class="u-url" href="https://example.org/a-new-article">permalink</a>""" | |
14 )) | |
15 | |
16 cli.appendSiloConfig('test', 'twitter', url='/blah') | |
18
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
17 cli.setFeedConfig('feed', feed) |
2 | 18 tweetmock.installTokens(cli, 'test') |
19 | |
18
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
20 ctx, _ = cli.run('process') |
2 | 21 assert ctx.cache.wasPosted('test', 'https://example.org/a-new-article') |
22 toot = ctx.silos[0].client.tweets[0] | |
4
c199bd681e4e
Twitter API accepts direct URLs for media.
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
23 assert toot == ('A new article https://example.org/a-new-article', []) |
2 | 24 |
25 | |
26 def test_one_micropost(cli, feedutil, tweetmock): | |
27 feed = cli.createTempFeed(feedutil.makeFeed( | |
28 """<p class="p-name">This is a quick update.</p> | |
29 <a class="u-url" href="/01234.html">permalink</a>""" | |
30 )) | |
31 | |
32 cli.appendSiloConfig('test', 'twitter', url='/blah') | |
18
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
33 cli.setFeedConfig('feed', feed) |
2 | 34 tweetmock.installTokens(cli, 'test') |
35 | |
18
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
36 ctx, _ = cli.run('process') |
2 | 37 assert ctx.cache.wasPosted('test', '/01234.html') |
38 toot = ctx.silos[0].client.tweets[0] | |
4
c199bd681e4e
Twitter API accepts direct URLs for media.
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
39 assert toot == ("This is a quick update.", []) |
2 | 40 |
41 | |
25
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
42 def test_one_micropost_with_mention(cli, feedutil, tweetmock): |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
43 feed = cli.createTempFeed(feedutil.makeFeed( |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
44 """<p class="p-name">Hey <a href="https://twitter.com/jack">Jacky</a> |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
45 you should fix your stuff!</p> |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
46 <a class="u-url" href="/01234.html">permalink</a>""" |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
47 )) |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
48 |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
49 cli.appendSiloConfig('test', 'twitter', url='/blah') |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
50 cli.setFeedConfig('feed', feed) |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
51 tweetmock.installTokens(cli, 'test') |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
52 |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
53 ctx, _ = cli.run('process') |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
54 assert ctx.cache.wasPosted('test', '/01234.html') |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
55 toot = ctx.silos[0].client.tweets[0] |
33
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
56 assert toot == ("Hey @jack\nyou should fix your stuff!", []) |
25
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
57 |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
58 |
2 | 59 def test_one_micropost_with_one_photo(cli, feedutil, tweetmock, monkeypatch): |
60 feed = cli.createTempFeed(feedutil.makeFeed( | |
61 """<p class="p-name">This is a quick photo update.</p> | |
62 <div> | |
63 <a class="u-photo" href="/fullimg.jpg"><img src="/thumbimg.jpg"/></a> | |
64 </div> | |
65 <a class="u-url" href="/01234.html">permalink</a>""" | |
66 )) | |
67 | |
68 cli.appendSiloConfig('test', 'twitter', url='/blah') | |
18
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
69 cli.setFeedConfig('feed', feed) |
2 | 70 tweetmock.installTokens(cli, 'test') |
71 | |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
72 with monkeypatch.context() as m: |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
73 import silorider.silos.twitter |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
74 mock_urllib(m) |
69
dafbbf25bfc8
Upgrade bluesky silo to atproto 0.0.35 and unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
75 m.setattr(os.path, 'getsize', lambda path: 42) |
58
d65f6dced79f
Fix media callback patches in unit tests
Ludovic Chabant <ludovic@chabant.com>
parents:
39
diff
changeset
|
76 m.setattr(silorider.silos.twitter.TwitterSilo, 'mediaCallback', |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
77 _patched_media_callback) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
78 ctx, _ = cli.run('process') |
2 | 79 |
80 assert ctx.cache.wasPosted('test', '/01234.html') | |
81 toot = ctx.silos[0].client.tweets[0] | |
4
c199bd681e4e
Twitter API accepts direct URLs for media.
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
82 assert toot == ("This is a quick photo update.", ['/fullimg.jpg']) |
2 | 83 |
84 | |
85 def test_one_micropost_with_two_photos(cli, feedutil, tweetmock, monkeypatch): | |
86 feed = cli.createTempFeed(feedutil.makeFeed( | |
87 """<p class="p-name">This is a photo update with 2 photos.</p> | |
88 <div> | |
89 <a class="u-photo" href="/fullimg1.jpg"><img src="/thumbimg1.jpg"/></a> | |
90 <a class="u-photo" href="/fullimg2.jpg"><img src="/thumbimg2.jpg"/></a> | |
91 </div> | |
92 <a class="u-url" href="/01234.html">permalink</a>""" | |
93 )) | |
94 | |
95 cli.appendSiloConfig('test', 'twitter', url='/blah') | |
18
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
96 cli.setFeedConfig('feed', feed) |
2 | 97 tweetmock.installTokens(cli, 'test') |
98 | |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
99 with monkeypatch.context() as m: |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
100 import silorider.silos.twitter |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
101 mock_urllib(m) |
69
dafbbf25bfc8
Upgrade bluesky silo to atproto 0.0.35 and unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
102 m.setattr(os.path, 'getsize', lambda path: 42) |
58
d65f6dced79f
Fix media callback patches in unit tests
Ludovic Chabant <ludovic@chabant.com>
parents:
39
diff
changeset
|
103 m.setattr(silorider.silos.twitter.TwitterSilo, 'mediaCallback', |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
104 _patched_media_callback) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
105 ctx, _ = cli.run('process') |
2 | 106 |
107 assert ctx.cache.wasPosted('test', '/01234.html') | |
108 toot = ctx.silos[0].client.tweets[0] | |
4
c199bd681e4e
Twitter API accepts direct URLs for media.
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
109 assert toot == ("This is a photo update with 2 photos.", |
c199bd681e4e
Twitter API accepts direct URLs for media.
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
110 ['/fullimg1.jpg', '/fullimg2.jpg']) |
2 | 111 |
112 | |
33
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
113 def test_micropost_with_long_text_and_link(cli, feedutil, tweetmock, monkeypatch): |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
114 feed = cli.createTempFeed(feedutil.makeFeed( |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
115 """<div class="p-name"> |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
116 <p>This a pretty long text that has a link in it :) We want to make sure it gets to the limit of what Twitter allows, so that we can test there won't be any off-by-one errors in measurements. Here is a <a href="https://docs.python.org/3/library/textwrap.html">link to Python's textwrap module</a>, which is appropriate!!!</p> |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
117 </div> |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
118 <a class="u-url" href="/01234.html">permalink</a>""" |
33
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
119 )) |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
120 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
121 cli.appendSiloConfig('test', 'twitter', url='/blah') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
122 cli.setFeedConfig('feed', feed) |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
123 tweetmock.installTokens(cli, 'test') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
124 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
125 ctx, _ = cli.run('process') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
126 assert ctx.cache.wasPosted('test', '/01234.html') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
127 toot = ctx.silos[0].client.tweets[0] |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
128 assert toot == ("This a pretty long text that has a link in it :) We want to make sure it gets to the limit of what Twitter allows, so that we can test there won't be any off-by-one errors in measurements. Here is a link to Python's textwrap module, which is appropriate!!! https://docs.python.org/3/library/textwrap.html", |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
129 []) |
33
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
130 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
131 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
132 def test_micropost_with_too_long_text_and_link_1(cli, feedutil, tweetmock, monkeypatch): |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
133 feed = cli.createTempFeed(feedutil.makeFeed( |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
134 """<div class="p-name"> |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
135 <p>This time we have a text that's slightly too long, with <a href="https://thisdoesntmatter.com">a link here</a>. We'll be one character too long, with a short word at the end to test the shortening algorithm. Otherwise, don't worry about it. Blah blah blah. Trying to get to the limit. Almost here yes</p> |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
136 </div> |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
137 <a class="u-url" href="/01234.html">permalink</a>""" |
33
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
138 )) |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
139 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
140 cli.appendSiloConfig('test', 'twitter', url='/blah') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
141 cli.setFeedConfig('feed', feed) |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
142 tweetmock.installTokens(cli, 'test') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
143 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
144 ctx, _ = cli.run('process') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
145 assert ctx.cache.wasPosted('test', '/01234.html') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
146 toot = ctx.silos[0].client.tweets[0] |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
147 assert toot == ("This time we have a text that's slightly too long, with a link here. We'll be one character too long, with a short word at the end to test the shortening algorithm. Otherwise, don't worry about it. Blah blah blah. Trying to get to the limit. Almost here... /01234.html", |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
148 []) |
33
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
149 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
150 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
151 def test_micropost_with_too_long_text_and_link_2(cli, feedutil, tweetmock, monkeypatch): |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
152 feed = cli.createTempFeed(feedutil.makeFeed( |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
153 """<div class="p-name"> |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
154 <p>This time we have a text that's slightly too long, with <a href="https://thisdoesntmatter.com">a link here</a>. We'll be one character too long, with a loooooong word at the end to test the shortening algorithm. Otherwise, don't worry about it. Blah blah blah. Our long word is: califragilisticastuff</p> |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
155 </div> |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
156 <a class="u-url" href="/01234.html">permalink</a>""" |
33
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
157 )) |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
158 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
159 cli.appendSiloConfig('test', 'twitter', url='/blah') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
160 cli.setFeedConfig('feed', feed) |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
161 tweetmock.installTokens(cli, 'test') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
162 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
163 ctx, _ = cli.run('process') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
164 assert ctx.cache.wasPosted('test', '/01234.html') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
165 toot = ctx.silos[0].client.tweets[0] |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
166 assert toot == ("This time we have a text that's slightly too long, with a link here. We'll be one character too long, with a loooooong word at the end to test the shortening algorithm. Otherwise, don't worry about it. Blah blah blah. Our long word is:... /01234.html", |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
167 []) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
168 |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
169 |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
170 def _patched_media_callback(self, tmpfile, mt, url, desc): |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
171 return self.client.simple_upload(url) |
33
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
172 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
173 |
2 | 174 @pytest.fixture(scope='session') |
175 def tweetmock(): | |
176 from silorider.silos.twitter import TwitterSilo | |
177 TwitterSilo._CLIENT_CLASS = TwitterMock | |
178 return TwitterMockUtil() | |
179 | |
180 | |
181 class TwitterMock: | |
182 def __init__(self, consumer_key, consumer_secret, | |
183 access_token_key, access_token_secret): | |
184 assert consumer_key == 'TEST_CLIENT_KEY' | |
185 assert consumer_secret == 'TEST_CLIENT_SECRET' | |
186 assert access_token_key == 'TEST_ACCESS_KEY' | |
187 assert access_token_secret == 'TEST_ACCESS_SECRET' | |
188 | |
189 self.tweets = [] | |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
190 self.media = [] |
2 | 191 |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
192 def create_tweet(self, text, media_ids=None): |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
193 media_names = [] |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
194 if media_ids: |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
195 for mid in media_ids: |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
196 assert(self.media[mid] is not None) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
197 media_names.append(self.media[mid]) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
198 self.media[mid] = None |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
199 assert all([m is None for m in self.media]) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
200 |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
201 self.tweets.append((text, media_names)) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
202 self.media = [] |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
203 |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
204 def simple_upload(self, fname, file=None): |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
205 self.media.append(fname) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
206 return len(self.media) - 1 |
2 | 207 |
208 | |
209 class TwitterMockUtil: | |
210 def installTokens(self, cli, silo_name): | |
211 def do_install_tokens(ctx): | |
212 ctx.cache.setCustomValue( | |
213 '%s_clienttoken' % silo_name, | |
214 'TEST_CLIENT_KEY,TEST_CLIENT_SECRET') | |
215 ctx.cache.setCustomValue( | |
216 '%s_accesstoken' % silo_name, | |
217 'TEST_ACCESS_KEY,TEST_ACCESS_SECRET') | |
218 | |
219 cli.preExecHook(do_install_tokens) |