Testing: Don't federate in testing.
authorlain <lain@soykaf.club>
Tue, 9 Jul 2019 06:30:51 +0000 (15:30 +0900)
committerlain <lain@soykaf.club>
Tue, 9 Jul 2019 06:30:51 +0000 (15:30 +0900)
config/test.exs
lib/pleroma/web/activity_pub/utils.ex
test/conversation_test.exs
test/web/activity_pub/activity_pub_controller_test.exs
test/web/federator_test.exs
test/web/ostatus/ostatus_controller_test.exs
test/web/plugs/federating_plug_test.exs
test/web/web_finger/web_finger_controller_test.exs
test/web/websub/websub_controller_test.exs

index 9d441a7f5e5123ebb80af51eca4544dcd3116d23..012021f2a137269feb71b08624388a825f3946cd 100644 (file)
@@ -28,7 +28,8 @@ config :pleroma, Pleroma.Emails.Mailer, adapter: Swoosh.Adapters.Test
 config :pleroma, :instance,
   email: "admin@example.com",
   notify_email: "noreply@example.com",
-  skip_thread_containment: false
+  skip_thread_containment: false,
+  federating: false
 
 # Configure your database
 config :pleroma, Pleroma.Repo,
index 514266ceefaa314484dbf9d840a51a1525195725..4288ea4c838a8cf291394663291246bea3d7c9bd 100644 (file)
@@ -170,14 +170,17 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   Enqueues an activity for federation if it's local
   """
   def maybe_federate(%Activity{local: true} = activity) do
-    priority =
-      case activity.data["type"] do
-        "Delete" -> 10
-        "Create" -> 1
-        _ -> 5
-      end
+    if Pleroma.Config.get!([:instance, :federating]) do
+      priority =
+        case activity.data["type"] do
+          "Delete" -> 10
+          "Create" -> 1
+          _ -> 5
+        end
+
+      Pleroma.Web.Federator.publish(activity, priority)
+    end
 
-    Pleroma.Web.Federator.publish(activity, priority)
     :ok
   end
 
index 5903d10ff05b1ffd94b4d4594952a1b393283b6f..aa193e0d40dadf907f974ef2cfa378ee7788844e 100644 (file)
@@ -11,6 +11,16 @@ defmodule Pleroma.ConversationTest do
 
   import Pleroma.Factory
 
+  setup_all do
+    config_path = [:instance, :federating]
+    initial_setting = Pleroma.Config.get(config_path)
+
+    Pleroma.Config.put(config_path, true)
+    on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
+
+    :ok
+  end
+
   test "it goes through old direct conversations" do
     user = insert(:user)
     other_user = insert(:user)
index 8b323372954bf9be125ac1658631a39c02fe2183..5a8a671552f18cf9bc218e4da47791e613ae49f3 100644 (file)
@@ -15,6 +15,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
 
   setup_all do
     Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
+    config_path = [:instance, :federating]
+    initial_setting = Pleroma.Config.get(config_path)
+
+    Pleroma.Config.put(config_path, true)
+    on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
+
     :ok
   end
 
index 0f43bc8f24e6d93c3857a9b265a66b80fcc365fc..69dd4d7473c4df10d78e638bb22537db48f03c0b 100644 (file)
@@ -12,6 +12,13 @@ defmodule Pleroma.Web.FederatorTest do
 
   setup_all do
     Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
+    config_path = [:instance, :federating]
+    initial_setting = Pleroma.Config.get(config_path)
+
+    Pleroma.Config.put(config_path, true)
+    on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
+
     :ok
   end
 
index 7441e5fce9d5ab87ee10651750c96eed68e4d785..eae44dba5125e734841e96a8f0f865d369c58a74 100644 (file)
@@ -12,6 +12,13 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
 
   setup_all do
     Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
+    config_path = [:instance, :federating]
+    initial_setting = Pleroma.Config.get(config_path)
+
+    Pleroma.Config.put(config_path, true)
+    on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
+
     :ok
   end
 
index 530562325f7a99664c48d6d2cfc9879448505987..c01e0112460b38397c8c554cae5e50117b694015 100644 (file)
@@ -5,6 +5,15 @@
 defmodule Pleroma.Web.FederatingPlugTest do
   use Pleroma.Web.ConnCase
 
+  setup_all do
+    config_path = [:instance, :federating]
+    initial_setting = Pleroma.Config.get(config_path)
+
+    on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
+
+    :ok
+  end
+
   test "returns and halt the conn when federating is disabled" do
     Pleroma.Config.put([:instance, :federating], false)
 
@@ -14,11 +23,11 @@ defmodule Pleroma.Web.FederatingPlugTest do
 
     assert conn.status == 404
     assert conn.halted
-
-    Pleroma.Config.put([:instance, :federating], true)
   end
 
   test "does nothing when federating is enabled" do
+    Pleroma.Config.put([:instance, :federating], true)
+
     conn =
       build_conn()
       |> Pleroma.Web.FederatingPlug.call(%{})
index 43fccfc7ab5241f948027589d807d9b66c821a94..a14ed3126d43395e298b95df87125ef79574e333 100644 (file)
@@ -10,6 +10,12 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
 
   setup do
     mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
+    config_path = [:instance, :federating]
+    initial_setting = Pleroma.Config.get(config_path)
+
+    Pleroma.Config.put(config_path, true)
+    on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
     :ok
   end
 
index f79745d58ce340dd0691beafe84bf5f033e05d34..aa7262beb1eb3c6d2a0cec2dabdead769e2523c2 100644 (file)
@@ -9,6 +9,16 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
   alias Pleroma.Web.Websub
   alias Pleroma.Web.Websub.WebsubClientSubscription
 
+  setup_all do
+    config_path = [:instance, :federating]
+    initial_setting = Pleroma.Config.get(config_path)
+
+    Pleroma.Config.put(config_path, true)
+    on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
+
+    :ok
+  end
+
   test "websub subscription request", %{conn: conn} do
     user = insert(:user)