diff options
| author | lain <lain@soykaf.club> | 2020-04-06 17:50:31 +0200 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-04-06 17:50:31 +0200 | 
| commit | 19335be24c25739e2334180af6c59dd8919d5fc8 (patch) | |
| tree | db34531b2dd5befb495d4379aa8aaad9284fa72c /test/support | |
| parent | fd97b0e634d30dec3217efcf3d67610d1b54bf8b (diff) | |
| parent | 1d4ab06505ec5143dbb1d78d718fa9efd1497751 (diff) | |
| download | pleroma-19335be24c25739e2334180af6c59dd8919d5fc8.tar.gz pleroma-19335be24c25739e2334180af6c59dd8919d5fc8.zip | |
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
Diffstat (limited to 'test/support')
| -rw-r--r-- | test/support/helpers.ex | 36 | ||||
| -rw-r--r-- | test/support/http_request_mock.ex | 109 | 
2 files changed, 75 insertions, 70 deletions
| diff --git a/test/support/helpers.ex b/test/support/helpers.ex index 6bf4b019e..e68e9bfd2 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -17,35 +17,17 @@ defmodule Pleroma.Tests.Helpers do    defmacro clear_config(config_path, do: yield) do      quote do -      setup do -        initial_setting = Config.get(unquote(config_path)) -        unquote(yield) -        on_exit(fn -> Config.put(unquote(config_path), initial_setting) end) -        :ok -      end -    end -  end - -  @doc "Stores initial config value and restores it after *all* test examples are executed." -  defmacro clear_config_all(config_path) do -    quote do -      clear_config_all(unquote(config_path)) do -      end +      initial_setting = Config.get(unquote(config_path)) +      unquote(yield) +      on_exit(fn -> Config.put(unquote(config_path), initial_setting) end) +      :ok      end    end -  @doc """ -  Stores initial config value and restores it after *all* test examples are executed. -  Only use if *all* test examples should work with the same stubbed value -  (*no* examples set a different value). -  """ -  defmacro clear_config_all(config_path, do: yield) do +  defmacro clear_config(config_path, temp_setting) do      quote do -      setup_all do -        initial_setting = Config.get(unquote(config_path)) -        unquote(yield) -        on_exit(fn -> Config.put(unquote(config_path), initial_setting) end) -        :ok +      clear_config(unquote(config_path)) do +        Config.put(unquote(config_path), unquote(temp_setting))        end      end    end @@ -55,9 +37,7 @@ defmodule Pleroma.Tests.Helpers do        import Pleroma.Tests.Helpers,          only: [            clear_config: 1, -          clear_config: 2, -          clear_config_all: 1, -          clear_config_all: 2 +          clear_config: 2          ]        def to_datetime(naive_datetime) do diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index e72638814..20cb2b3d1 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -107,7 +107,7 @@ defmodule HttpRequestMock do          "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -120,7 +120,7 @@ defmodule HttpRequestMock do          "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -141,7 +141,7 @@ defmodule HttpRequestMock do          "https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -167,7 +167,7 @@ defmodule HttpRequestMock do          "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -188,7 +188,7 @@ defmodule HttpRequestMock do          "https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -201,7 +201,7 @@ defmodule HttpRequestMock do          "https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -214,7 +214,7 @@ defmodule HttpRequestMock do          "https://squeet.me/xrd/?uri=lain@squeet.me",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -227,7 +227,7 @@ defmodule HttpRequestMock do          "https://mst3k.interlinked.me/users/luciferMysticus",          _,          _, -        Accept: "application/activity+json" +        [{"accept", "application/activity+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -248,7 +248,7 @@ defmodule HttpRequestMock do          "https://hubzilla.example.org/channel/kaniini",          _,          _, -        Accept: "application/activity+json" +        [{"accept", "application/activity+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -257,7 +257,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, @@ -265,7 +265,7 @@ defmodule HttpRequestMock do       }}    end -  def get("https://n1u.moe/users/rye", _, _, Accept: "application/activity+json") do +  def get("https://n1u.moe/users/rye", _, _, [{"accept", "application/activity+json"}]) do      {:ok,       %Tesla.Env{         status: 200, @@ -284,7 +284,7 @@ defmodule HttpRequestMock do       }}    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, @@ -308,9 +308,9 @@ defmodule HttpRequestMock do       }}    end -  def get("https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39", _, _, -        Accept: "application/activity+json" -      ) do +  def get("https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39", _, _, [ +        {"accept", "application/activity+json"} +      ]) do      {:ok,       %Tesla.Env{         status: 200, @@ -318,7 +318,7 @@ defmodule HttpRequestMock do       }}    end -  def get("https://mobilizon.org/@tcit", _, _, Accept: "application/activity+json") do +  def get("https://mobilizon.org/@tcit", _, _, [{"accept", "application/activity+json"}]) do      {:ok,       %Tesla.Env{         status: 200, @@ -358,7 +358,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", _, _, _) do      {:ok,       %Tesla.Env{         status: 200, @@ -366,7 +366,9 @@ defmodule HttpRequestMock do       }}    end -  def get("http://mastodon.example.org/users/relay", _, _, Accept: "application/activity+json") do +  def get("http://mastodon.example.org/users/relay", _, _, [ +        {"accept", "application/activity+json"} +      ]) do      {:ok,       %Tesla.Env{         status: 200, @@ -374,7 +376,9 @@ defmodule HttpRequestMock do       }}    end -  def get("http://mastodon.example.org/users/gargron", _, _, Accept: "application/activity+json") do +  def get("http://mastodon.example.org/users/gargron", _, _, [ +        {"accept", "application/activity+json"} +      ]) do      {:error, :nxdomain}    end @@ -557,7 +561,7 @@ defmodule HttpRequestMock do          "http://mastodon.example.org/@admin/99541947525187367",          _,          _, -        Accept: "application/activity+json" +        _        ) do      {:ok,       %Tesla.Env{ @@ -582,7 +586,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, @@ -594,7 +598,7 @@ defmodule HttpRequestMock do          "https://mstdn.io/users/mayuutann/statuses/99568293732299394",          _,          _, -        Accept: "application/activity+json" +        [{"accept", "application/activity+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -614,7 +618,7 @@ defmodule HttpRequestMock do       }}    end -  def get(url, _, _, Accept: "application/xrd+xml,application/jrd+json") +  def get(url, _, _, [{"accept", "application/xrd+xml,application/jrd+json"}])        when url in [               "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",               "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain" @@ -641,7 +645,7 @@ defmodule HttpRequestMock do          "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -685,7 +689,7 @@ defmodule HttpRequestMock do          "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -738,7 +742,7 @@ defmodule HttpRequestMock do          "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -751,7 +755,7 @@ defmodule HttpRequestMock do          "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",          _,          _, -        Accept: "application/atom+xml" +        [{"accept", "application/atom+xml"}]        ) do      {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}    end @@ -768,7 +772,7 @@ defmodule HttpRequestMock do          "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -790,7 +794,7 @@ defmodule HttpRequestMock do          "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -804,7 +808,7 @@ defmodule HttpRequestMock do          "http://gs.example.org:4040/index.php/user/1",          _,          _, -        Accept: "application/activity+json" +        [{"accept", "application/activity+json"}]        ) do      {:ok, %Tesla.Env{status: 406, body: ""}}    end @@ -840,7 +844,7 @@ defmodule HttpRequestMock do          "https://squeet.me/xrd?uri=lain@squeet.me",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -853,7 +857,7 @@ defmodule HttpRequestMock do          "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -866,7 +870,7 @@ defmodule HttpRequestMock do          "https://social.heldscal.la/.well-known/webfinger?resource=invalid_content@social.heldscal.la",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok, %Tesla.Env{status: 200, body: ""}}    end @@ -883,7 +887,7 @@ defmodule HttpRequestMock do          "http://framatube.org/main/xrd?uri=framasoft@framatube.org",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -905,7 +909,7 @@ defmodule HttpRequestMock do          "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -942,7 +946,7 @@ defmodule HttpRequestMock do          "https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -1005,7 +1009,7 @@ defmodule HttpRequestMock do       %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json")}}    end -  def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do +  def get("https://social.heldscal.la/user/23211", _, _, [{"accept", "application/activity+json"}]) do      {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}    end @@ -1138,7 +1142,7 @@ defmodule HttpRequestMock do          "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=lain@zetsubou.xn--q9jyb4c",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -1151,7 +1155,7 @@ defmodule HttpRequestMock do          "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=https://zetsubou.xn--q9jyb4c/users/lain",          _,          _, -        Accept: "application/xrd+xml,application/jrd+json" +        [{"accept", "application/xrd+xml,application/jrd+json"}]        ) do      {:ok,       %Tesla.Env{ @@ -1173,7 +1177,9 @@ defmodule HttpRequestMock do       }}    end -  def get("https://info.pleroma.site/activity.json", _, _, Accept: "application/activity+json") do +  def get("https://info.pleroma.site/activity.json", _, _, [ +        {"accept", "application/activity+json"} +      ]) do      {:ok,       %Tesla.Env{         status: 200, @@ -1185,7 +1191,9 @@ defmodule HttpRequestMock do      {:ok, %Tesla.Env{status: 404, body: ""}}    end -  def get("https://info.pleroma.site/activity2.json", _, _, Accept: "application/activity+json") do +  def get("https://info.pleroma.site/activity2.json", _, _, [ +        {"accept", "application/activity+json"} +      ]) do      {:ok,       %Tesla.Env{         status: 200, @@ -1197,7 +1205,9 @@ defmodule HttpRequestMock do      {:ok, %Tesla.Env{status: 404, body: ""}}    end -  def get("https://info.pleroma.site/activity3.json", _, _, Accept: "application/activity+json") do +  def get("https://info.pleroma.site/activity3.json", _, _, [ +        {"accept", "application/activity+json"} +      ]) do      {:ok,       %Tesla.Env{         status: 200, @@ -1273,6 +1283,21 @@ defmodule HttpRequestMock do      {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}}    end +  def get( +        "https://channels.tests.funkwhale.audio/federation/music/uploads/42342395-0208-4fee-a38d-259a6dae0871", +        _, +        _, +        _ +      ) do +    {:ok, +     %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/funkwhale_audio.json")}} +  end + +  def get("https://channels.tests.funkwhale.audio/federation/actors/compositions", _, _, _) do +    {:ok, +     %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json")}} +  end +    def get("http://example.com/rel_me/error", _, _, _) do      {:ok, %Tesla.Env{status: 404, body: ""}}    end | 
