httpoison_mock.ex 6.02 KB
Newer Older
lain's avatar
lain committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
defmodule HTTPoisonMock do
  alias HTTPoison.Response

  def get(url, body \\ [], headers \\ [])

  def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "nonexistant@social.heldscal.la"]]) do
    {:ok, %Response{
      status_code: 500,
      body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
    }}
  end

  def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "shp@social.heldscal.la"]]) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
    }}
  end
lain's avatar
lain committed
19

lain's avatar
lain committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://social.heldscal.la/user/23211"]]) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
    }}
  end
  
  def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://social.heldscal.la/user/29191"]]) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
    }}
  end

  def get("https://mastodon.social/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://mastodon.social/users/lambadalambda"]]) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml")
    }}
  end

41 42 43 44 45 46 47
  def get("https://shitposter.club/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://shitposter.club/user/1"]]) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
    }}
  end

lain's avatar
lain committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
  def get("http://gs.example.org/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "http://gs.example.org:4040/index.php/user/1"], follow_redirect: true]) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml")
    }}
  end

  def get("https://pleroma.soykaf.com/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://pleroma.soykaf.com/users/lain"]]) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
    }}
  end

  def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _body, _headers) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml")
    }}
  end

  def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _body, _headers) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml")
    }}
  end

  def get("https://mastodon.social/users/lambadalambda.atom", _body, _headers) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.atom")
    }}
  end

  def get("https://pleroma.soykaf.com/users/lain/feed.atom", _body, _headers) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml")
    }}
  end

  def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _body, _headers) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml")
    }}
  end

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
  def get("https://shitposter.club/notice/2827873", _body, _headers) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html")
    }}
  end

  def get("https://shitposter.club/api/statuses/show/2827873.atom", _body, _headers) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml")
    }}
  end

  def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _body, _headers) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml")
    }}
  end

lain's avatar
lain committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
  def post("https://social.heldscal.la/main/push/hub", {:form, data}, ["Content-type": "application/x-www-form-urlencoded"]) do
    {:ok, %Response{
      status_code: 202
    }}
  end

  def get("https://pawoo.net/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://pawoo.net/users/pekorino"]]) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
    }}
  end

  def get("https://pawoo.net/users/pekorino.atom", _, _) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom")
    }}
  end

lain's avatar
lain committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151
  def get("https://mamot.fr/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://mamot.fr/users/Skruyb"]]) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
    }}
  end

  def get("https://mamot.fr/users/Skruyb.atom", _, _) do
    {:ok, %Response{
      status_code: 200,
      body: File.read!("test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom")
    }}
  end

lain's avatar
lain committed
152
  def get(url, body, headers) do
lain's avatar
lain committed
153
    {:error, "Not implemented the mock response for get #{inspect(url)}, #{inspect(body)}, #{inspect(headers)}"}
lain's avatar
lain committed
154 155 156 157 158 159
  end

  def post(url, body, headers) do
    {:error, "Not implemented the mock response for post #{inspect(url)}"}
  end
end