31c085e0d640ecf9b2605b8c898dc1dd9f1138ea
[akkoma] / test / support / http_request_mock.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule HttpRequestMock do
6 require Logger
7
8 def request(
9 %Tesla.Env{
10 url: url,
11 method: method,
12 headers: headers,
13 query: query,
14 body: body
15 } = _env
16 ) do
17 with {:ok, res} <- apply(__MODULE__, method, [url, query, body, headers]) do
18 res
19 else
20 {_, _r} = error ->
21 # Logger.warn(r)
22 error
23 end
24 end
25
26 # GET Requests
27 #
28 def get(url, query \\ [], body \\ [], headers \\ [])
29
30 def get("https://osada.macgirvin.com/channel/mike", _, _, _) do
31 {:ok,
32 %Tesla.Env{
33 status: 200,
34 body: File.read!("test/fixtures/tesla_mock/https___osada.macgirvin.com_channel_mike.json")
35 }}
36 end
37
38 def get("https://mastodon.social/users/emelie/statuses/101849165031453009", _, _, _) do
39 {:ok,
40 %Tesla.Env{
41 status: 200,
42 body: File.read!("test/fixtures/tesla_mock/status.emelie.json")
43 }}
44 end
45
46 def get("https://mastodon.social/users/emelie", _, _, _) do
47 {:ok,
48 %Tesla.Env{
49 status: 200,
50 body: File.read!("test/fixtures/tesla_mock/emelie.json")
51 }}
52 end
53
54 def get("https://mastodon.sdf.org/users/rinpatch", _, _, _) do
55 {:ok,
56 %Tesla.Env{
57 status: 200,
58 body: File.read!("test/fixtures/tesla_mock/rinpatch.json")
59 }}
60 end
61
62 def get(
63 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/emelie",
64 _,
65 _,
66 _
67 ) do
68 {:ok,
69 %Tesla.Env{
70 status: 200,
71 body: File.read!("test/fixtures/tesla_mock/webfinger_emelie.json")
72 }}
73 end
74
75 def get("https://mastodon.social/users/emelie.atom", _, _, _) do
76 {:ok,
77 %Tesla.Env{
78 status: 200,
79 body: File.read!("test/fixtures/tesla_mock/emelie.atom")
80 }}
81 end
82
83 def get(
84 "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
85 _,
86 _,
87 Accept: "application/xrd+xml,application/jrd+json"
88 ) do
89 {:ok,
90 %Tesla.Env{
91 status: 200,
92 body: File.read!("test/fixtures/tesla_mock/mike@osada.macgirvin.com.json")
93 }}
94 end
95
96 def get(
97 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
98 _,
99 _,
100 Accept: "application/xrd+xml,application/jrd+json"
101 ) do
102 {:ok,
103 %Tesla.Env{
104 status: 200,
105 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_29191.xml")
106 }}
107 end
108
109 def get("https://pawoo.net/users/pekorino.atom", _, _, _) do
110 {:ok,
111 %Tesla.Env{
112 status: 200,
113 body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.atom")
114 }}
115 end
116
117 def get(
118 "https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
119 _,
120 _,
121 Accept: "application/xrd+xml,application/jrd+json"
122 ) do
123 {:ok,
124 %Tesla.Env{
125 status: 200,
126 body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml")
127 }}
128 end
129
130 def get(
131 "https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom",
132 _,
133 _,
134 _
135 ) do
136 {:ok,
137 %Tesla.Env{
138 status: 200,
139 body: File.read!("test/fixtures/tesla_mock/atarifrosch_feed.xml")
140 }}
141 end
142
143 def get(
144 "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
145 _,
146 _,
147 Accept: "application/xrd+xml,application/jrd+json"
148 ) do
149 {:ok,
150 %Tesla.Env{
151 status: 200,
152 body: File.read!("test/fixtures/tesla_mock/atarifrosch_webfinger.xml")
153 }}
154 end
155
156 def get("https://mamot.fr/users/Skruyb.atom", _, _, _) do
157 {:ok,
158 %Tesla.Env{
159 status: 200,
160 body: File.read!("test/fixtures/tesla_mock/https___mamot.fr_users_Skruyb.atom")
161 }}
162 end
163
164 def get(
165 "https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb",
166 _,
167 _,
168 Accept: "application/xrd+xml,application/jrd+json"
169 ) do
170 {:ok,
171 %Tesla.Env{
172 status: 200,
173 body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom")
174 }}
175 end
176
177 def get(
178 "https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la",
179 _,
180 _,
181 Accept: "application/xrd+xml,application/jrd+json"
182 ) do
183 {:ok,
184 %Tesla.Env{
185 status: 200,
186 body: File.read!("test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml")
187 }}
188 end
189
190 def get(
191 "https://squeet.me/xrd/?uri=lain@squeet.me",
192 _,
193 _,
194 Accept: "application/xrd+xml,application/jrd+json"
195 ) do
196 {:ok,
197 %Tesla.Env{
198 status: 200,
199 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
200 }}
201 end
202
203 def get(
204 "https://mst3k.interlinked.me/users/luciferMysticus",
205 _,
206 _,
207 Accept: "application/activity+json"
208 ) do
209 {:ok,
210 %Tesla.Env{
211 status: 200,
212 body: File.read!("test/fixtures/tesla_mock/lucifermysticus.json")
213 }}
214 end
215
216 def get("https://prismo.news/@mxb", _, _, _) do
217 {:ok,
218 %Tesla.Env{
219 status: 200,
220 body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json")
221 }}
222 end
223
224 def get(
225 "https://hubzilla.example.org/channel/kaniini",
226 _,
227 _,
228 Accept: "application/activity+json"
229 ) do
230 {:ok,
231 %Tesla.Env{
232 status: 200,
233 body: File.read!("test/fixtures/tesla_mock/kaniini@hubzilla.example.org.json")
234 }}
235 end
236
237 def get("https://niu.moe/users/rye", _, _, Accept: "application/activity+json") do
238 {:ok,
239 %Tesla.Env{
240 status: 200,
241 body: File.read!("test/fixtures/tesla_mock/rye.json")
242 }}
243 end
244
245 def get("https://n1u.moe/users/rye", _, _, Accept: "application/activity+json") do
246 {:ok,
247 %Tesla.Env{
248 status: 200,
249 body: File.read!("test/fixtures/tesla_mock/rye.json")
250 }}
251 end
252
253 def get("http://mastodon.example.org/users/admin/statuses/100787282858396771", _, _, _) do
254 {:ok,
255 %Tesla.Env{
256 status: 200,
257 body:
258 File.read!(
259 "test/fixtures/tesla_mock/http___mastodon.example.org_users_admin_status_1234.json"
260 )
261 }}
262 end
263
264 def get("https://puckipedia.com/", _, _, Accept: "application/activity+json") do
265 {:ok,
266 %Tesla.Env{
267 status: 200,
268 body: File.read!("test/fixtures/tesla_mock/puckipedia.com.json")
269 }}
270 end
271
272 def get("https://peertube.moe/accounts/7even", _, _, _) do
273 {:ok,
274 %Tesla.Env{
275 status: 200,
276 body: File.read!("test/fixtures/tesla_mock/7even.json")
277 }}
278 end
279
280 def get("https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3", _, _, _) do
281 {:ok,
282 %Tesla.Env{
283 status: 200,
284 body: File.read!("test/fixtures/tesla_mock/peertube.moe-vid.json")
285 }}
286 end
287
288 def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do
289 {:ok,
290 %Tesla.Env{
291 status: 200,
292 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
293 }}
294 end
295
296 def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _, _) do
297 {:ok,
298 %Tesla.Env{
299 status: 200,
300 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
301 }}
302 end
303
304 def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do
305 {:ok,
306 %Tesla.Env{
307 status: 200,
308 body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json")
309 }}
310 end
311
312 def get("http://mastodon.example.org/users/gargron", _, _, Accept: "application/activity+json") do
313 {:error, :nxdomain}
314 end
315
316 def get(
317 "http://mastodon.example.org/@admin/99541947525187367",
318 _,
319 _,
320 Accept: "application/activity+json"
321 ) do
322 {:ok,
323 %Tesla.Env{
324 status: 200,
325 body: File.read!("test/fixtures/mastodon-note-object.json")
326 }}
327 end
328
329 def get("https://shitposter.club/notice/7369654", _, _, _) do
330 {:ok,
331 %Tesla.Env{
332 status: 200,
333 body: File.read!("test/fixtures/tesla_mock/7369654.html")
334 }}
335 end
336
337 def get("https://mstdn.io/users/mayuutann", _, _, Accept: "application/activity+json") do
338 {:ok,
339 %Tesla.Env{
340 status: 200,
341 body: File.read!("test/fixtures/tesla_mock/mayumayu.json")
342 }}
343 end
344
345 def get(
346 "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
347 _,
348 _,
349 Accept: "application/activity+json"
350 ) do
351 {:ok,
352 %Tesla.Env{
353 status: 200,
354 body: File.read!("test/fixtures/tesla_mock/mayumayupost.json")
355 }}
356 end
357
358 def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
359 {:ok,
360 %Tesla.Env{
361 status: 200,
362 body:
363 File.read!(
364 "test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
365 )
366 }}
367 end
368
369 def get(url, _, _, Accept: "application/xrd+xml,application/jrd+json")
370 when url in [
371 "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
372 "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
373 ] do
374 {:ok,
375 %Tesla.Env{
376 status: 200,
377 body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
378 }}
379 end
380
381 def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _, _, _) do
382 {:ok,
383 %Tesla.Env{
384 status: 200,
385 body:
386 File.read!(
387 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
388 )
389 }}
390 end
391
392 def get(
393 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
394 _,
395 _,
396 Accept: "application/xrd+xml,application/jrd+json"
397 ) do
398 {:ok,
399 %Tesla.Env{
400 status: 200,
401 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
402 }}
403 end
404
405 def get("https://shitposter.club/notice/2827873", _, _, _) do
406 {:ok,
407 %Tesla.Env{
408 status: 200,
409 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.html")
410 }}
411 end
412
413 def get("https://shitposter.club/api/statuses/show/2827873.atom", _, _, _) do
414 {:ok,
415 %Tesla.Env{
416 status: 200,
417 body:
418 File.read!(
419 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
420 )
421 }}
422 end
423
424 def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
425 {:ok, %Tesla.Env{status: 200}}
426 end
427
428 def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _, _, _) do
429 {:ok,
430 %Tesla.Env{
431 status: 200,
432 body: File.read!("test/fixtures/tesla_mock/spc_5381.atom")
433 }}
434 end
435
436 def get(
437 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
438 _,
439 _,
440 Accept: "application/xrd+xml,application/jrd+json"
441 ) do
442 {:ok,
443 %Tesla.Env{
444 status: 200,
445 body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
446 }}
447 end
448
449 def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
450 {:ok,
451 %Tesla.Env{
452 status: 200,
453 body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
454 }}
455 end
456
457 def get("https://shitposter.club/api/statuses/show/7369654.atom", _, _, _) do
458 {:ok,
459 %Tesla.Env{
460 status: 200,
461 body: File.read!("test/fixtures/tesla_mock/7369654.atom")
462 }}
463 end
464
465 def get("https://shitposter.club/notice/4027863", _, _, _) do
466 {:ok,
467 %Tesla.Env{
468 status: 200,
469 body: File.read!("test/fixtures/tesla_mock/7369654.html")
470 }}
471 end
472
473 def get("https://social.sakamoto.gq/users/eal/feed.atom", _, _, _) do
474 {:ok,
475 %Tesla.Env{
476 status: 200,
477 body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom")
478 }}
479 end
480
481 def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
482 {:ok,
483 %Tesla.Env{
484 status: 200,
485 body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
486 }}
487 end
488
489 def get(
490 "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
491 _,
492 _,
493 Accept: "application/xrd+xml,application/jrd+json"
494 ) do
495 {:ok,
496 %Tesla.Env{
497 status: 200,
498 body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
499 }}
500 end
501
502 def get(
503 "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
504 _,
505 _,
506 Accept: "application/atom+xml"
507 ) do
508 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}
509 end
510
511 def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
512 {:ok,
513 %Tesla.Env{
514 status: 200,
515 body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
516 }}
517 end
518
519 def get(
520 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
521 _,
522 _,
523 Accept: "application/xrd+xml,application/jrd+json"
524 ) do
525 {:ok,
526 %Tesla.Env{
527 status: 200,
528 body:
529 File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
530 }}
531 end
532
533 def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
534 {:ok,
535 %Tesla.Env{
536 status: 200,
537 body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
538 }}
539 end
540
541 def get(
542 "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
543 _,
544 _,
545 Accept: "application/xrd+xml,application/jrd+json"
546 ) do
547 {:ok,
548 %Tesla.Env{
549 status: 200,
550 body:
551 File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
552 }}
553 end
554
555 def get(
556 "http://gs.example.org:4040/index.php/user/1",
557 _,
558 _,
559 Accept: "application/activity+json"
560 ) do
561 {:ok, %Tesla.Env{status: 406, body: ""}}
562 end
563
564 def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do
565 {:ok,
566 %Tesla.Env{
567 status: 200,
568 body:
569 File.read!(
570 "test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
571 )
572 }}
573 end
574
575 def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _, _, _) do
576 {:ok,
577 %Tesla.Env{
578 status: 200,
579 body:
580 File.read!(
581 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
582 )
583 }}
584 end
585
586 def get("http://squeet.me/.well-known/host-meta", _, _, _) do
587 {:ok,
588 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
589 end
590
591 def get(
592 "https://squeet.me/xrd?uri=lain@squeet.me",
593 _,
594 _,
595 Accept: "application/xrd+xml,application/jrd+json"
596 ) do
597 {:ok,
598 %Tesla.Env{
599 status: 200,
600 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
601 }}
602 end
603
604 def get(
605 "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",
606 _,
607 _,
608 Accept: "application/xrd+xml,application/jrd+json"
609 ) do
610 {:ok,
611 %Tesla.Env{
612 status: 200,
613 body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
614 }}
615 end
616
617 def get(
618 "https://social.heldscal.la/.well-known/webfinger?resource=invalid_content@social.heldscal.la",
619 _,
620 _,
621 Accept: "application/xrd+xml,application/jrd+json"
622 ) do
623 {:ok, %Tesla.Env{status: 200, body: ""}}
624 end
625
626 def get("http://framatube.org/.well-known/host-meta", _, _, _) do
627 {:ok,
628 %Tesla.Env{
629 status: 200,
630 body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
631 }}
632 end
633
634 def get(
635 "http://framatube.org/main/xrd?uri=framasoft@framatube.org",
636 _,
637 _,
638 Accept: "application/xrd+xml,application/jrd+json"
639 ) do
640 {:ok,
641 %Tesla.Env{
642 status: 200,
643 headers: [{"content-type", "application/json"}],
644 body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
645 }}
646 end
647
648 def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
649 {:ok,
650 %Tesla.Env{
651 status: 200,
652 body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
653 }}
654 end
655
656 def get(
657 "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
658 _,
659 _,
660 Accept: "application/xrd+xml,application/jrd+json"
661 ) do
662 {:ok,
663 %Tesla.Env{
664 status: 200,
665 body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
666 }}
667 end
668
669 def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
670 {:ok,
671 %Tesla.Env{
672 status: 200,
673 body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
674 }}
675 end
676
677 def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
678 {:ok,
679 %Tesla.Env{
680 status: 200,
681 body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
682 }}
683 end
684
685 def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
686 {:ok,
687 %Tesla.Env{
688 status: 200,
689 body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
690 }}
691 end
692
693 def get(
694 "https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de",
695 _,
696 _,
697 Accept: "application/xrd+xml,application/jrd+json"
698 ) do
699 {:ok,
700 %Tesla.Env{
701 status: 200,
702 headers: [{"content-type", "application/json"}],
703 body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
704 }}
705 end
706
707 def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
708 {:ok,
709 %Tesla.Env{
710 status: 200,
711 body:
712 File.read!(
713 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
714 )
715 }}
716 end
717
718 def get(
719 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
720 _,
721 _,
722 _
723 ) do
724 {:ok,
725 %Tesla.Env{
726 status: 200,
727 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
728 }}
729 end
730
731 def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
732 {:ok,
733 %Tesla.Env{
734 status: 200,
735 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
736 }}
737 end
738
739 def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
740 {:ok,
741 %Tesla.Env{
742 status: 200,
743 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
744 }}
745 end
746
747 def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
748 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
749 end
750
751 def get("https://mastodon.social/users/lambadalambda", _, _, _) do
752 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
753 end
754
755 def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
756 {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
757 end
758
759 def get("http://example.com/ogp", _, _, _) do
760 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
761 end
762
763 def get("https://example.com/ogp", _, _, _) do
764 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
765 end
766
767 def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
768 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
769 end
770
771 def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
772 {:ok,
773 %Tesla.Env{
774 status: 200,
775 body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
776 }}
777 end
778
779 def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
780 {:ok,
781 %Tesla.Env{
782 status: 200,
783 body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
784 }}
785 end
786
787 def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
788 {:ok,
789 %Tesla.Env{
790 status: 200,
791 body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
792 }}
793 end
794
795 def get("http://localhost:4001/users/fuser2/following", _, _, _) do
796 {:ok,
797 %Tesla.Env{
798 status: 200,
799 body: File.read!("test/fixtures/users_mock/pleroma_following.json")
800 }}
801 end
802
803 def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
804 {:ok,
805 %Tesla.Env{
806 status: 504,
807 body: ""
808 }}
809 end
810
811 def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
812 {:ok,
813 %Tesla.Env{
814 status: 504,
815 body: ""
816 }}
817 end
818
819 def get("http://example.com/ogp-missing-data", _, _, _) do
820 {:ok,
821 %Tesla.Env{
822 status: 200,
823 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
824 }}
825 end
826
827 def get("https://example.com/ogp-missing-data", _, _, _) do
828 {:ok,
829 %Tesla.Env{
830 status: 200,
831 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
832 }}
833 end
834
835 def get("http://example.com/malformed", _, _, _) do
836 {:ok,
837 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
838 end
839
840 def get("http://example.com/empty", _, _, _) do
841 {:ok, %Tesla.Env{status: 200, body: "hello"}}
842 end
843
844 def get("http://404.site" <> _, _, _, _) do
845 {:ok,
846 %Tesla.Env{
847 status: 404,
848 body: ""
849 }}
850 end
851
852 def get(
853 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=lain@zetsubou.xn--q9jyb4c",
854 _,
855 _,
856 Accept: "application/xrd+xml,application/jrd+json"
857 ) do
858 {:ok,
859 %Tesla.Env{
860 status: 200,
861 body: File.read!("test/fixtures/lain.xml")
862 }}
863 end
864
865 def get(
866 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=https://zetsubou.xn--q9jyb4c/users/lain",
867 _,
868 _,
869 Accept: "application/xrd+xml,application/jrd+json"
870 ) do
871 {:ok,
872 %Tesla.Env{
873 status: 200,
874 body: File.read!("test/fixtures/lain.xml")
875 }}
876 end
877
878 def get(
879 "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
880 _,
881 _,
882 _
883 ) do
884 {:ok,
885 %Tesla.Env{
886 status: 200,
887 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
888 }}
889 end
890
891 def get("https://info.pleroma.site/activity.json", _, _, Accept: "application/activity+json") do
892 {:ok,
893 %Tesla.Env{
894 status: 200,
895 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json")
896 }}
897 end
898
899 def get("https://info.pleroma.site/activity.json", _, _, _) do
900 {:ok, %Tesla.Env{status: 404, body: ""}}
901 end
902
903 def get("https://info.pleroma.site/activity2.json", _, _, Accept: "application/activity+json") do
904 {:ok,
905 %Tesla.Env{
906 status: 200,
907 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json")
908 }}
909 end
910
911 def get("https://info.pleroma.site/activity2.json", _, _, _) do
912 {:ok, %Tesla.Env{status: 404, body: ""}}
913 end
914
915 def get("https://info.pleroma.site/activity3.json", _, _, Accept: "application/activity+json") do
916 {:ok,
917 %Tesla.Env{
918 status: 200,
919 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json")
920 }}
921 end
922
923 def get("https://info.pleroma.site/activity3.json", _, _, _) do
924 {:ok, %Tesla.Env{status: 404, body: ""}}
925 end
926
927 def get(url, query, body, headers) do
928 {:error,
929 "Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
930 inspect(headers)
931 }"}
932 end
933
934 # POST Requests
935 #
936
937 def post(url, query \\ [], body \\ [], headers \\ [])
938
939 def post("http://example.org/needs_refresh", _, _, _) do
940 {:ok,
941 %Tesla.Env{
942 status: 200,
943 body: ""
944 }}
945 end
946
947 def post("http://mastodon.example.org/inbox", _, _, _) do
948 {:ok,
949 %Tesla.Env{
950 status: 200,
951 body: ""
952 }}
953 end
954
955 def post("https://hubzilla.example.org/inbox", _, _, _) do
956 {:ok,
957 %Tesla.Env{
958 status: 200,
959 body: ""
960 }}
961 end
962
963 def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
964 {:ok,
965 %Tesla.Env{
966 status: 200,
967 body: ""
968 }}
969 end
970
971 def post("http://200.site" <> _, _, _, _) do
972 {:ok,
973 %Tesla.Env{
974 status: 200,
975 body: ""
976 }}
977 end
978
979 def post("http://connrefused.site" <> _, _, _, _) do
980 {:error, :connrefused}
981 end
982
983 def post("http://404.site" <> _, _, _, _) do
984 {:ok,
985 %Tesla.Env{
986 status: 404,
987 body: ""
988 }}
989 end
990
991 def post(url, _query, _body, _headers) do
992 {:error, "Not implemented the mock response for post #{inspect(url)}"}
993 end
994 end