setup do: clear_config([:instance, :cleanup_attachments])
test "Disabled via config" do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
- Pleroma.Config.put([:instance, :cleanup_attachments], false)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([:instance, :cleanup_attachments], false)
file = %Plug.Upload{
content_type: "image/jpeg",
end
test "in subdirectories" do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
- Pleroma.Config.put([:instance, :cleanup_attachments], true)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([:instance, :cleanup_attachments], true)
file = %Plug.Upload{
content_type: "image/jpeg",
end
test "with dedupe enabled" do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
- Pleroma.Config.put([Pleroma.Upload, :filters], [Pleroma.Upload.Filter.Dedupe])
- Pleroma.Config.put([:instance, :cleanup_attachments], true)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([Pleroma.Upload, :filters], [Pleroma.Upload.Filter.Dedupe])
+ clear_config([:instance, :cleanup_attachments], true)
uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads])
end
test "with objects that have legacy data.url attribute" do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
- Pleroma.Config.put([:instance, :cleanup_attachments], true)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([:instance, :cleanup_attachments], true)
file = %Plug.Upload{
content_type: "image/jpeg",
end
test "With custom base_url" do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
- Pleroma.Config.put([Pleroma.Upload, :base_url], "https://sub.domain.tld/dir/")
- Pleroma.Config.put([:instance, :cleanup_attachments], true)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([Pleroma.Upload, :base_url], "https://sub.domain.tld/dir/")
+ clear_config([:instance, :cleanup_attachments], true)
file = %Plug.Upload{
content_type: "image/jpeg",
setup do
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
-
- clear_config(Pleroma.Uploaders.S3,
- bucket: "test_bucket"
- )
+ clear_config([Pleroma.Uploaders.S3])
+ clear_config([Pleroma.Uploaders.S3, :bucket], "test_bucket")
end
describe "get_file/1" do
truncated_namespace: ""
)
- Config.put([Pleroma.Upload], base_url: "https://s3.amazonaws.com")
+ Config.put([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
assert S3.get_file("test_image.jpg") == {
:ok,
use ExUnit.CaseTemplate
+ import Pleroma.Tests.Helpers, only: [clear_config: 2]
+
using do
quote do
alias Pleroma.Repo
end
def ensure_local_uploader(context) do
- test_uploader = Map.get(context, :uploader, Pleroma.Uploaders.Local)
- uploader = Pleroma.Config.get([Pleroma.Upload, :uploader])
- filters = Pleroma.Config.get([Pleroma.Upload, :filters]) || []
-
- Pleroma.Config.put([Pleroma.Upload, :uploader], test_uploader)
- Pleroma.Config.put([Pleroma.Upload, :filters], [])
+ test_uploader = Map.get(context, :uploader) || Pleroma.Uploaders.Local
- on_exit(fn ->
- Pleroma.Config.put([Pleroma.Upload, :uploader], uploader)
- Pleroma.Config.put([Pleroma.Upload, :filters], filters)
- end)
+ clear_config([Pleroma.Upload, :uploader], test_uploader)
+ clear_config([Pleroma.Upload, :filters], [])
:ok
end
"""
alias Pleroma.Config
+ require Logger
+
defmacro clear_config(config_path) do
quote do
clear_config(unquote(config_path)) do
defmacro clear_config(config_path, do: yield) do
quote do
initial_setting = Config.fetch(unquote(config_path))
+
unquote(yield)
on_exit(fn ->
end
defmacro clear_config(config_path, temp_setting) do
+ # NOTE: `clear_config([section, key], value)` != `clear_config([section], key: value)` (!)
+ # Displaying a warning to prevent unintentional clearing of all but one keys in section
+ if Keyword.keyword?(temp_setting) and length(temp_setting) == 1 do
+ Logger.warn(
+ "Please change to `clear_config([section]); clear_config([section, key], value)`: " <>
+ "#{inspect(config_path)}, #{inspect(temp_setting)}"
+ )
+ end
+
quote do
clear_config(unquote(config_path)) do
Config.put(unquote(config_path), unquote(temp_setting))