Mercurial > silorider
annotate tests/test_silos_twitter.py @ 55:d71871654790
Downgrade error message to warning message when datetimes can't be parsed
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 17 Oct 2023 15:31:09 -0700 |
parents | c5f73ebb43a5 |
children | d65f6dced79f |
rev | line source |
---|---|
2 | 1 import pytest |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
2 from .mockutil import mock_urllib |
2 | 3 |
4 | |
5 def test_one_article(cli, feedutil, tweetmock): | |
6 feed = cli.createTempFeed(feedutil.makeFeed( | |
7 """<h1 class="p-name">A new article</h1> | |
8 <div class="e-content"> | |
9 <p>This is the text of the article.</p> | |
10 <p>It has 2 paragraphs.</p> | |
11 </div> | |
12 <a class="u-url" href="https://example.org/a-new-article">permalink</a>""" | |
13 )) | |
14 | |
15 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
|
16 cli.setFeedConfig('feed', feed) |
2 | 17 tweetmock.installTokens(cli, 'test') |
18 | |
18
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
19 ctx, _ = cli.run('process') |
2 | 20 assert ctx.cache.wasPosted('test', 'https://example.org/a-new-article') |
21 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
|
22 assert toot == ('A new article https://example.org/a-new-article', []) |
2 | 23 |
24 | |
25 def test_one_micropost(cli, feedutil, tweetmock): | |
26 feed = cli.createTempFeed(feedutil.makeFeed( | |
27 """<p class="p-name">This is a quick update.</p> | |
28 <a class="u-url" href="/01234.html">permalink</a>""" | |
29 )) | |
30 | |
31 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
|
32 cli.setFeedConfig('feed', feed) |
2 | 33 tweetmock.installTokens(cli, 'test') |
34 | |
18
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
35 ctx, _ = cli.run('process') |
2 | 36 assert ctx.cache.wasPosted('test', '/01234.html') |
37 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
|
38 assert toot == ("This is a quick update.", []) |
2 | 39 |
40 | |
25
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
41 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
|
42 feed = cli.createTempFeed(feedutil.makeFeed( |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
43 """<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
|
44 you should fix your stuff!</p> |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
45 <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
|
46 )) |
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 cli.appendSiloConfig('test', 'twitter', url='/blah') |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
49 cli.setFeedConfig('feed', feed) |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
50 tweetmock.installTokens(cli, 'test') |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
51 |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
52 ctx, _ = cli.run('process') |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
53 assert ctx.cache.wasPosted('test', '/01234.html') |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
54 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
|
55 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
|
56 |
fb93d3fbff4e
Support transforming twitter profile URLs into mentions.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
57 |
2 | 58 def test_one_micropost_with_one_photo(cli, feedutil, tweetmock, monkeypatch): |
59 feed = cli.createTempFeed(feedutil.makeFeed( | |
60 """<p class="p-name">This is a quick photo update.</p> | |
61 <div> | |
62 <a class="u-photo" href="/fullimg.jpg"><img src="/thumbimg.jpg"/></a> | |
63 </div> | |
64 <a class="u-url" href="/01234.html">permalink</a>""" | |
65 )) | |
66 | |
67 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
|
68 cli.setFeedConfig('feed', feed) |
2 | 69 tweetmock.installTokens(cli, 'test') |
70 | |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
71 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
|
72 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
|
73 mock_urllib(m) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
74 m.setattr(silorider.silos.twitter.TwitterSilo, '_media_callback', |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
75 _patched_media_callback) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
76 ctx, _ = cli.run('process') |
2 | 77 |
78 assert ctx.cache.wasPosted('test', '/01234.html') | |
79 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
|
80 assert toot == ("This is a quick photo update.", ['/fullimg.jpg']) |
2 | 81 |
82 | |
83 def test_one_micropost_with_two_photos(cli, feedutil, tweetmock, monkeypatch): | |
84 feed = cli.createTempFeed(feedutil.makeFeed( | |
85 """<p class="p-name">This is a photo update with 2 photos.</p> | |
86 <div> | |
87 <a class="u-photo" href="/fullimg1.jpg"><img src="/thumbimg1.jpg"/></a> | |
88 <a class="u-photo" href="/fullimg2.jpg"><img src="/thumbimg2.jpg"/></a> | |
89 </div> | |
90 <a class="u-url" href="/01234.html">permalink</a>""" | |
91 )) | |
92 | |
93 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
|
94 cli.setFeedConfig('feed', feed) |
2 | 95 tweetmock.installTokens(cli, 'test') |
96 | |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
97 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
|
98 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
|
99 mock_urllib(m) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
100 m.setattr(silorider.silos.twitter.TwitterSilo, '_media_callback', |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
101 _patched_media_callback) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
102 ctx, _ = cli.run('process') |
2 | 103 |
104 assert ctx.cache.wasPosted('test', '/01234.html') | |
105 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
|
106 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
|
107 ['/fullimg1.jpg', '/fullimg2.jpg']) |
2 | 108 |
109 | |
33
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
110 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
|
111 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
|
112 """<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
|
113 <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
|
114 </div> |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
115 <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
|
116 )) |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
117 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
118 cli.appendSiloConfig('test', 'twitter', url='/blah') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
119 cli.setFeedConfig('feed', feed) |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
120 tweetmock.installTokens(cli, 'test') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
121 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
122 ctx, _ = cli.run('process') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 []) |
33
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
127 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
128 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
129 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
|
130 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
|
131 """<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
|
132 <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
|
133 </div> |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
134 <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
|
135 )) |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
136 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
137 cli.appendSiloConfig('test', 'twitter', url='/blah') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
138 cli.setFeedConfig('feed', feed) |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
139 tweetmock.installTokens(cli, 'test') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
140 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
141 ctx, _ = cli.run('process') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
142 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
|
143 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
|
144 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
|
145 []) |
33
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
146 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
147 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
148 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
|
149 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
|
150 """<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
|
151 <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
|
152 </div> |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
153 <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
|
154 )) |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
155 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
156 cli.appendSiloConfig('test', 'twitter', url='/blah') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
157 cli.setFeedConfig('feed', feed) |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
158 tweetmock.installTokens(cli, 'test') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
159 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
160 ctx, _ = cli.run('process') |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 []) |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
165 |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
166 |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
167 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
|
168 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
|
169 |
9e4eb3f2754e
Improve handling of character limits in html stripping
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
170 |
2 | 171 @pytest.fixture(scope='session') |
172 def tweetmock(): | |
173 from silorider.silos.twitter import TwitterSilo | |
174 TwitterSilo._CLIENT_CLASS = TwitterMock | |
175 return TwitterMockUtil() | |
176 | |
177 | |
178 class TwitterMock: | |
179 def __init__(self, consumer_key, consumer_secret, | |
180 access_token_key, access_token_secret): | |
181 assert consumer_key == 'TEST_CLIENT_KEY' | |
182 assert consumer_secret == 'TEST_CLIENT_SECRET' | |
183 assert access_token_key == 'TEST_ACCESS_KEY' | |
184 assert access_token_secret == 'TEST_ACCESS_SECRET' | |
185 | |
186 self.tweets = [] | |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
187 self.media = [] |
2 | 188 |
39
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
189 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
|
190 media_names = [] |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
191 if media_ids: |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 |
c5f73ebb43a5
Replace python-twitter with tweepy to use Twitter's V2 API
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
198 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
|
199 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 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
|
202 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
|
203 return len(self.media) - 1 |
2 | 204 |
205 | |
206 class TwitterMockUtil: | |
207 def installTokens(self, cli, silo_name): | |
208 def do_install_tokens(ctx): | |
209 ctx.cache.setCustomValue( | |
210 '%s_clienttoken' % silo_name, | |
211 'TEST_CLIENT_KEY,TEST_CLIENT_SECRET') | |
212 ctx.cache.setCustomValue( | |
213 '%s_accesstoken' % silo_name, | |
214 'TEST_ACCESS_KEY,TEST_ACCESS_SECRET') | |
215 | |
216 cli.preExecHook(do_install_tokens) |