Fix/1019 correct count remote users
[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("http://framatube.org/.well-known/host-meta", _, _, _) do
618 {:ok,
619 %Tesla.Env{
620 status: 200,
621 body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
622 }}
623 end
624
625 def get(
626 "http://framatube.org/main/xrd?uri=framasoft@framatube.org",
627 _,
628 _,
629 Accept: "application/xrd+xml,application/jrd+json"
630 ) do
631 {:ok,
632 %Tesla.Env{
633 status: 200,
634 headers: [{"content-type", "application/json"}],
635 body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
636 }}
637 end
638
639 def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
640 {:ok,
641 %Tesla.Env{
642 status: 200,
643 body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
644 }}
645 end
646
647 def get(
648 "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
649 _,
650 _,
651 Accept: "application/xrd+xml,application/jrd+json"
652 ) do
653 {:ok,
654 %Tesla.Env{
655 status: 200,
656 body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
657 }}
658 end
659
660 def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
661 {:ok,
662 %Tesla.Env{
663 status: 200,
664 body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
665 }}
666 end
667
668 def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
669 {:ok,
670 %Tesla.Env{
671 status: 200,
672 body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
673 }}
674 end
675
676 def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
677 {:ok,
678 %Tesla.Env{
679 status: 200,
680 body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
681 }}
682 end
683
684 def get(
685 "https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de",
686 _,
687 _,
688 Accept: "application/xrd+xml,application/jrd+json"
689 ) do
690 {:ok,
691 %Tesla.Env{
692 status: 200,
693 headers: [{"content-type", "application/json"}],
694 body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
695 }}
696 end
697
698 def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
699 {:ok,
700 %Tesla.Env{
701 status: 200,
702 body:
703 File.read!(
704 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
705 )
706 }}
707 end
708
709 def get(
710 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
711 _,
712 _,
713 _
714 ) do
715 {:ok,
716 %Tesla.Env{
717 status: 200,
718 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
719 }}
720 end
721
722 def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
723 {:ok,
724 %Tesla.Env{
725 status: 200,
726 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
727 }}
728 end
729
730 def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
731 {:ok,
732 %Tesla.Env{
733 status: 200,
734 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
735 }}
736 end
737
738 def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
739 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
740 end
741
742 def get("https://mastodon.social/users/lambadalambda", _, _, _) do
743 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
744 end
745
746 def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
747 {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
748 end
749
750 def get("http://example.com/ogp", _, _, _) do
751 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
752 end
753
754 def get("https://example.com/ogp", _, _, _) do
755 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
756 end
757
758 def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
759 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
760 end
761
762 def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
763 {:ok,
764 %Tesla.Env{
765 status: 200,
766 body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
767 }}
768 end
769
770 def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
771 {:ok,
772 %Tesla.Env{
773 status: 200,
774 body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
775 }}
776 end
777
778 def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
779 {:ok,
780 %Tesla.Env{
781 status: 200,
782 body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
783 }}
784 end
785
786 def get("http://localhost:4001/users/fuser2/following", _, _, _) do
787 {:ok,
788 %Tesla.Env{
789 status: 200,
790 body: File.read!("test/fixtures/users_mock/pleroma_following.json")
791 }}
792 end
793
794 def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
795 {:ok,
796 %Tesla.Env{
797 status: 504,
798 body: ""
799 }}
800 end
801
802 def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
803 {:ok,
804 %Tesla.Env{
805 status: 504,
806 body: ""
807 }}
808 end
809
810 def get("http://example.com/ogp-missing-data", _, _, _) do
811 {:ok,
812 %Tesla.Env{
813 status: 200,
814 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
815 }}
816 end
817
818 def get("https://example.com/ogp-missing-data", _, _, _) do
819 {:ok,
820 %Tesla.Env{
821 status: 200,
822 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
823 }}
824 end
825
826 def get("http://example.com/malformed", _, _, _) do
827 {:ok,
828 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
829 end
830
831 def get("http://example.com/empty", _, _, _) do
832 {:ok, %Tesla.Env{status: 200, body: "hello"}}
833 end
834
835 def get("http://404.site" <> _, _, _, _) do
836 {:ok,
837 %Tesla.Env{
838 status: 404,
839 body: ""
840 }}
841 end
842
843 def get(url, query, body, headers) do
844 {:error,
845 "Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
846 inspect(headers)
847 }"}
848 end
849
850 # POST Requests
851 #
852
853 def post(url, query \\ [], body \\ [], headers \\ [])
854
855 def post("http://example.org/needs_refresh", _, _, _) do
856 {:ok,
857 %Tesla.Env{
858 status: 200,
859 body: ""
860 }}
861 end
862
863 def post("http://mastodon.example.org/inbox", _, _, _) do
864 {:ok,
865 %Tesla.Env{
866 status: 200,
867 body: ""
868 }}
869 end
870
871 def post("https://hubzilla.example.org/inbox", _, _, _) do
872 {:ok,
873 %Tesla.Env{
874 status: 200,
875 body: ""
876 }}
877 end
878
879 def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
880 {:ok,
881 %Tesla.Env{
882 status: 200,
883 body: ""
884 }}
885 end
886
887 def post("http://200.site" <> _, _, _, _) do
888 {:ok,
889 %Tesla.Env{
890 status: 200,
891 body: ""
892 }}
893 end
894
895 def post("http://connrefused.site" <> _, _, _, _) do
896 {:error, :connrefused}
897 end
898
899 def post("http://404.site" <> _, _, _, _) do
900 {:ok,
901 %Tesla.Env{
902 status: 404,
903 body: ""
904 }}
905 end
906
907 def post(url, _query, _body, _headers) do
908 {:error, "Not implemented the mock response for post #{inspect(url)}"}
909 end
910 end