Add some more tests.
[akkoma] / test / support / httpoison_mock.ex
1 defmodule HTTPoisonMock do
2 alias HTTPoison.Response
3
4 def get(url, body \\ [], headers \\ [])
5
6 def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "nonexistant@social.heldscal.la"]]) do
7 {:ok, %Response{
8 status_code: 500,
9 body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
10 }}
11 end
12
13 def get("https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la", [Accept: "application/xrd+xml"], []) do
14 {:ok, %Response{
15 status_code: 200,
16 body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
17 }}
18 end
19
20 def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "shp@social.heldscal.la"]]) do
21 {:ok, %Response{
22 status_code: 200,
23 body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
24 }}
25 end
26
27 def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://social.heldscal.la/user/23211"]]) do
28 {:ok, %Response{
29 status_code: 200,
30 body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
31 }}
32 end
33
34 def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211", [Accept: "application/xrd+xml"], []) do
35 {:ok, %Response{
36 status_code: 200,
37 body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
38 }}
39 end
40
41 def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://social.heldscal.la/user/29191"]]) do
42 {:ok, %Response{
43 status_code: 200,
44 body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
45 }}
46 end
47
48 def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191", [Accept: "application/xrd+xml"], []) do
49 {:ok, %Response{
50 status_code: 200,
51 body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
52 }}
53 end
54
55 def get("https://mastodon.social/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://mastodon.social/users/lambadalambda"]]) do
56 {:ok, %Response{
57 status_code: 200,
58 body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml")
59 }}
60 end
61
62 def get("https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda", [Accept: "application/xrd+xml"], []) do
63 {:ok, %Response{
64 status_code: 200,
65 body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml")
66 }}
67 end
68
69 def get("https://shitposter.club/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://shitposter.club/user/1"]]) do
70 {:ok, %Response{
71 status_code: 200,
72 body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
73 }}
74 end
75
76 def get("https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1", [Accept: "application/xrd+xml"], []) do
77 {:ok, %Response{
78 status_code: 200,
79 body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
80 }}
81 end
82
83 def get("http://gs.example.org/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "http://gs.example.org:4040/index.php/user/1"], follow_redirect: true]) do
84 {:ok, %Response{
85 status_code: 200,
86 body: File.read!("test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml")
87 }}
88 end
89
90 def get("http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1", [Accept: "application/xrd+xml"], []) do
91 {:ok, %Response{
92 status_code: 200,
93 body: File.read!("test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml")
94 }}
95 end
96
97 def get("https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=https://social.stopwatchingus-heidelberg.de/user/18330", [Accept: "application/xrd+xml"], []) do
98 {:ok, %Response{
99 status_code: 200,
100 body: File.read!("test/fixtures/httpoison_mock/atarifrosch_webfinger.xml")
101 }}
102 end
103
104 def get("https://pleroma.soykaf.com/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://pleroma.soykaf.com/users/lain"]]) do
105 {:ok, %Response{
106 status_code: 200,
107 body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
108 }}
109 end
110
111 def get("https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain", [Accept: "application/xrd+xml"], []) do
112 {:ok, %Response{
113 status_code: 200,
114 body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
115 }}
116 end
117
118 def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _body, _headers) do
119 {:ok, %Response{
120 status_code: 200,
121 body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml")
122 }}
123 end
124
125 def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _body, _headers) do
126 {:ok, %Response{
127 status_code: 200,
128 body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml")
129 }}
130 end
131
132 def get("https://mastodon.social/users/lambadalambda.atom", _body, _headers) do
133 {:ok, %Response{
134 status_code: 200,
135 body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.atom")
136 }}
137 end
138
139 def get("https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom", _body, _headers) do
140 {:ok, %Response{
141 status_code: 200,
142 body: File.read!("test/fixtures/httpoison_mock/atarifrosch_feed.xml")
143 }}
144 end
145
146 def get("https://pleroma.soykaf.com/users/lain/feed.atom", _body, _headers) do
147 {:ok, %Response{
148 status_code: 200,
149 body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml")
150 }}
151 end
152
153 def get("https://social.sakamoto.gq/users/eal/feed.atom", _body, _headers) do
154 {:ok, %Response{
155 status_code: 200,
156 body: File.read!("test/fixtures/httpoison_mock/sakamoto_eal_feed.atom")
157 }}
158 end
159
160 def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _body, _headers) do
161 {:ok, %Response{
162 status_code: 200,
163 body: File.read!("test/fixtures/httpoison_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml")
164 }}
165 end
166
167 def get("https://shitposter.club/notice/2827873", _body, _headers) do
168 {:ok, %Response{
169 status_code: 200,
170 body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html")
171 }}
172 end
173
174 def get("https://shitposter.club/api/statuses/show/2827873.atom", _body, _headers) do
175 {:ok, %Response{
176 status_code: 200,
177 body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml")
178 }}
179 end
180
181 def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _body, _headers) do
182 {:ok, %Response{
183 status_code: 200,
184 body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml")
185 }}
186 end
187
188 def post("https://social.heldscal.la/main/push/hub", {:form, data}, ["Content-type": "application/x-www-form-urlencoded"]) do
189 {:ok, %Response{
190 status_code: 202
191 }}
192 end
193
194 def get("https://pawoo.net/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://pawoo.net/users/pekorino"]]) do
195 {:ok, %Response{
196 status_code: 200,
197 body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
198 }}
199 end
200
201 def get("https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino", [Accept: "application/xrd+xml"], []) do
202 {:ok, %Response{
203 status_code: 200,
204 body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
205 }}
206 end
207
208 def get("https://pawoo.net/users/pekorino.atom", _, _) do
209 {:ok, %Response{
210 status_code: 200,
211 body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom")
212 }}
213 end
214
215 def get("https://mamot.fr/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://mamot.fr/users/Skruyb"]]) do
216 {:ok, %Response{
217 status_code: 200,
218 body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
219 }}
220 end
221
222 def get("https://mamot.fr/.well-known/webfinger?resource=https://mamot.fr/users/Skruyb", [Accept: "application/xrd+xml"], []) do
223 {:ok, %Response{
224 status_code: 200,
225 body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
226 }}
227 end
228
229 def get("https://social.sakamoto.gq/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://social.sakamoto.gq/users/eal"]]) do
230 {:ok, %Response{
231 status_code: 200,
232 body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
233 }}
234 end
235
236 def get("https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal", [Accept: "application/xrd+xml"], []) do
237 {:ok, %Response{
238 status_code: 200,
239 body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
240 }}
241 end
242
243 def get("https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/shp", [Accept: "application/xrd+xml"], []) do
244 {:ok, %Response{
245 status_code: 200,
246 body: File.read!("test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.webfigner")
247 }}
248 end
249
250 def get("https://squeet.me/xrd/?uri=lain@squeet.me", [Accept: "application/xrd+xml"], []) do
251 {:ok, %Response{
252 status_code: 200,
253 body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
254 }}
255 end
256
257 def get("https://mamot.fr/users/Skruyb.atom", _, _) do
258 {:ok, %Response{
259 status_code: 200,
260 body: File.read!("test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom")
261 }}
262 end
263
264 def get("https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056", [Accept: "application/atom+xml"], _) do
265 {:ok, %Response{
266 status_code: 200,
267 body: File.read!("test/fixtures/httpoison_mock/sakamoto.atom")
268 }}
269 end
270
271 def get("https://pleroma.soykaf.com/users/shp/feed.atom", _, _) do
272 {:ok, %Response{
273 status_code: 200,
274 body: File.read!("test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.feed")
275 }}
276 end
277
278 def get("http://social.heldscal.la/.well-known/host-meta", [], [follow_redirect: true]) do
279 {:ok, %Response{
280 status_code: 200,
281 body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")
282 }}
283 end
284
285 def get("http://macgirvin.com/.well-known/host-meta", [], [follow_redirect: true]) do
286 {:ok, %Response{
287 status_code: 200,
288 body: File.read!("test/fixtures/httpoison_mock/macgirvin.com_host_meta")
289 }}
290 end
291
292 def get("http://mastodon.social/.well-known/host-meta", [], [follow_redirect: true]) do
293 {:ok, %Response{
294 status_code: 200,
295 body: File.read!("test/fixtures/httpoison_mock/mastodon.social_host_meta")
296 }}
297 end
298
299 def get("http://shitposter.club/.well-known/host-meta", [], [follow_redirect: true]) do
300 {:ok, %Response{
301 status_code: 200,
302 body: File.read!("test/fixtures/httpoison_mock/shitposter.club_host_meta")
303 }}
304 end
305
306 def get("http://pleroma.soykaf.com/.well-known/host-meta", [], [follow_redirect: true]) do
307 {:ok, %Response{
308 status_code: 200,
309 body: File.read!("test/fixtures/httpoison_mock/pleroma.soykaf.com_host_meta")
310 }}
311 end
312
313 def get("http://social.sakamoto.gq/.well-known/host-meta", [], [follow_redirect: true]) do
314 {:ok, %Response{
315 status_code: 200,
316 body: File.read!("test/fixtures/httpoison_mock/social.sakamoto.gq_host_meta")
317 }}
318 end
319
320 def get("http://gs.example.org/.well-known/host-meta", [], [follow_redirect: true]) do
321 {:ok, %Response{
322 status_code: 200,
323 body: File.read!("test/fixtures/httpoison_mock/gs.example.org_host_meta")
324 }}
325 end
326
327 def get("http://pawoo.net/.well-known/host-meta", [], [follow_redirect: true]) do
328 {:ok, %Response{
329 status_code: 200,
330 body: File.read!("test/fixtures/httpoison_mock/pawoo.net_host_meta")
331 }}
332 end
333
334 def get("http://mamot.fr/.well-known/host-meta", [], [follow_redirect: true]) do
335 {:ok, %Response{
336 status_code: 200,
337 body: File.read!("test/fixtures/httpoison_mock/mamot.fr_host_meta")
338 }}
339 end
340
341 def get("http://mastodon.xyz/.well-known/host-meta", [], [follow_redirect: true]) do
342 {:ok, %Response{
343 status_code: 200,
344 body: File.read!("test/fixtures/httpoison_mock/mastodon.xyz_host_meta")
345 }}
346 end
347
348 def get("http://social.wxcafe.net/.well-known/host-meta", [], [follow_redirect: true]) do
349 {:ok, %Response{
350 status_code: 200,
351 body: File.read!("test/fixtures/httpoison_mock/social.wxcafe.net_host_meta")
352 }}
353 end
354
355 def get("http://squeet.me/.well-known/host-meta", [], [follow_redirect: true]) do
356 {:ok, %Response{
357 status_code: 200,
358 body: File.read!("test/fixtures/httpoison_mock/squeet.me_host_meta")
359 }}
360 end
361
362 def get("http://social.stopwatchingus-heidelberg.de/.well-known/host-meta", [], [follow_redirect: true]) do
363 {:ok, %Response{
364 status_code: 200,
365 body: File.read!("test/fixtures/httpoison_mock/social.stopwatchingus-heidelberg.de_host_meta")
366 }}
367 end
368
369 def get("http://mastodon.example.org/users/admin", ["Accept": "application/activity+json"], _) do
370 {:ok, %Response{
371 status_code: 200,
372 body: File.read!("test/fixtures/httpoison_mock/admin@mastdon.example.org.json")
373 }}
374 end
375
376 def get("https://masto.quad.moe/users/_HellPie", ["Accept": "application/activity+json"], _) do
377 {:ok, %Response{
378 status_code: 200,
379 body: File.read!("test/fixtures/httpoison_mock/hellpie.json")
380 }}
381 end
382
383 def get("https://niu.moe/users/rye", ["Accept": "application/activity+json"], _) do
384 {:ok, %Response{
385 status_code: 200,
386 body: File.read!("test/fixtures/httpoison_mock/rye.json")
387 }}
388 end
389
390 def get("http://mastodon.example.org/@admin/99541947525187367", ["Accept": "application/activity+json"], _) do
391 {:ok, %Response{
392 status_code: 200,
393 body: File.read!("test/fixtures/mastodon-note-object.json")
394 }}
395 end
396
397 def get(url, body, headers) do
398 {:error, "Not implemented the mock response for get #{inspect(url)}, #{inspect(body)}, #{inspect(headers)}"}
399 end
400
401 def post(url, body, headers) do
402 {:error, "Not implemented the mock response for post #{inspect(url)}"}
403 end
404 end