mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-18 19:14:03 +00:00
Merge branch 'missing-tesla-mocks' into 'develop'
add missing tesla mocks See merge request pleroma/pleroma!1879
This commit is contained in:
commit
f7f69356bd
|
@ -25,13 +25,13 @@ def parse(url) when is_binary(url) do
|
|||
def parse(_), do: {:error, "No URL provided"}
|
||||
|
||||
defp parse_url(url) do
|
||||
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: @hackney_options)
|
||||
|
||||
data =
|
||||
Floki.attribute(html, "link[rel~=me]", "href") ++
|
||||
Floki.attribute(html, "a[rel~=me]", "href")
|
||||
|
||||
{:ok, data}
|
||||
with {:ok, %Tesla.Env{body: html, status: status}} when status in 200..299 <-
|
||||
Pleroma.HTTP.get(url, [], adapter: @hackney_options),
|
||||
data <-
|
||||
Floki.attribute(html, "link[rel~=me]", "href") ++
|
||||
Floki.attribute(html, "a[rel~=me]", "href") do
|
||||
{:ok, data}
|
||||
end
|
||||
rescue
|
||||
e -> {:error, "Parsing error: #{inspect(e)}"}
|
||||
end
|
||||
|
|
|
@ -1183,6 +1183,30 @@ def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp",
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://10.111.10.1/notice/9kCP7V", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end
|
||||
|
||||
def get("https://172.16.32.40/notice/9kCP7V", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end
|
||||
|
||||
def get("https://192.168.10.40/notice/9kCP7V", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end
|
||||
|
||||
def get("https://www.patreon.com/posts/mastodon-2-9-and-28121681", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end
|
||||
|
||||
def get("http://mastodon.example.org/@admin/99541947525187367", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/mastodon-post-activity.json")}}
|
||||
end
|
||||
|
||||
def get("https://info.pleroma.site/activity4.json", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 500, body: "Error occurred"}}
|
||||
end
|
||||
|
||||
def get("http://example.com/rel_me/anchor", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}
|
||||
end
|
||||
|
@ -1215,6 +1239,10 @@ def get("https://patch.cx/users/rin", _, _, _) do
|
|||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}}
|
||||
end
|
||||
|
||||
def get("http://example.com/rel_me/error", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 404, body: ""}}
|
||||
end
|
||||
|
||||
def get(url, query, body, headers) do
|
||||
{:error,
|
||||
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||
|
|
|
@ -14,7 +14,9 @@ test "parse/1" do
|
|||
hrefs = ["https://social.example.org/users/lain"]
|
||||
|
||||
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/null") == {:ok, []}
|
||||
assert {:error, _} = Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
|
||||
|
||||
assert {:ok, %Tesla.Env{status: 404}} =
|
||||
Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
|
||||
|
||||
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
|
||||
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs}
|
||||
|
|
Loading…
Reference in a new issue