X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Fpleroma%2Fweb%2Fpleroma_api%2Fcontrollers%2Femoji_pack_controller_test.exs;h=d1ba067b8eebb9d69485118db402b77277fb1966;hb=842ab82ef08e005cbb88aa0e1ef48cf130402fc0;hp=151f69cde7f7d4a65e29c5aa5a8ef429df3012b1;hpb=36ec6045214a69cd958c00eb6d37852fff1c7d08;p=akkoma
diff --git a/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs
index 151f69cde..d1ba067b8 100644
--- a/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs
@@ -1,10 +1,11 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
use Pleroma.Web.ConnCase, async: false
+ import Mock
import Tesla.Mock
import Pleroma.Factory
@@ -12,7 +13,6 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
Pleroma.Config.get!([:instance, :static_dir]),
"emoji"
)
- setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
setup do: clear_config([:instance, :public], true)
@@ -30,7 +30,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
end
test "GET /api/pleroma/emoji/packs when :public: false", %{conn: conn} do
- Config.put([:instance, :public], false)
+ clear_config([:instance, :public], false)
conn |> get("/api/pleroma/emoji/packs") |> json_response_and_validate_schema(200)
end
@@ -366,11 +366,9 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
end
test "returns error when file system not writable", %{admin_conn: conn} = ctx do
- {:ok, %File.Stat{mode: mode}} = File.stat(@emoji_path)
-
- try do
- File.chmod!(@emoji_path, 0o400)
-
+ with_mocks([
+ {File, [:passthrough], [stat: fn _ -> {:error, :eacces} end]}
+ ]) do
assert conn
|> put_req_header("content-type", "multipart/form-data")
|> patch(
@@ -378,8 +376,6 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
%{"metadata" => ctx[:new_data]}
)
|> json_response_and_validate_schema(500)
- after
- File.chmod!(@emoji_path, mode)
end
end
@@ -442,40 +438,43 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
end
describe "POST/DELETE /api/pleroma/emoji/pack?name=:name" do
- test "returns error when file system not writable", %{admin_conn: admin_conn} do
- {:ok, %File.Stat{mode: mode}} = File.stat(@emoji_path)
-
- try do
- File.chmod!(@emoji_path, 0o400)
+ test "returns an error on creates pack when file system not writable", %{
+ admin_conn: admin_conn
+ } do
+ path_pack = Path.join(@emoji_path, "test_pack")
+ with_mocks([
+ {File, [:passthrough], [mkdir: fn ^path_pack -> {:error, :eacces} end]}
+ ]) do
assert admin_conn
|> post("/api/pleroma/emoji/pack?name=test_pack")
|> json_response_and_validate_schema(500) == %{
"error" =>
"Unexpected error occurred while creating pack. (POSIX error: Permission denied)"
}
- after
- File.chmod!(@emoji_path, mode)
end
end
test "returns an error on deletes pack when the file system is not writable", %{
admin_conn: admin_conn
} do
- {:ok, _pack} = Pleroma.Emoji.Pack.create("test_pack2")
- {:ok, %File.Stat{mode: mode}} = File.stat(@emoji_path)
+ path_pack = Path.join(@emoji_path, "test_emoji_pack")
try do
- File.chmod!(@emoji_path, 0o400)
-
- assert admin_conn
- |> delete("/api/pleroma/emoji/pack?name=test_pack")
- |> json_response_and_validate_schema(500) == %{
- "error" => "Couldn't delete the pack test_pack (POSIX error: Permission denied)"
- }
+ {:ok, _pack} = Pleroma.Emoji.Pack.create("test_emoji_pack")
+
+ with_mocks([
+ {File, [:passthrough], [rm_rf: fn ^path_pack -> {:error, :eacces, path_pack} end]}
+ ]) do
+ assert admin_conn
+ |> delete("/api/pleroma/emoji/pack?name=test_emoji_pack")
+ |> json_response_and_validate_schema(500) == %{
+ "error" =>
+ "Couldn't delete the `test_emoji_pack` pack (POSIX error: Permission denied)"
+ }
+ end
after
- File.chmod!(@emoji_path, mode)
- File.rm_rf!(Path.join([@emoji_path, "test_pack2"]))
+ File.rm_rf(path_pack)
end
end