summaryrefslogtreecommitdiff
path: root/test/support
diff options
context:
space:
mode:
Diffstat (limited to 'test/support')
-rw-r--r--test/support/builders/activity_builder.ex4
-rw-r--r--test/support/factory.ex16
-rw-r--r--test/support/httpoison_mock.ex125
3 files changed, 141 insertions, 4 deletions
diff --git a/test/support/builders/activity_builder.ex b/test/support/builders/activity_builder.ex
index 0f9cd0d15..16011edbf 100644
--- a/test/support/builders/activity_builder.ex
+++ b/test/support/builders/activity_builder.ex
@@ -5,7 +5,7 @@ defmodule Pleroma.Builders.ActivityBuilder do
def build(data \\ %{}, opts \\ %{}) do
user = opts[:user] || Pleroma.Factory.insert(:user)
activity = %{
- "id" => 1,
+ "id" => Pleroma.Web.ActivityPub.ActivityPub.generate_object_id,
"actor" => user.ap_id,
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"object" => %{
@@ -23,7 +23,7 @@ defmodule Pleroma.Builders.ActivityBuilder do
def insert_list(times, data \\ %{}, opts \\ %{}) do
Enum.map(1..times, fn (n) ->
- {:ok, activity} = insert(Map.merge(data, %{"id" => n}))
+ {:ok, activity} = insert(data)
activity
end)
end
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 1662d4cd6..5c110c72d 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -24,7 +24,8 @@ defmodule Pleroma.Factory do
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601,
"likes" => [],
- "like_count" => 0
+ "like_count" => 0,
+ "context" => "2hu"
}
%Pleroma.Object{
@@ -40,7 +41,8 @@ defmodule Pleroma.Factory do
"actor" => note.data["actor"],
"to" => note.data["to"],
"object" => note.data,
- "published_at" => DateTime.utc_now() |> DateTime.to_iso8601
+ "published_at" => DateTime.utc_now() |> DateTime.to_iso8601,
+ "context" => note.data["context"]
}
%Pleroma.Activity{
@@ -91,4 +93,14 @@ defmodule Pleroma.Factory do
state: "requested"
}
end
+
+ def websub_client_subscription_factory do
+ %Pleroma.Web.Websub.WebsubClientSubscription{
+ topic: "http://example.org",
+ secret: "here's a secret",
+ valid_until: nil,
+ state: "requested",
+ subscribers: []
+ }
+ end
end
diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex
new file mode 100644
index 000000000..733abced2
--- /dev/null
+++ b/test/support/httpoison_mock.ex
@@ -0,0 +1,125 @@
+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
+
+ 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
+
+ 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
+
+ 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
+
+ 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
+
+ def get(url, body, headers) do
+ {:error, "Not implemented the mock response for get #{inspect(url)}"}
+ end
+
+ def post(url, body, headers) do
+ {:error, "Not implemented the mock response for post #{inspect(url)}"}
+ end
+end