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