Merge branch 'develop' into refactor/deactivated_user_field
This commit is contained in:
commit
537ba1c5e0
48 changed files with 1066 additions and 214 deletions
|
|
@ -94,6 +94,15 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
|||
end) =~ "Your config is using old namespace for activity expiration configuration."
|
||||
end
|
||||
|
||||
test "check_uploders_s3_public_endpoint/0" do
|
||||
clear_config(Pleroma.Uploaders.S3, public_endpoint: "https://fake.amazonaws.com/bucket/")
|
||||
|
||||
assert capture_log(fn ->
|
||||
DeprecationWarnings.check_uploders_s3_public_endpoint()
|
||||
end) =~
|
||||
"Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket."
|
||||
end
|
||||
|
||||
describe "check_gun_pool_options/0" do
|
||||
test "await_up_timeout" do
|
||||
config = Config.get(:connections_pool)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ defmodule Pleroma.Gun.ConnectionPoolTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
setup :set_mox_from_context
|
||||
setup :gun_mock
|
||||
|
||||
test "gives the same connection to 2 concurrent requests" do
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ defmodule Pleroma.ObjectTest do
|
|||
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",
|
||||
|
|
@ -112,8 +112,8 @@ defmodule Pleroma.ObjectTest do
|
|||
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",
|
||||
|
|
@ -146,9 +146,9 @@ defmodule Pleroma.ObjectTest do
|
|||
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])
|
||||
|
||||
|
|
@ -184,8 +184,8 @@ defmodule Pleroma.ObjectTest do
|
|||
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",
|
||||
|
|
@ -220,9 +220,9 @@ defmodule Pleroma.ObjectTest do
|
|||
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",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Repo.Migrations.DeprecatePublicEndpointTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
import Pleroma.Tests.Helpers
|
||||
alias Pleroma.ConfigDB
|
||||
|
||||
setup do: clear_config(Pleroma.Upload)
|
||||
setup do: clear_config(Pleroma.Uploaders.S3)
|
||||
setup_all do: require_migration("20210113225652_deprecate_public_endpoint")
|
||||
|
||||
test "up/0 migrates public_endpoint to base_url", %{migration: migration} do
|
||||
s3_values = [
|
||||
public_endpoint: "https://coolhost.com/",
|
||||
bucket: "secret_bucket"
|
||||
]
|
||||
|
||||
insert(:config, group: :pleroma, key: Pleroma.Uploaders.S3, value: s3_values)
|
||||
|
||||
upload_values = [
|
||||
uploader: Pleroma.Uploaders.S3
|
||||
]
|
||||
|
||||
insert(:config, group: :pleroma, key: Pleroma.Upload, value: upload_values)
|
||||
|
||||
migration.up()
|
||||
|
||||
assert [bucket: "secret_bucket"] ==
|
||||
ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}).value
|
||||
|
||||
assert [uploader: Pleroma.Uploaders.S3, base_url: "https://coolhost.com/"] ==
|
||||
ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}).value
|
||||
end
|
||||
|
||||
test "down/0 reverts base_url to public_endpoint", %{migration: migration} do
|
||||
s3_values = [
|
||||
bucket: "secret_bucket"
|
||||
]
|
||||
|
||||
insert(:config, group: :pleroma, key: Pleroma.Uploaders.S3, value: s3_values)
|
||||
|
||||
upload_values = [
|
||||
uploader: Pleroma.Uploaders.S3,
|
||||
base_url: "https://coolhost.com/"
|
||||
]
|
||||
|
||||
insert(:config, group: :pleroma, key: Pleroma.Upload, value: upload_values)
|
||||
|
||||
migration.down()
|
||||
|
||||
assert [bucket: "secret_bucket", public_endpoint: "https://coolhost.com/"] ==
|
||||
ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}).value
|
||||
|
||||
assert [uploader: Pleroma.Uploaders.S3] ==
|
||||
ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}).value
|
||||
end
|
||||
end
|
||||
|
|
@ -4,15 +4,14 @@
|
|||
|
||||
defmodule Pleroma.ScheduledActivityTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.DataCase
|
||||
|
||||
alias Pleroma.ScheduledActivity
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do: clear_config([ScheduledActivity, :enabled])
|
||||
|
||||
setup context do
|
||||
DataCase.ensure_local_uploader(context)
|
||||
end
|
||||
setup [:ensure_local_uploader]
|
||||
|
||||
describe "creation" do
|
||||
test "scheduled activities with jobs when ScheduledActivity enabled" do
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ defmodule Pleroma.UploadTest do
|
|||
|
||||
assert %{"url" => [%{"href" => url}]} = data
|
||||
|
||||
assert String.starts_with?(url, Pleroma.Web.base_url() <> "/media/")
|
||||
assert String.starts_with?(url, Pleroma.Upload.base_url())
|
||||
end
|
||||
|
||||
test "copies the file to the configured folder with deduping" do
|
||||
|
|
@ -148,8 +148,8 @@ defmodule Pleroma.UploadTest do
|
|||
{:ok, data} = Upload.store(file, filters: [Pleroma.Upload.Filter.Dedupe])
|
||||
|
||||
assert List.first(data["url"])["href"] ==
|
||||
Pleroma.Web.base_url() <>
|
||||
"/media/e30397b58d226d6583ab5b8b3c5defb0c682bda5c31ef07a9f57c1c4986e3781.jpg"
|
||||
Pleroma.Upload.base_url() <>
|
||||
"e30397b58d226d6583ab5b8b3c5defb0c682bda5c31ef07a9f57c1c4986e3781.jpg"
|
||||
end
|
||||
|
||||
test "copies the file to the configured folder without deduping" do
|
||||
|
|
|
|||
|
|
@ -12,14 +12,10 @@ defmodule Pleroma.Uploaders.S3Test do
|
|||
import ExUnit.CaptureLog
|
||||
|
||||
setup do
|
||||
clear_config(Pleroma.Upload,
|
||||
uploader: Pleroma.Uploaders.S3
|
||||
)
|
||||
|
||||
clear_config(Pleroma.Uploaders.S3,
|
||||
bucket: "test_bucket",
|
||||
public_endpoint: "https://s3.amazonaws.com"
|
||||
)
|
||||
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
|
||||
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
|
||||
clear_config([Pleroma.Uploaders.S3])
|
||||
clear_config([Pleroma.Uploaders.S3, :bucket], "test_bucket")
|
||||
end
|
||||
|
||||
describe "get_file/1" do
|
||||
|
|
@ -33,10 +29,12 @@ defmodule Pleroma.Uploaders.S3Test do
|
|||
test "it returns path without bucket when truncated_namespace set to ''" do
|
||||
Config.put([Pleroma.Uploaders.S3],
|
||||
bucket: "test_bucket",
|
||||
public_endpoint: "https://s3.amazonaws.com",
|
||||
bucket_namespace: "myaccount",
|
||||
truncated_namespace: ""
|
||||
)
|
||||
|
||||
Config.put([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
|
||||
|
||||
assert S3.get_file("test_image.jpg") == {
|
||||
:ok,
|
||||
{:url, "https://s3.amazonaws.com/test_image.jpg"}
|
||||
|
|
@ -46,7 +44,6 @@ defmodule Pleroma.Uploaders.S3Test do
|
|||
test "it returns path with bucket namespace when namespace is set" do
|
||||
Config.put([Pleroma.Uploaders.S3],
|
||||
bucket: "test_bucket",
|
||||
public_endpoint: "https://s3.amazonaws.com",
|
||||
bucket_namespace: "family"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -195,12 +195,8 @@ defmodule Pleroma.User.BackupTest do
|
|||
|
||||
describe "it uploads and deletes a backup archive" do
|
||||
setup do
|
||||
clear_config(Pleroma.Uploaders.S3,
|
||||
bucket: "test_bucket",
|
||||
public_endpoint: "https://s3.amazonaws.com"
|
||||
)
|
||||
|
||||
clear_config([Pleroma.Upload, :uploader])
|
||||
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
|
||||
clear_config([Pleroma.Uploaders.S3, :bucket], "test_bucket")
|
||||
|
||||
user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
|
||||
|
||||
|
|
@ -219,7 +215,8 @@ defmodule Pleroma.User.BackupTest do
|
|||
end
|
||||
|
||||
test "S3", %{path: path, backup: backup} do
|
||||
Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
|
||||
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
|
||||
clear_config([Pleroma.Uploaders.S3, :streaming_enabled], false)
|
||||
|
||||
with_mock ExAws,
|
||||
request: fn
|
||||
|
|
@ -229,13 +226,10 @@ defmodule Pleroma.User.BackupTest do
|
|||
assert {:ok, %Pleroma.Upload{}} = Backup.upload(backup, path)
|
||||
assert {:ok, _backup} = Backup.delete(backup)
|
||||
end
|
||||
|
||||
with_mock ExAws, request: fn %{http_method: :delete} -> {:ok, %{status_code: 204}} end do
|
||||
end
|
||||
end
|
||||
|
||||
test "Local", %{path: path, backup: backup} do
|
||||
Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
|
||||
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
|
||||
|
||||
assert {:ok, %Pleroma.Upload{}} = Backup.upload(backup, path)
|
||||
assert {:ok, _backup} = Backup.delete(backup)
|
||||
|
|
|
|||
|
|
@ -1563,31 +1563,15 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "delete/1 when confirmation is pending" do
|
||||
setup do
|
||||
user = insert(:user, is_confirmed: false)
|
||||
{:ok, user: user}
|
||||
end
|
||||
test "delete/1 when confirmation is pending deletes the user" do
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
user = insert(:user, is_confirmed: false)
|
||||
|
||||
test "deletes user from database when activation required", %{user: user} do
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
{:ok, job} = User.delete(user)
|
||||
{:ok, _} = ObanHelpers.perform(job)
|
||||
|
||||
{:ok, job} = User.delete(user)
|
||||
{:ok, _} = ObanHelpers.perform(job)
|
||||
|
||||
refute User.get_cached_by_id(user.id)
|
||||
refute User.get_by_id(user.id)
|
||||
end
|
||||
|
||||
test "deactivates user when activation is not required", %{user: user} do
|
||||
clear_config([:instance, :account_activation_required], false)
|
||||
|
||||
{:ok, job} = User.delete(user)
|
||||
{:ok, _} = ObanHelpers.perform(job)
|
||||
|
||||
assert %{is_active: false} = User.get_cached_by_id(user.id)
|
||||
assert %{is_active: false} = User.get_by_id(user.id)
|
||||
end
|
||||
refute User.get_cached_by_id(user.id)
|
||||
refute User.get_by_id(user.id)
|
||||
end
|
||||
|
||||
test "delete/1 when approval is pending deletes the user" do
|
||||
|
|
@ -1830,13 +1814,6 @@ defmodule Pleroma.UserTest do
|
|||
assert User.visible_for(user, other_user) == :visible
|
||||
end
|
||||
|
||||
test "returns true when the account is unconfirmed and confirmation is not required" do
|
||||
user = insert(:user, local: true, is_confirmed: false)
|
||||
other_user = insert(:user, local: true)
|
||||
|
||||
assert User.visible_for(user, other_user) == :visible
|
||||
end
|
||||
|
||||
test "returns true when the account is unconfirmed and being viewed by a privileged account (confirmation required)" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
|
|
|
|||
|
|
@ -165,14 +165,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
{:ok, delete: delete_user, user: user}
|
||||
end
|
||||
|
||||
test "when activation is not required", %{delete: delete, user: user} do
|
||||
clear_config([:instance, :account_activation_required], false)
|
||||
{:ok, _, _} = SideEffects.handle(delete)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
refute User.get_cached_by_id(user.id).is_active
|
||||
end
|
||||
|
||||
test "when activation is required", %{delete: delete, user: user} do
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
{:ok, _, _} = SideEffects.handle(delete)
|
||||
|
|
|
|||
|
|
@ -744,6 +744,22 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
refute Visibility.visible_for_user?(announce_activity, nil)
|
||||
end
|
||||
|
||||
test "author can repeat own private statuses" do
|
||||
author = insert(:user)
|
||||
follower = insert(:user)
|
||||
CommonAPI.follow(follower, author)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(author, %{status: "cofe", visibility: "private"})
|
||||
|
||||
{:ok, %Activity{} = announce_activity} = CommonAPI.repeat(activity.id, author)
|
||||
|
||||
assert Visibility.is_private?(announce_activity)
|
||||
refute Visibility.visible_for_user?(announce_activity, nil)
|
||||
|
||||
assert Visibility.visible_for_user?(activity, follower)
|
||||
assert {:error, :not_found} = CommonAPI.repeat(activity.id, follower)
|
||||
end
|
||||
|
||||
test "favoriting a status" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -954,6 +954,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
assert to_string(activity.id) == id
|
||||
end
|
||||
|
||||
test "author can reblog own private status", %{conn: conn, user: user} do
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "cofe", visibility: "private"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses/#{activity.id}/reblog")
|
||||
|
||||
assert %{
|
||||
"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
|
||||
"reblogged" => true,
|
||||
"visibility" => "private"
|
||||
} = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
assert to_string(activity.id) == id
|
||||
end
|
||||
end
|
||||
|
||||
describe "unreblogging" do
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
tags: [
|
||||
%{
|
||||
name: "#{object_data["tag"]}",
|
||||
url: "/tag/#{object_data["tag"]}"
|
||||
url: "http://localhost:4001/tag/#{object_data["tag"]}"
|
||||
}
|
||||
],
|
||||
application: %{
|
||||
|
|
@ -585,9 +585,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
]
|
||||
|
||||
assert StatusView.build_tags(object_tags) == [
|
||||
%{name: "fediverse", url: "/tag/fediverse"},
|
||||
%{name: "mastodon", url: "/tag/mastodon"},
|
||||
%{name: "nextcloud", url: "/tag/nextcloud"}
|
||||
%{name: "fediverse", url: "http://localhost:4001/tag/fediverse"},
|
||||
%{name: "mastodon", url: "http://localhost:4001/tag/mastodon"},
|
||||
%{name: "nextcloud", url: "http://localhost:4001/tag/nextcloud"}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -30,19 +30,5 @@ defmodule Pleroma.Web.ChannelCase do
|
|||
end
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
|
||||
|
||||
if tags[:async] do
|
||||
Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
|
||||
Mox.set_mox_private()
|
||||
else
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
|
||||
Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy)
|
||||
Mox.set_mox_global()
|
||||
Pleroma.DataCase.clear_cachex()
|
||||
end
|
||||
|
||||
:ok
|
||||
end
|
||||
setup tags, do: Pleroma.DataCase.setup_multi_process_mode(tags)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ defmodule Pleroma.Web.ConnCase do
|
|||
|
||||
use ExUnit.CaseTemplate
|
||||
|
||||
alias Pleroma.DataCase
|
||||
|
||||
using do
|
||||
quote do
|
||||
# Import conveniences for testing with connections
|
||||
|
|
@ -116,27 +118,9 @@ defmodule Pleroma.Web.ConnCase do
|
|||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
|
||||
|
||||
if tags[:async] do
|
||||
Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
|
||||
Mox.set_mox_private()
|
||||
else
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
|
||||
Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy)
|
||||
Mox.set_mox_global()
|
||||
Pleroma.DataCase.clear_cachex()
|
||||
end
|
||||
|
||||
if tags[:needs_streamer] do
|
||||
start_supervised(%{
|
||||
id: Pleroma.Web.Streamer.registry(),
|
||||
start:
|
||||
{Registry, :start_link, [[keys: :duplicate, name: Pleroma.Web.Streamer.registry()]]}
|
||||
})
|
||||
end
|
||||
|
||||
Pleroma.DataCase.stub_pipeline()
|
||||
DataCase.setup_multi_process_mode(tags)
|
||||
DataCase.setup_streamer(tags)
|
||||
DataCase.stub_pipeline()
|
||||
|
||||
Mox.verify_on_exit!()
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ defmodule Pleroma.DataCase do
|
|||
|
||||
use ExUnit.CaseTemplate
|
||||
|
||||
import Pleroma.Tests.Helpers, only: [clear_config: 2]
|
||||
|
||||
using do
|
||||
quote do
|
||||
alias Pleroma.Repo
|
||||
|
|
@ -62,7 +64,7 @@ defmodule Pleroma.DataCase do
|
|||
end)
|
||||
end
|
||||
|
||||
setup tags do
|
||||
def setup_multi_process_mode(tags) do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
|
||||
|
||||
if tags[:async] do
|
||||
|
|
@ -70,11 +72,16 @@ defmodule Pleroma.DataCase do
|
|||
Mox.set_mox_private()
|
||||
else
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
|
||||
Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy)
|
||||
|
||||
Mox.set_mox_global()
|
||||
Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy)
|
||||
clear_cachex()
|
||||
end
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
def setup_streamer(tags) do
|
||||
if tags[:needs_streamer] do
|
||||
start_supervised(%{
|
||||
id: Pleroma.Web.Streamer.registry(),
|
||||
|
|
@ -83,6 +90,12 @@ defmodule Pleroma.DataCase do
|
|||
})
|
||||
end
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
setup tags do
|
||||
setup_multi_process_mode(tags)
|
||||
setup_streamer(tags)
|
||||
stub_pipeline()
|
||||
|
||||
Mox.verify_on_exit!()
|
||||
|
|
@ -105,17 +118,10 @@ defmodule Pleroma.DataCase do
|
|||
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])
|
||||
test_uploader = Map.get(context, :uploader) || Pleroma.Uploaders.Local
|
||||
|
||||
Pleroma.Config.put([Pleroma.Upload, :uploader], test_uploader)
|
||||
Pleroma.Config.put([Pleroma.Upload, :filters], [])
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ defmodule Pleroma.Tests.Helpers do
|
|||
"""
|
||||
alias Pleroma.Config
|
||||
|
||||
require Logger
|
||||
|
||||
defmacro clear_config(config_path) do
|
||||
quote do
|
||||
clear_config(unquote(config_path)) do
|
||||
|
|
@ -18,6 +20,7 @@ defmodule Pleroma.Tests.Helpers do
|
|||
defmacro clear_config(config_path, do: yield) do
|
||||
quote do
|
||||
initial_setting = Config.fetch(unquote(config_path))
|
||||
|
||||
unquote(yield)
|
||||
|
||||
on_exit(fn ->
|
||||
|
|
@ -35,6 +38,15 @@ defmodule Pleroma.Tests.Helpers do
|
|||
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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue