summaryrefslogtreecommitdiff
path: root/test/support/http_request_mock.ex
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2024-02-07 05:47:38 +0000
committerfeld <feld@feld.me>2024-02-07 05:47:38 +0000
commit72480e7b2fc19beaa8a0a524e8b1c83442debd01 (patch)
tree22df6edc6f1ad0919825efcebdb92a3af2d43a30 /test/support/http_request_mock.ex
parente9573627792df4cdaea15f1ca1563594f477cd8e (diff)
parent9f2319e50dc0516bde4bfa3b117ec4792e553bd2 (diff)
downloadpleroma-72480e7b2fc19beaa8a0a524e8b1c83442debd01.tar.gz
pleroma-72480e7b2fc19beaa8a0a524e8b1c83442debd01.zip
Merge branch 'rich-media-tests' into 'develop'
Pleroma.Web.RichMedia.Parser: Remove test-specific codepaths See merge request pleroma/pleroma!4053
Diffstat (limited to 'test/support/http_request_mock.ex')
-rw-r--r--test/support/http_request_mock.ex61
1 files changed, 58 insertions, 3 deletions
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index df3371a75..f4b6f1f9f 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -1059,7 +1059,7 @@ defmodule HttpRequestMock do
}}
end
- def get("http://example.com/malformed", _, _, _) do
+ def get("https://example.com/malformed", _, _, _) do
{:ok,
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
end
@@ -1472,6 +1472,37 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/yahoo.html")}}
end
+ def get("https://example.com/error", _, _, _), do: {:error, :overload}
+
+ def get("https://example.com/ogp-missing-title", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/rich_media/ogp-missing-title.html")
+ }}
+ end
+
+ def get("https://example.com/oembed", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.html")}}
+ end
+
+ def get("https://example.com/oembed.json", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.json")}}
+ end
+
+ def get("https://example.com/twitter-card", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")}}
+ end
+
+ def get("https://example.com/non-ogp", _, _, _) do
+ {:ok,
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/non_ogp_embed.html")}}
+ end
+
+ def get("https://example.com/empty", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: "hello"}}
+ end
+
def get(url, query, body, headers) do
{:error,
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
@@ -1545,17 +1576,41 @@ defmodule HttpRequestMock do
# Most of the rich media mocks are missing HEAD requests, so we just return 404.
@rich_media_mocks [
+ "https://example.com/empty",
+ "https://example.com/error",
+ "https://example.com/malformed",
+ "https://example.com/non-ogp",
+ "https://example.com/oembed",
+ "https://example.com/oembed.json",
"https://example.com/ogp",
"https://example.com/ogp-missing-data",
+ "https://example.com/ogp-missing-title",
"https://example.com/twitter-card",
"https://google.com/",
- "https://yahoo.com/",
- "https://pleroma.local/notice/9kCP7V"
+ "https://pleroma.local/notice/9kCP7V",
+ "https://yahoo.com/"
]
+
def head(url, _query, _body, _headers) when url in @rich_media_mocks do
{:ok, %Tesla.Env{status: 404, body: ""}}
end
+ def head("https://example.com/pdf-file", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-length", "1000000"}, {"content-type", "application/pdf"}]
+ }}
+ end
+
+ def head("https://example.com/huge-page", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-length", "2000001"}, {"content-type", "text/html"}]
+ }}
+ end
+
def head(url, query, body, headers) do
{:error,
"Mock response not implemented for HEAD #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}