From 7ec64ac33f52d2f5072b56f2f8eb5e9ce498e00f Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Mon, 3 Dec 2018 21:37:55 +0300 Subject: [PATCH] update test --- test/support/http_request_mock.ex | 61 ++++++++++++++----- test/web/http_sigs/http_sig_test.exs | 6 ++ .../mastodon_api_controller_test.exs | 6 ++ test/web/mastodon_api/status_view_test.exs | 6 ++ .../web/ostatus/activity_representer_test.exs | 6 ++ test/web/ostatus/ostatus_controller_test.exs | 6 ++ 6 files changed, 75 insertions(+), 16 deletions(-) diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index 4a4566e84..f44e9a1c6 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -23,6 +23,34 @@ defmodule HttpRequestMock do # def get(url, query \\ [], body \\ [], headers \\ []) + def get("http://gs.example.org:4040/index.php/user/1", _, _, Accept: "application/activity+json") do + {:ok, + %Tesla.Env{ + status: 200, + body: "{\"id\": 1}" + }} + end + + def get("https://squeet.me/xrd/?uri=lain@squeet.me", _, _, + Accept: "application/xrd+xml,application/jrd+json" + ) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml") + }} + end + + def get("https://mst3k.interlinked.me/users/luciferMysticus", _, _, + Accept: "application/activity+json" + ) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/httpoison_mock/lucifermysticus.json") + }} + end + def get("https://prismo.news/@mxb", _, _, _) do {:ok, %Tesla.Env{ @@ -31,8 +59,9 @@ defmodule HttpRequestMock do }} end - def get("https://hubzilla.example.org/channel/kaniini", - _, _, [Accept: "application/activity+json"]) do + def get("https://hubzilla.example.org/channel/kaniini", _, _, + Accept: "application/activity+json" + ) do {:ok, %Tesla.Env{ status: 200, @@ -40,7 +69,7 @@ defmodule HttpRequestMock do }} end - def get("https://niu.moe/users/rye", _, _, [Accept: "application/activity+json"]) do + def get("https://niu.moe/users/rye", _, _, Accept: "application/activity+json") do {:ok, %Tesla.Env{ status: 200, @@ -52,13 +81,14 @@ defmodule HttpRequestMock do {:ok, %Tesla.Env{ status: 200, - body: File.read!( - "test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json" - ) + body: + File.read!( + "test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json" + ) }} end - def get("https://puckipedia.com/", _, _, [Accept: "application/activity+json"]) do + def get("https://puckipedia.com/", _, _, Accept: "application/activity+json") do {:ok, %Tesla.Env{ status: 200, @@ -66,7 +96,6 @@ defmodule HttpRequestMock do }} end - def get("https://peertube.moe/accounts/7even", _, _, _) do {:ok, %Tesla.Env{ @@ -99,8 +128,7 @@ defmodule HttpRequestMock do }} end - - def get("http://mastodon.example.org/users/admin", _, _, [Accept: "application/activity+json"]) do + def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do {:ok, %Tesla.Env{ status: 200, @@ -108,8 +136,9 @@ defmodule HttpRequestMock do }} end - def get("http://mastodon.example.org/@admin/99541947525187367", - _, _, [Accept: "application/activity+json"]) do + def get("http://mastodon.example.org/@admin/99541947525187367", _, _, + Accept: "application/activity+json" + ) do {:ok, %Tesla.Env{ status: 200, @@ -125,7 +154,7 @@ defmodule HttpRequestMock do }} end - def get("https://mstdn.io/users/mayuutann", _, _, [Accept: "application/activity+json"]) do + def get("https://mstdn.io/users/mayuutann", _, _, Accept: "application/activity+json") do {:ok, %Tesla.Env{ status: 200, @@ -133,8 +162,9 @@ defmodule HttpRequestMock do }} end - def get("https://mstdn.io/users/mayuutann/statuses/99568293732299394", - _, _, [Accept: "application/activity+json"]) do + def get("https://mstdn.io/users/mayuutann/statuses/99568293732299394", _, _, + Accept: "application/activity+json" + ) do {:ok, %Tesla.Env{ status: 200, @@ -142,7 +172,6 @@ defmodule HttpRequestMock do }} end - def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do {:ok, %Tesla.Env{ diff --git a/test/web/http_sigs/http_sig_test.exs b/test/web/http_sigs/http_sig_test.exs index b2bf8d61b..2e189d583 100644 --- a/test/web/http_sigs/http_sig_test.exs +++ b/test/web/http_sigs/http_sig_test.exs @@ -4,6 +4,12 @@ defmodule Pleroma.Web.HTTPSignaturesTest do use Pleroma.DataCase alias Pleroma.Web.HTTPSignatures import Pleroma.Factory + import Tesla.Mock + + setup do + mock(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end @private_key hd(:public_key.pem_decode(File.read!("test/web/http_sigs/priv.key"))) |> :public_key.pem_entry_decode() diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 098acb59f..7cd98cde8 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -8,6 +8,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do import Pleroma.Factory import ExUnit.CaptureLog + import Tesla.Mock + + setup do + mock(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end test "the home timeline", %{conn: conn} do user = insert(:user) diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 31554a07d..9e69b3189 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -6,6 +6,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do alias Pleroma.Web.OStatus alias Pleroma.Web.CommonAPI import Pleroma.Factory + import Tesla.Mock + + setup do + mock(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end test "a note with null content" do note = insert(:note_activity) diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs index 8bf3bc775..a351510d8 100644 --- a/test/web/ostatus/activity_representer_test.exs +++ b/test/web/ostatus/activity_representer_test.exs @@ -7,6 +7,12 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do alias Pleroma.Web.OStatus import Pleroma.Factory + import Tesla.Mock + + setup do + mock(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end test "an external note activity" do incoming = File.read!("test/fixtures/mastodon-note-cw.xml") diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index e81adde68..6327a524e 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -4,6 +4,12 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do alias Pleroma.{User, Repo} alias Pleroma.Web.CommonAPI alias Pleroma.Web.OStatus.ActivityRepresenter + import Tesla.Mock + + setup do + mock(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end test "decodes a salmon", %{conn: conn} do user = insert(:user) -- 2.45.2