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