aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/config_test.exs39
-rw-r--r--test/web/activity_pub/activity_pub_controller_test.exs12
-rw-r--r--test/web/federator_test.exs12
3 files changed, 43 insertions, 20 deletions
diff --git a/test/config_test.exs b/test/config_test.exs
new file mode 100644
index 000000000..32d5cc90c
--- /dev/null
+++ b/test/config_test.exs
@@ -0,0 +1,39 @@
+defmodule Pleroma.ConfigTest do
+ use ExUnit.Case
+
+ test "get/1 with an atom" do
+ assert Pleroma.Config.get(:instance) == Application.get_env(:pleroma, :instance)
+ assert Pleroma.Config.get(:azertyuiop) == nil
+ end
+
+ test "get/1 with a list of keys" do
+ assert Pleroma.Config.get([:instance, :public]) ==
+ Keyword.get(Application.get_env(:pleroma, :instance), :public)
+
+ assert Pleroma.Config.get([Pleroma.Web.Endpoint, :render_errors, :view]) ==
+ get_in(
+ Application.get_env(
+ :pleroma,
+ Pleroma.Web.Endpoint
+ ),
+ [:render_errors, :view]
+ )
+
+ assert Pleroma.Config.get([:azerty, :uiop]) == nil
+ end
+
+ test "put/2 with a key" do
+ Pleroma.Config.put(:config_test, true)
+
+ assert Pleroma.Config.get(:config_test) == true
+ end
+
+ test "put/2 with a list of keys" do
+ Pleroma.Config.put([:instance, :config_test], true)
+ Pleroma.Config.put([:instance, :config_nested_test], [])
+ Pleroma.Config.put([:instance, :config_nested_test, :x], true)
+
+ assert Pleroma.Config.get([:instance, :config_test]) == true
+ assert Pleroma.Config.get([:instance, :config_nested_test, :x]) == true
+ end
+end
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index f22975f86..1c24b348c 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -16,22 +16,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
test "with the relay disabled, it returns 404", %{conn: conn} do
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:allow_relay, false)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :allow_relay], false)
res =
conn
|> get(activity_pub_path(conn, :relay))
|> json_response(404)
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:allow_relay, true)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :allow_relay], true)
end
end
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 88aef0d0f..c709d1181 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -50,11 +50,7 @@ defmodule Pleroma.Web.FederatorTest do
activity: activity,
relay_mock: relay_mock
} do
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:allow_relay, false)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :allow_relay], false)
with_mocks([relay_mock]) do
Federator.handle(:publish, activity)
@@ -62,11 +58,7 @@ defmodule Pleroma.Web.FederatorTest do
refute_received :relay_publish
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:allow_relay, true)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :allow_relay], true)
end
end
end