Add tests for counters being updated on follow
[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("https://wedistribute.org/wp-json/pterotype/v1/object/85810", _, _, _) do
305 {:ok,
306 %Tesla.Env{
307 status: 200,
308 body: File.read!("test/fixtures/tesla_mock/wedistribute-article.json")
309 }}
310 end
311
312 def get("https://wedistribute.org/wp-json/pterotype/v1/actor/-blog", _, _, _) do
313 {:ok,
314 %Tesla.Env{
315 status: 200,
316 body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")
317 }}
318 end
319
320 def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do
321 {:ok,
322 %Tesla.Env{
323 status: 200,
324 body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json")
325 }}
326 end
327
328 def get("http://mastodon.example.org/users/gargron", _, _, Accept: "application/activity+json") do
329 {:error, :nxdomain}
330 end
331
332 def get(
333 "http://mastodon.example.org/@admin/99541947525187367",
334 _,
335 _,
336 Accept: "application/activity+json"
337 ) do
338 {:ok,
339 %Tesla.Env{
340 status: 200,
341 body: File.read!("test/fixtures/mastodon-note-object.json")
342 }}
343 end
344
345 def get("https://shitposter.club/notice/7369654", _, _, _) do
346 {:ok,
347 %Tesla.Env{
348 status: 200,
349 body: File.read!("test/fixtures/tesla_mock/7369654.html")
350 }}
351 end
352
353 def get("https://mstdn.io/users/mayuutann", _, _, Accept: "application/activity+json") do
354 {:ok,
355 %Tesla.Env{
356 status: 200,
357 body: File.read!("test/fixtures/tesla_mock/mayumayu.json")
358 }}
359 end
360
361 def get(
362 "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
363 _,
364 _,
365 Accept: "application/activity+json"
366 ) do
367 {:ok,
368 %Tesla.Env{
369 status: 200,
370 body: File.read!("test/fixtures/tesla_mock/mayumayupost.json")
371 }}
372 end
373
374 def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
375 {:ok,
376 %Tesla.Env{
377 status: 200,
378 body:
379 File.read!(
380 "test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
381 )
382 }}
383 end
384
385 def get(url, _, _, Accept: "application/xrd+xml,application/jrd+json")
386 when url in [
387 "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
388 "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
389 ] do
390 {:ok,
391 %Tesla.Env{
392 status: 200,
393 body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
394 }}
395 end
396
397 def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _, _, _) do
398 {:ok,
399 %Tesla.Env{
400 status: 200,
401 body:
402 File.read!(
403 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
404 )
405 }}
406 end
407
408 def get(
409 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
410 _,
411 _,
412 Accept: "application/xrd+xml,application/jrd+json"
413 ) do
414 {:ok,
415 %Tesla.Env{
416 status: 200,
417 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
418 }}
419 end
420
421 def get("https://shitposter.club/notice/2827873", _, _, _) do
422 {:ok,
423 %Tesla.Env{
424 status: 200,
425 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.html")
426 }}
427 end
428
429 def get("https://shitposter.club/api/statuses/show/2827873.atom", _, _, _) do
430 {:ok,
431 %Tesla.Env{
432 status: 200,
433 body:
434 File.read!(
435 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
436 )
437 }}
438 end
439
440 def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
441 {:ok, %Tesla.Env{status: 200}}
442 end
443
444 def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _, _, _) do
445 {:ok,
446 %Tesla.Env{
447 status: 200,
448 body: File.read!("test/fixtures/tesla_mock/spc_5381.atom")
449 }}
450 end
451
452 def get(
453 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
454 _,
455 _,
456 Accept: "application/xrd+xml,application/jrd+json"
457 ) do
458 {:ok,
459 %Tesla.Env{
460 status: 200,
461 body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
462 }}
463 end
464
465 def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
466 {:ok,
467 %Tesla.Env{
468 status: 200,
469 body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
470 }}
471 end
472
473 def get("https://shitposter.club/api/statuses/show/7369654.atom", _, _, _) do
474 {:ok,
475 %Tesla.Env{
476 status: 200,
477 body: File.read!("test/fixtures/tesla_mock/7369654.atom")
478 }}
479 end
480
481 def get("https://shitposter.club/notice/4027863", _, _, _) do
482 {:ok,
483 %Tesla.Env{
484 status: 200,
485 body: File.read!("test/fixtures/tesla_mock/7369654.html")
486 }}
487 end
488
489 def get("https://social.sakamoto.gq/users/eal/feed.atom", _, _, _) do
490 {:ok,
491 %Tesla.Env{
492 status: 200,
493 body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom")
494 }}
495 end
496
497 def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
498 {:ok,
499 %Tesla.Env{
500 status: 200,
501 body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
502 }}
503 end
504
505 def get(
506 "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
507 _,
508 _,
509 Accept: "application/xrd+xml,application/jrd+json"
510 ) do
511 {:ok,
512 %Tesla.Env{
513 status: 200,
514 body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
515 }}
516 end
517
518 def get(
519 "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
520 _,
521 _,
522 Accept: "application/atom+xml"
523 ) do
524 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}
525 end
526
527 def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
528 {:ok,
529 %Tesla.Env{
530 status: 200,
531 body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
532 }}
533 end
534
535 def get(
536 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
537 _,
538 _,
539 Accept: "application/xrd+xml,application/jrd+json"
540 ) do
541 {:ok,
542 %Tesla.Env{
543 status: 200,
544 body:
545 File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
546 }}
547 end
548
549 def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
550 {:ok,
551 %Tesla.Env{
552 status: 200,
553 body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
554 }}
555 end
556
557 def get(
558 "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
559 _,
560 _,
561 Accept: "application/xrd+xml,application/jrd+json"
562 ) do
563 {:ok,
564 %Tesla.Env{
565 status: 200,
566 body:
567 File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
568 }}
569 end
570
571 def get(
572 "http://gs.example.org:4040/index.php/user/1",
573 _,
574 _,
575 Accept: "application/activity+json"
576 ) do
577 {:ok, %Tesla.Env{status: 406, body: ""}}
578 end
579
580 def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do
581 {:ok,
582 %Tesla.Env{
583 status: 200,
584 body:
585 File.read!(
586 "test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
587 )
588 }}
589 end
590
591 def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _, _, _) do
592 {:ok,
593 %Tesla.Env{
594 status: 200,
595 body:
596 File.read!(
597 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
598 )
599 }}
600 end
601
602 def get("http://squeet.me/.well-known/host-meta", _, _, _) do
603 {:ok,
604 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
605 end
606
607 def get(
608 "https://squeet.me/xrd?uri=lain@squeet.me",
609 _,
610 _,
611 Accept: "application/xrd+xml,application/jrd+json"
612 ) do
613 {:ok,
614 %Tesla.Env{
615 status: 200,
616 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
617 }}
618 end
619
620 def get(
621 "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",
622 _,
623 _,
624 Accept: "application/xrd+xml,application/jrd+json"
625 ) do
626 {:ok,
627 %Tesla.Env{
628 status: 200,
629 body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
630 }}
631 end
632
633 def get(
634 "https://social.heldscal.la/.well-known/webfinger?resource=invalid_content@social.heldscal.la",
635 _,
636 _,
637 Accept: "application/xrd+xml,application/jrd+json"
638 ) do
639 {:ok, %Tesla.Env{status: 200, body: ""}}
640 end
641
642 def get("http://framatube.org/.well-known/host-meta", _, _, _) do
643 {:ok,
644 %Tesla.Env{
645 status: 200,
646 body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
647 }}
648 end
649
650 def get(
651 "http://framatube.org/main/xrd?uri=framasoft@framatube.org",
652 _,
653 _,
654 Accept: "application/xrd+xml,application/jrd+json"
655 ) do
656 {:ok,
657 %Tesla.Env{
658 status: 200,
659 headers: [{"content-type", "application/json"}],
660 body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
661 }}
662 end
663
664 def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
665 {:ok,
666 %Tesla.Env{
667 status: 200,
668 body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
669 }}
670 end
671
672 def get(
673 "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
674 _,
675 _,
676 Accept: "application/xrd+xml,application/jrd+json"
677 ) do
678 {:ok,
679 %Tesla.Env{
680 status: 200,
681 body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
682 }}
683 end
684
685 def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
686 {:ok,
687 %Tesla.Env{
688 status: 200,
689 body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
690 }}
691 end
692
693 def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
694 {:ok,
695 %Tesla.Env{
696 status: 200,
697 body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
698 }}
699 end
700
701 def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
702 {:ok,
703 %Tesla.Env{
704 status: 200,
705 body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
706 }}
707 end
708
709 def get(
710 "https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de",
711 _,
712 _,
713 Accept: "application/xrd+xml,application/jrd+json"
714 ) do
715 {:ok,
716 %Tesla.Env{
717 status: 200,
718 headers: [{"content-type", "application/json"}],
719 body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
720 }}
721 end
722
723 def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
724 {:ok,
725 %Tesla.Env{
726 status: 200,
727 body:
728 File.read!(
729 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
730 )
731 }}
732 end
733
734 def get(
735 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
736 _,
737 _,
738 _
739 ) do
740 {:ok,
741 %Tesla.Env{
742 status: 200,
743 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
744 }}
745 end
746
747 def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
748 {:ok,
749 %Tesla.Env{
750 status: 200,
751 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
752 }}
753 end
754
755 def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
756 {:ok,
757 %Tesla.Env{
758 status: 200,
759 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
760 }}
761 end
762
763 def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
764 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
765 end
766
767 def get("https://mastodon.social/users/lambadalambda", _, _, _) do
768 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
769 end
770
771 def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
772 {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
773 end
774
775 def get("http://example.com/ogp", _, _, _) do
776 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
777 end
778
779 def get("https://example.com/ogp", _, _, _) do
780 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
781 end
782
783 def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
784 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
785 end
786
787 def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
788 {:ok,
789 %Tesla.Env{
790 status: 200,
791 body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
792 }}
793 end
794
795 def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
796 {:ok,
797 %Tesla.Env{
798 status: 200,
799 body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json")
800 }}
801 end
802
803 def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
804 {:ok,
805 %Tesla.Env{
806 status: 200,
807 body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
808 }}
809 end
810
811 def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
812 {:ok,
813 %Tesla.Env{
814 status: 200,
815 body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json")
816 }}
817 end
818
819 def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
820 {:ok,
821 %Tesla.Env{
822 status: 200,
823 body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
824 }}
825 end
826
827 def get("http://localhost:4001/users/fuser2/following", _, _, _) do
828 {:ok,
829 %Tesla.Env{
830 status: 200,
831 body: File.read!("test/fixtures/users_mock/pleroma_following.json")
832 }}
833 end
834
835 def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
836 {:ok,
837 %Tesla.Env{
838 status: 504,
839 body: ""
840 }}
841 end
842
843 def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
844 {:ok,
845 %Tesla.Env{
846 status: 504,
847 body: ""
848 }}
849 end
850
851 def get("http://example.com/ogp-missing-data", _, _, _) do
852 {:ok,
853 %Tesla.Env{
854 status: 200,
855 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
856 }}
857 end
858
859 def get("https://example.com/ogp-missing-data", _, _, _) do
860 {:ok,
861 %Tesla.Env{
862 status: 200,
863 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
864 }}
865 end
866
867 def get("http://example.com/malformed", _, _, _) do
868 {:ok,
869 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
870 end
871
872 def get("http://example.com/empty", _, _, _) do
873 {:ok, %Tesla.Env{status: 200, body: "hello"}}
874 end
875
876 def get("http://404.site" <> _, _, _, _) do
877 {:ok,
878 %Tesla.Env{
879 status: 404,
880 body: ""
881 }}
882 end
883
884 def get(
885 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=lain@zetsubou.xn--q9jyb4c",
886 _,
887 _,
888 Accept: "application/xrd+xml,application/jrd+json"
889 ) do
890 {:ok,
891 %Tesla.Env{
892 status: 200,
893 body: File.read!("test/fixtures/lain.xml")
894 }}
895 end
896
897 def get(
898 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=https://zetsubou.xn--q9jyb4c/users/lain",
899 _,
900 _,
901 Accept: "application/xrd+xml,application/jrd+json"
902 ) do
903 {:ok,
904 %Tesla.Env{
905 status: 200,
906 body: File.read!("test/fixtures/lain.xml")
907 }}
908 end
909
910 def get(
911 "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
912 _,
913 _,
914 _
915 ) do
916 {:ok,
917 %Tesla.Env{
918 status: 200,
919 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
920 }}
921 end
922
923 def get("https://info.pleroma.site/activity.json", _, _, Accept: "application/activity+json") do
924 {:ok,
925 %Tesla.Env{
926 status: 200,
927 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json")
928 }}
929 end
930
931 def get("https://info.pleroma.site/activity.json", _, _, _) do
932 {:ok, %Tesla.Env{status: 404, body: ""}}
933 end
934
935 def get("https://info.pleroma.site/activity2.json", _, _, Accept: "application/activity+json") do
936 {:ok,
937 %Tesla.Env{
938 status: 200,
939 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json")
940 }}
941 end
942
943 def get("https://info.pleroma.site/activity2.json", _, _, _) do
944 {:ok, %Tesla.Env{status: 404, body: ""}}
945 end
946
947 def get("https://info.pleroma.site/activity3.json", _, _, Accept: "application/activity+json") do
948 {:ok,
949 %Tesla.Env{
950 status: 200,
951 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json")
952 }}
953 end
954
955 def get("https://info.pleroma.site/activity3.json", _, _, _) do
956 {:ok, %Tesla.Env{status: 404, body: ""}}
957 end
958
959 def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
960 {:ok,
961 %Tesla.Env{
962 status: 200,
963 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
964 }}
965 end
966
967 def get(url, query, body, headers) do
968 {:error,
969 "Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
970 inspect(headers)
971 }"}
972 end
973
974 # POST Requests
975 #
976
977 def post(url, query \\ [], body \\ [], headers \\ [])
978
979 def post("http://example.org/needs_refresh", _, _, _) do
980 {:ok,
981 %Tesla.Env{
982 status: 200,
983 body: ""
984 }}
985 end
986
987 def post("http://mastodon.example.org/inbox", _, _, _) do
988 {:ok,
989 %Tesla.Env{
990 status: 200,
991 body: ""
992 }}
993 end
994
995 def post("https://hubzilla.example.org/inbox", _, _, _) do
996 {:ok,
997 %Tesla.Env{
998 status: 200,
999 body: ""
1000 }}
1001 end
1002
1003 def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
1004 {:ok,
1005 %Tesla.Env{
1006 status: 200,
1007 body: ""
1008 }}
1009 end
1010
1011 def post("http://200.site" <> _, _, _, _) do
1012 {:ok,
1013 %Tesla.Env{
1014 status: 200,
1015 body: ""
1016 }}
1017 end
1018
1019 def post("http://connrefused.site" <> _, _, _, _) do
1020 {:error, :connrefused}
1021 end
1022
1023 def post("http://404.site" <> _, _, _, _) do
1024 {:ok,
1025 %Tesla.Env{
1026 status: 404,
1027 body: ""
1028 }}
1029 end
1030
1031 def post(url, _query, _body, _headers) do
1032 {:error, "Not implemented the mock response for post #{inspect(url)}"}
1033 end
1034 end