update test
authorMaksim Pechnikov <parallel588@gmail.com>
Tue, 4 Dec 2018 11:01:39 +0000 (14:01 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Tue, 4 Dec 2018 11:04:06 +0000 (14:04 +0300)
lib/pleroma/http/http.ex
test/formatter_test.exs
test/support/http_request_mock.ex
test/user_test.exs
test/web/activity_pub/transmogrifier_test.exs
test/web/ostatus/ostatus_controller_test.exs
test/web/ostatus/ostatus_test.exs

index 93ac9d62bc8247d426a2747f6af907e296ec0c6e..59afacf4cd54c5fc4659b6e9307dd111dcb4fd8b 100644 (file)
@@ -18,6 +18,7 @@ defmodule Pleroma.HTTP do
     |> (&Tesla.request(Connection.new(), &1)).()
   end
 
+  defp process_sni_options(options, nil), do: options
   defp process_sni_options(options, url) do
     uri = URI.parse(url)
     host = uri.host |> to_charlist()
index e4da84c101ad9bc7d7ae9dba3c055405bf81662f..d5c74a321eeb165341975b944fb20ef819af4adf 100644 (file)
@@ -4,6 +4,10 @@ defmodule Pleroma.FormatterTest do
   use Pleroma.DataCase
 
   import Pleroma.Factory
+  setup_all do
+    Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+    :ok
+  end
 
   describe ".add_hashtag_links" do
     test "turns hashtags into links" do
index f44e9a1c686dc8ba352d8e653a17df1adc0fb486..80b84d59137de7b369bc4176bb76aa0e98b989c1 100644 (file)
@@ -22,6 +22,73 @@ defmodule HttpRequestMock do
   # GET Requests
   #
   def get(url, query \\ [], body \\ [], headers \\ [])
+  def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
+    _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
+     }}
+  end
+
+  def get("https://pawoo.net/users/pekorino.atom", _, _, _) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom")
+     }}
+  end
+
+  def get("https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
+    _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
+     }}
+  end
+
+  def get("https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom", _, _, _) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/atarifrosch_feed.xml")
+     }}
+  end
+
+  def get("https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
+    _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/atarifrosch_webfinger.xml")
+     }}
+  end
+
+  def get("https://mamot.fr/users/Skruyb.atom", _, _, _) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom")
+     }}
+  end
+
+  def get("https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb",
+    _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
+     }}
+  end
+
+  def get("https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la", _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
+     }}
+  end
 
   def get("http://gs.example.org:4040/index.php/user/1", _, _, Accept: "application/activity+json") do
     {:ok,
index 62104df90501a099488f8ef9812733ede9c28e53..d097eb17128c6cb13605df393d472c304a983fe5 100644 (file)
@@ -9,6 +9,11 @@ defmodule Pleroma.UserTest do
   import Pleroma.Factory
   import Ecto.Query
 
+  setup_all do
+    Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+    :ok
+  end
+
   test "ap_id returns the activity pub id for the user" do
     user = UserBuilder.build()
 
index faba80354c0c3c9b8a58ee694e91958d3f76d9f3..eeb0cb5cf8291c400783cd7dcbdd8b3bdd63a259 100644 (file)
@@ -11,11 +11,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
 
   import Pleroma.Factory
   alias Pleroma.Web.CommonAPI
-
-  import Tesla.Mock
-
-  setup do
-    mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+  setup_all do
+    Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
     :ok
   end
 
index 6327a524ea253c1bd85297943c5c988fccf39597..411e89e943488bc8eb1cb3927f627e520b38b417 100644 (file)
@@ -4,10 +4,9 @@ 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)
+  setup_all do
+    Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
     :ok
   end
 
index 83525456b19c74e09968c7d70cfe31d45f1a760e..f3268e83d975448f1edbdd416df07d9fe226fe9b 100644 (file)
@@ -5,10 +5,9 @@ defmodule Pleroma.Web.OStatusTest do
   alias Pleroma.{Object, Repo, User, Activity}
   import Pleroma.Factory
   import ExUnit.CaptureLog
-  import Tesla.Mock
 
-  setup do
-    mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+  setup_all do
+    Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
     :ok
   end