summaryrefslogtreecommitdiff
path: root/test/mix/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'test/mix/tasks')
-rw-r--r--test/mix/tasks/pleroma/app_test.exs2
-rw-r--r--test/mix/tasks/pleroma/config_test.exs173
-rw-r--r--test/mix/tasks/pleroma/count_statuses_test.exs3
-rw-r--r--test/mix/tasks/pleroma/database_test.exs9
-rw-r--r--test/mix/tasks/pleroma/digest_test.exs2
-rw-r--r--test/mix/tasks/pleroma/ecto/migrate_test.exs4
-rw-r--r--test/mix/tasks/pleroma/ecto/rollback_test.exs6
-rw-r--r--test/mix/tasks/pleroma/ecto_test.exs2
-rw-r--r--test/mix/tasks/pleroma/email_test.exs20
-rw-r--r--test/mix/tasks/pleroma/emoji_test.exs2
-rw-r--r--test/mix/tasks/pleroma/frontend_test.exs2
-rw-r--r--test/mix/tasks/pleroma/instance_test.exs13
-rw-r--r--test/mix/tasks/pleroma/refresh_counter_cache_test.exs3
-rw-r--r--test/mix/tasks/pleroma/relay_test.exs6
-rw-r--r--test/mix/tasks/pleroma/robots_txt_test.exs6
-rw-r--r--test/mix/tasks/pleroma/uploads_test.exs2
-rw-r--r--test/mix/tasks/pleroma/user_test.exs175
17 files changed, 280 insertions, 150 deletions
diff --git a/test/mix/tasks/pleroma/app_test.exs b/test/mix/tasks/pleroma/app_test.exs
index 71a84ac8e..9eabd32af 100644
--- a/test/mix/tasks/pleroma/app_test.exs
+++ b/test/mix/tasks/pleroma/app_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.AppTest do
diff --git a/test/mix/tasks/pleroma/config_test.exs b/test/mix/tasks/pleroma/config_test.exs
index f36648829..21f8f2286 100644
--- a/test/mix/tasks/pleroma/config_test.exs
+++ b/test/mix/tasks/pleroma/config_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.ConfigTest do
@@ -7,6 +7,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
import Pleroma.Factory
+ alias Mix.Tasks.Pleroma.Config, as: MixTask
alias Pleroma.ConfigDB
alias Pleroma.Repo
@@ -22,30 +23,41 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
:ok
end
- setup_all do: clear_config(:configurable_from_database, true)
+ defp config_records do
+ ConfigDB
+ |> Repo.all()
+ |> Enum.sort()
+ end
+
+ defp insert_config_record(group, key, value) do
+ insert(:config,
+ group: group,
+ key: key,
+ value: value
+ )
+ end
test "error if file with custom settings doesn't exist" do
- Mix.Tasks.Pleroma.Config.migrate_to_db("config/not_existance_config_file.exs")
+ MixTask.migrate_to_db("config/non_existent_config_file.exs")
+
+ msg =
+ "To migrate settings, you must define custom settings in config/non_existent_config_file.exs."
- assert_receive {:mix_shell, :info,
- [
- "To migrate settings, you must define custom settings in config/not_existance_config_file.exs."
- ]},
- 15
+ assert_receive {:mix_shell, :info, [^msg]}, 15
end
describe "migrate_to_db/1" do
setup do
- initial = Application.get_env(:quack, :level)
- on_exit(fn -> Application.put_env(:quack, :level, initial) end)
+ clear_config(:configurable_from_database, true)
+ clear_config([:quack, :level])
end
@tag capture_log: true
test "config migration refused when deprecated settings are found" do
clear_config([:media_proxy, :whitelist], ["domain_without_scheme.com"])
- assert Repo.all(ConfigDB) == []
+ assert config_records() == []
- Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
+ MixTask.migrate_to_db("test/fixtures/config/temp.secret.exs")
assert_received {:mix_shell, :error, [message]}
@@ -54,9 +66,9 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
end
test "filtered settings are migrated to db" do
- assert Repo.all(ConfigDB) == []
+ assert config_records() == []
- Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
+ MixTask.migrate_to_db("test/fixtures/config/temp.secret.exs")
config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"})
@@ -71,18 +83,19 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
end
test "config table is truncated before migration" do
- insert(:config, key: :first_setting, value: [key: "value", key2: ["Activity"]])
- assert Repo.aggregate(ConfigDB, :count, :id) == 1
+ insert_config_record(:pleroma, :first_setting, key: "value", key2: ["Activity"])
+ assert length(config_records()) == 1
- Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
+ MixTask.migrate_to_db("test/fixtures/config/temp.secret.exs")
config = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
assert config.value == [key: "value", key2: [Repo]]
end
end
- describe "with deletion temp file" do
+ describe "with deletion of temp file" do
setup do
+ clear_config(:configurable_from_database, true)
temp_file = "config/temp.exported_from_db.secret.exs"
on_exit(fn ->
@@ -93,13 +106,13 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
end
test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do
- insert(:config, key: :setting_first, value: [key: "value", key2: ["Activity"]])
- insert(:config, key: :setting_second, value: [key: "value2", key2: [Repo]])
- insert(:config, group: :quack, key: :level, value: :info)
+ insert_config_record(:pleroma, :setting_first, key: "value", key2: ["Activity"])
+ insert_config_record(:pleroma, :setting_second, key: "value2", key2: [Repo])
+ insert_config_record(:quack, :level, :info)
- Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"])
+ MixTask.run(["migrate_from_db", "--env", "temp", "-d"])
- assert Repo.all(ConfigDB) == []
+ assert config_records() == []
file = File.read!(temp_file)
assert file =~ "config :pleroma, :setting_first,"
@@ -169,9 +182,9 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
]
)
- Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"])
+ MixTask.run(["migrate_from_db", "--env", "temp", "-d"])
- assert Repo.all(ConfigDB) == []
+ assert config_records() == []
assert File.exists?(temp_file)
{:ok, file} = File.read(temp_file)
@@ -186,4 +199,114 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
"#{header}\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n attachment_links: false,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
end
end
+
+ describe "operations on database config" do
+ setup do: clear_config(:configurable_from_database, true)
+
+ test "dumping a specific group" do
+ insert_config_record(:pleroma, :instance, name: "Pleroma Test")
+
+ insert_config_record(:web_push_encryption, :vapid_details,
+ subject: "mailto:administrator@example.com",
+ public_key:
+ "BOsPL-_KjNnjj_RMvLeR3dTOrcndi4TbMR0cu56gLGfGaT5m1gXxSfRHOcC4Dd78ycQL1gdhtx13qgKHmTM5xAI",
+ private_key: "Ism6FNdS31nLCA94EfVbJbDdJXCxAZ8cZiB1JQPN_t4"
+ )
+
+ MixTask.run(["dump", "pleroma"])
+
+ assert_receive {:mix_shell, :info,
+ ["config :pleroma, :instance, [name: \"Pleroma Test\"]\r\n\r\n"]}
+
+ refute_receive {
+ :mix_shell,
+ :info,
+ [
+ "config :web_push_encryption, :vapid_details, [subject: \"mailto:administrator@example.com\", public_key: \"BOsPL-_KjNnjj_RMvLeR3dTOrcndi4TbMR0cu56gLGfGaT5m1gXxSfRHOcC4Dd78ycQL1gdhtx13qgKHmTM5xAI\", private_key: \"Ism6FNdS31nLCA94EfVbJbDdJXCxAZ8cZiB1JQPN_t4\"]\r\n\r\n"
+ ]
+ }
+
+ # Ensure operations work when using atom syntax
+ MixTask.run(["dump", ":pleroma"])
+
+ assert_receive {:mix_shell, :info,
+ ["config :pleroma, :instance, [name: \"Pleroma Test\"]\r\n\r\n"]}
+ end
+
+ test "dumping a specific key in a group" do
+ insert_config_record(:pleroma, :instance, name: "Pleroma Test")
+ insert_config_record(:pleroma, Pleroma.Captcha, enabled: false)
+
+ MixTask.run(["dump", "pleroma", "Pleroma.Captcha"])
+
+ refute_receive {:mix_shell, :info,
+ ["config :pleroma, :instance, [name: \"Pleroma Test\"]\r\n\r\n"]}
+
+ assert_receive {:mix_shell, :info,
+ ["config :pleroma, Pleroma.Captcha, [enabled: false]\r\n\r\n"]}
+ end
+
+ test "dumps all configuration successfully" do
+ insert_config_record(:pleroma, :instance, name: "Pleroma Test")
+ insert_config_record(:pleroma, Pleroma.Captcha, enabled: false)
+
+ MixTask.run(["dump"])
+
+ assert_receive {:mix_shell, :info,
+ ["config :pleroma, :instance, [name: \"Pleroma Test\"]\r\n\r\n"]}
+
+ assert_receive {:mix_shell, :info,
+ ["config :pleroma, Pleroma.Captcha, [enabled: false]\r\n\r\n"]}
+ end
+ end
+
+ describe "when configdb disabled" do
+ test "refuses to dump" do
+ clear_config(:configurable_from_database, false)
+
+ insert_config_record(:pleroma, :instance, name: "Pleroma Test")
+
+ MixTask.run(["dump"])
+
+ msg =
+ "ConfigDB not enabled. Please check the value of :configurable_from_database in your configuration."
+
+ assert_receive {:mix_shell, :error, [^msg]}
+ end
+ end
+
+ describe "destructive operations" do
+ setup do: clear_config(:configurable_from_database, true)
+
+ setup do
+ insert_config_record(:pleroma, :instance, name: "Pleroma Test")
+ insert_config_record(:pleroma, Pleroma.Captcha, enabled: false)
+ insert_config_record(:pleroma2, :key2, z: 1)
+
+ assert length(config_records()) == 3
+
+ :ok
+ end
+
+ test "deletes group of settings" do
+ MixTask.run(["delete", "--force", "pleroma"])
+
+ assert [%ConfigDB{group: :pleroma2, key: :key2}] = config_records()
+ end
+
+ test "deletes specified key" do
+ MixTask.run(["delete", "--force", "pleroma", "Pleroma.Captcha"])
+
+ assert [
+ %ConfigDB{group: :pleroma, key: :instance},
+ %ConfigDB{group: :pleroma2, key: :key2}
+ ] = config_records()
+ end
+
+ test "resets entire config" do
+ MixTask.run(["reset", "--force"])
+
+ assert config_records() == []
+ end
+ end
end
diff --git a/test/mix/tasks/pleroma/count_statuses_test.exs b/test/mix/tasks/pleroma/count_statuses_test.exs
index c5cd16960..80ec206b8 100644
--- a/test/mix/tasks/pleroma/count_statuses_test.exs
+++ b/test/mix/tasks/pleroma/count_statuses_test.exs
@@ -1,8 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.CountStatusesTest do
+ # Uses log capture, has to stay synchronous
use Pleroma.DataCase
alias Pleroma.User
diff --git a/test/mix/tasks/pleroma/database_test.exs b/test/mix/tasks/pleroma/database_test.exs
index 292a5ef5f..7a1a759da 100644
--- a/test/mix/tasks/pleroma/database_test.exs
+++ b/test/mix/tasks/pleroma/database_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.DatabaseTest do
- use Pleroma.DataCase
+ use Pleroma.DataCase, async: true
use Oban.Testing, repo: Pleroma.Repo
alias Pleroma.Activity
@@ -73,7 +73,7 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
describe "running update_users_following_followers_counts" do
test "following and followers count are updated" do
[user, user2] = insert_pair(:user)
- {:ok, %User{} = user} = User.follow(user, user2)
+ {:ok, %User{} = user, _user2} = User.follow(user, user2)
following = User.following(user)
@@ -87,7 +87,8 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
assert user.follower_count == 3
- assert :ok == Mix.Tasks.Pleroma.Database.run(["update_users_following_followers_counts"])
+ assert {:ok, :ok} ==
+ Mix.Tasks.Pleroma.Database.run(["update_users_following_followers_counts"])
user = User.get_by_id(user.id)
diff --git a/test/mix/tasks/pleroma/digest_test.exs b/test/mix/tasks/pleroma/digest_test.exs
index 69dccb745..4a9e461a9 100644
--- a/test/mix/tasks/pleroma/digest_test.exs
+++ b/test/mix/tasks/pleroma/digest_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.DigestTest do
diff --git a/test/mix/tasks/pleroma/ecto/migrate_test.exs b/test/mix/tasks/pleroma/ecto/migrate_test.exs
index 43df176a1..5bdfd8f30 100644
--- a/test/mix/tasks/pleroma/ecto/migrate_test.exs
+++ b/test/mix/tasks/pleroma/ecto/migrate_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-onl
defmodule Mix.Tasks.Pleroma.Ecto.MigrateTest do
- use Pleroma.DataCase, async: true
+ use Pleroma.DataCase
import ExUnit.CaptureLog
require Logger
diff --git a/test/mix/tasks/pleroma/ecto/rollback_test.exs b/test/mix/tasks/pleroma/ecto/rollback_test.exs
index 0236e35d5..f8a37bd49 100644
--- a/test/mix/tasks/pleroma/ecto/rollback_test.exs
+++ b/test/mix/tasks/pleroma/ecto/rollback_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.Ecto.RollbackTest do
- use Pleroma.DataCase
+ use Pleroma.DataCase, async: true
import ExUnit.CaptureLog
require Logger
@@ -12,7 +12,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.RollbackTest do
Logger.configure(level: :warn)
assert capture_log(fn ->
- Mix.Tasks.Pleroma.Ecto.Rollback.run()
+ Mix.Tasks.Pleroma.Ecto.Rollback.run(["--env", "test"])
end) =~ "[info] Rollback succesfully"
Logger.configure(level: level)
diff --git a/test/mix/tasks/pleroma/ecto_test.exs b/test/mix/tasks/pleroma/ecto_test.exs
index 3a028df83..0164da5a8 100644
--- a/test/mix/tasks/pleroma/ecto_test.exs
+++ b/test/mix/tasks/pleroma/ecto_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.EctoTest do
diff --git a/test/mix/tasks/pleroma/email_test.exs b/test/mix/tasks/pleroma/email_test.exs
index 9523aefd8..ce68b88de 100644
--- a/test/mix/tasks/pleroma/email_test.exs
+++ b/test/mix/tasks/pleroma/email_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.EmailTest do
@@ -61,18 +61,18 @@ defmodule Mix.Tasks.Pleroma.EmailTest do
test "Sends confirmation emails" do
local_user1 =
insert(:user, %{
- confirmation_pending: true,
+ is_confirmed: false,
confirmation_token: "mytoken",
- deactivated: false,
+ is_active: true,
email: "local1@pleroma.com",
local: true
})
local_user2 =
insert(:user, %{
- confirmation_pending: true,
+ is_confirmed: false,
confirmation_token: "mytoken",
- deactivated: false,
+ is_active: true,
email: "local2@pleroma.com",
local: true
})
@@ -88,30 +88,30 @@ defmodule Mix.Tasks.Pleroma.EmailTest do
test "Does not send confirmation email to inappropriate users" do
# confirmed user
insert(:user, %{
- confirmation_pending: false,
+ is_confirmed: true,
confirmation_token: "mytoken",
- deactivated: false,
+ is_active: true,
email: "confirmed@pleroma.com",
local: true
})
# remote user
insert(:user, %{
- deactivated: false,
+ is_active: true,
email: "remote@not-pleroma.com",
local: false
})
# deactivated user =
insert(:user, %{
- deactivated: true,
+ is_active: false,
email: "deactivated@pleroma.com",
local: false
})
# invisible user
insert(:user, %{
- deactivated: false,
+ is_active: true,
email: "invisible@pleroma.com",
local: true,
invisible: true
diff --git a/test/mix/tasks/pleroma/emoji_test.exs b/test/mix/tasks/pleroma/emoji_test.exs
index 0fb8603ac..bd20f285c 100644
--- a/test/mix/tasks/pleroma/emoji_test.exs
+++ b/test/mix/tasks/pleroma/emoji_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.EmojiTest do
diff --git a/test/mix/tasks/pleroma/frontend_test.exs b/test/mix/tasks/pleroma/frontend_test.exs
index 6f9ec14cd..aa4b25ebb 100644
--- a/test/mix/tasks/pleroma/frontend_test.exs
+++ b/test/mix/tasks/pleroma/frontend_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.FrontendTest do
diff --git a/test/mix/tasks/pleroma/instance_test.exs b/test/mix/tasks/pleroma/instance_test.exs
index 6580fc932..5a5a68053 100644
--- a/test/mix/tasks/pleroma/instance_test.exs
+++ b/test/mix/tasks/pleroma/instance_test.exs
@@ -1,9 +1,10 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.InstanceTest do
- use ExUnit.Case
+ # Modifies the Application Environment, has to stay synchronous.
+ use Pleroma.DataCase
setup do
File.mkdir_p!(tmp_path())
@@ -15,15 +16,17 @@ defmodule Mix.Tasks.Pleroma.InstanceTest do
if File.exists?(static_dir) do
File.rm_rf(Path.join(static_dir, "robots.txt"))
end
-
- Pleroma.Config.put([:instance, :static_dir], static_dir)
end)
+ # Is being modified by the mix task.
+ clear_config([:instance, :static_dir])
+
:ok
end
+ @uuid Ecto.UUID.generate()
defp tmp_path do
- "/tmp/generated_files/"
+ "/tmp/generated_files/#{@uuid}/"
end
test "running gen" do
diff --git a/test/mix/tasks/pleroma/refresh_counter_cache_test.exs b/test/mix/tasks/pleroma/refresh_counter_cache_test.exs
index 6a1a9ac17..fe9e5cfeb 100644
--- a/test/mix/tasks/pleroma/refresh_counter_cache_test.exs
+++ b/test/mix/tasks/pleroma/refresh_counter_cache_test.exs
@@ -1,8 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.RefreshCounterCacheTest do
+ # Uses log capture, has to stay synchronous
use Pleroma.DataCase
alias Pleroma.Web.CommonAPI
import ExUnit.CaptureIO, only: [capture_io: 1]
diff --git a/test/mix/tasks/pleroma/relay_test.exs b/test/mix/tasks/pleroma/relay_test.exs
index cf48e7dda..db75b3630 100644
--- a/test/mix/tasks/pleroma/relay_test.exs
+++ b/test/mix/tasks/pleroma/relay_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.RelayTest do
@@ -100,7 +100,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
end)
Pleroma.Repo.delete(user)
- Cachex.clear(:user_cache)
+ User.invalidate_cache(user)
Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
@@ -137,7 +137,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
end)
Pleroma.Repo.delete(user)
- Cachex.clear(:user_cache)
+ User.invalidate_cache(user)
Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance, "--force"])
diff --git a/test/mix/tasks/pleroma/robots_txt_test.exs b/test/mix/tasks/pleroma/robots_txt_test.exs
index 7040a0e4e..028aa4ccc 100644
--- a/test/mix/tasks/pleroma/robots_txt_test.exs
+++ b/test/mix/tasks/pleroma/robots_txt_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
@@ -12,7 +12,7 @@ defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
test "creates new dir" do
path = "test/fixtures/new_dir/"
file_path = path <> "robots.txt"
- Pleroma.Config.put([:instance, :static_dir], path)
+ clear_config([:instance, :static_dir], path)
on_exit(fn ->
{:ok, ["test/fixtures/new_dir/", "test/fixtures/new_dir/robots.txt"]} = File.rm_rf(path)
@@ -29,7 +29,7 @@ defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
test "to existance folder" do
path = "test/fixtures/"
file_path = path <> "robots.txt"
- Pleroma.Config.put([:instance, :static_dir], path)
+ clear_config([:instance, :static_dir], path)
on_exit(fn ->
:ok = File.rm(file_path)
diff --git a/test/mix/tasks/pleroma/uploads_test.exs b/test/mix/tasks/pleroma/uploads_test.exs
index d69e149a8..a7d15e0fa 100644
--- a/test/mix/tasks/pleroma/uploads_test.exs
+++ b/test/mix/tasks/pleroma/uploads_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.UploadsTest do
diff --git a/test/mix/tasks/pleroma/user_test.exs b/test/mix/tasks/pleroma/user_test.exs
index ce819f815..a2178bbd1 100644
--- a/test/mix/tasks/pleroma/user_test.exs
+++ b/test/mix/tasks/pleroma/user_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.UserTest do
@@ -36,7 +36,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
unsaved = build(:user)
# prepare to answer yes
- send(self(), {:mix_shell_input, :yes?, true})
+ send(self(), {:mix_shell_input, :prompt, "Y"})
Mix.Tasks.Pleroma.User.run([
"new",
@@ -55,7 +55,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ "user will be created"
- assert_received {:mix_shell, :yes?, [message]}
+ assert_received {:mix_shell, :prompt, [message]}
assert message =~ "Continue"
assert_received {:mix_shell, :info, [message]}
@@ -73,14 +73,14 @@ defmodule Mix.Tasks.Pleroma.UserTest do
unsaved = build(:user)
# prepare to answer no
- send(self(), {:mix_shell_input, :yes?, false})
+ send(self(), {:mix_shell_input, :prompt, "N"})
Mix.Tasks.Pleroma.User.run(["new", unsaved.nickname, unsaved.email])
assert_received {:mix_shell, :info, [message]}
assert message =~ "user will be created"
- assert_received {:mix_shell, :yes?, [message]}
+ assert_received {:mix_shell, :prompt, [message]}
assert message =~ "Continue"
assert_received {:mix_shell, :info, [message]}
@@ -102,7 +102,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted"
- assert %{deactivated: true} = User.get_by_nickname(user.nickname)
+ assert %{is_active: false} = User.get_by_nickname(user.nickname)
assert called(Pleroma.Web.Federator.publish(:_))
end
@@ -114,7 +114,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
{:ok, post} = CommonAPI.post(user, %{status: "uguu"})
{:ok, post2} = CommonAPI.post(user2, %{status: "test"})
- obj = Object.normalize(post2)
+ obj = Object.normalize(post2, fetch: false)
{:ok, like_object, meta} = Pleroma.Web.ActivityPub.Builder.like(user, obj)
@@ -130,7 +130,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
clear_config([:instance, :federating], true)
- object = Object.normalize(post)
+ object = Object.normalize(post, fetch: false)
Object.prune(object)
with_mock Pleroma.Web.Federator,
@@ -140,7 +140,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted"
- assert %{deactivated: true} = User.get_by_nickname(user.nickname)
+ assert %{is_active: false} = User.get_by_nickname(user.nickname)
assert called(Pleroma.Web.Federator.publish(:_))
refute Pleroma.Repo.get(Pleroma.Activity, like_activity.id)
@@ -157,41 +157,8 @@ defmodule Mix.Tasks.Pleroma.UserTest do
end
end
- describe "running toggle_activated" do
- test "user is deactivated" do
- user = insert(:user)
-
- Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
-
- assert_received {:mix_shell, :info, [message]}
- assert message =~ " deactivated"
-
- user = User.get_cached_by_nickname(user.nickname)
- assert user.deactivated
- end
-
- test "user is activated" do
- user = insert(:user, deactivated: true)
-
- Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
-
- assert_received {:mix_shell, :info, [message]}
- assert message =~ " activated"
-
- user = User.get_cached_by_nickname(user.nickname)
- refute user.deactivated
- end
-
- test "no user to toggle" do
- Mix.Tasks.Pleroma.User.run(["toggle_activated", "nonexistent"])
-
- assert_received {:mix_shell, :error, [message]}
- assert message =~ "No user"
- end
- end
-
describe "running deactivate" do
- test "user is unsubscribed" do
+ test "active user is deactivated and unsubscribed" do
followed = insert(:user)
remote_followed = insert(:user, local: false)
user = insert(:user)
@@ -201,16 +168,26 @@ defmodule Mix.Tasks.Pleroma.UserTest do
Mix.Tasks.Pleroma.User.run(["deactivate", user.nickname])
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "Deactivating"
-
# Note that the task has delay :timer.sleep(500)
assert_received {:mix_shell, :info, [message]}
- assert message =~ "Successfully unsubscribed"
+
+ assert message ==
+ "Successfully deactivated #{user.nickname} and unsubscribed all local followers"
user = User.get_cached_by_nickname(user.nickname)
assert Enum.empty?(Enum.filter(User.get_friends(user), & &1.local))
- assert user.deactivated
+ refute user.is_active
+ end
+
+ test "user is deactivated" do
+ %{id: id, nickname: nickname} = insert(:user, is_active: false)
+
+ assert :ok = Mix.Tasks.Pleroma.User.run(["deactivate", nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message == "User #{nickname} already deactivated"
+
+ user = Repo.get(User, id)
+ refute user.is_active
end
test "no user to deactivate" do
@@ -238,7 +215,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert message =~ ~r/Admin status .* true/
assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r/Confirmation pending .* false/
+ assert message =~ ~r/Confirmation status.* true/
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Locked status .* true/
@@ -250,7 +227,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert user.is_moderator
assert user.is_locked
assert user.is_admin
- refute user.confirmation_pending
+ assert user.is_confirmed
end
test "All statuses unset" do
@@ -259,7 +236,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
is_locked: true,
is_moderator: true,
is_admin: true,
- confirmation_pending: true
+ is_confirmed: false
)
Mix.Tasks.Pleroma.User.run([
@@ -275,7 +252,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert message =~ ~r/Admin status .* false/
assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r/Confirmation pending .* true/
+ assert message =~ ~r/Confirmation status.* false/
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Locked status .* false/
@@ -287,7 +264,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
refute user.is_moderator
refute user.is_locked
refute user.is_admin
- assert user.confirmation_pending
+ refute user.is_confirmed
end
test "no user to set status" do
@@ -436,13 +413,6 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ "Invite for token #{invite.token} was revoked."
end
-
- test "it prints an error message when invite is not exist" do
- Mix.Tasks.Pleroma.User.run(["revoke_invite", "foo"])
-
- assert_received {:mix_shell, :error, [message]}
- assert message =~ "No invite found"
- end
end
describe "running delete_activities" do
@@ -462,40 +432,71 @@ defmodule Mix.Tasks.Pleroma.UserTest do
end
end
- describe "running toggle_confirmed" do
+ describe "running confirm" do
test "user is confirmed" do
- %{id: id, nickname: nickname} = insert(:user, confirmation_pending: false)
+ %{id: id, nickname: nickname} = insert(:user, is_confirmed: true)
- assert :ok = Mix.Tasks.Pleroma.User.run(["toggle_confirmed", nickname])
+ assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname])
assert_received {:mix_shell, :info, [message]}
- assert message == "#{nickname} needs confirmation."
+ assert message == "#{nickname} doesn't need confirmation."
user = Repo.get(User, id)
- assert user.confirmation_pending
- assert user.confirmation_token
+ assert user.is_confirmed
+ refute user.confirmation_token
end
test "user is not confirmed" do
%{id: id, nickname: nickname} =
- insert(:user, confirmation_pending: true, confirmation_token: "some token")
+ insert(:user, is_confirmed: false, confirmation_token: "some token")
- assert :ok = Mix.Tasks.Pleroma.User.run(["toggle_confirmed", nickname])
+ assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname])
assert_received {:mix_shell, :info, [message]}
assert message == "#{nickname} doesn't need confirmation."
user = Repo.get(User, id)
- refute user.confirmation_pending
+ assert user.is_confirmed
refute user.confirmation_token
end
test "it prints an error message when user is not exist" do
- Mix.Tasks.Pleroma.User.run(["toggle_confirmed", "foo"])
+ Mix.Tasks.Pleroma.User.run(["confirm", "foo"])
assert_received {:mix_shell, :error, [message]}
assert message =~ "No local user"
end
end
+ describe "running activate" do
+ test "user is activated" do
+ %{id: id, nickname: nickname} = insert(:user, is_active: true)
+
+ assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message == "User #{nickname} already activated"
+
+ user = Repo.get(User, id)
+ assert user.is_active
+ end
+
+ test "user is not activated" do
+ %{id: id, nickname: nickname} = insert(:user, is_active: false)
+
+ assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message == "Successfully activated #{nickname}"
+
+ user = Repo.get(User, id)
+ assert user.is_active
+ end
+
+ test "no user to activate" do
+ Mix.Tasks.Pleroma.User.run(["activate", "foo"])
+
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No user"
+ end
+ end
+
describe "search" do
test "it returns users matching" do
user = insert(:user)
@@ -503,7 +504,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
moot = insert(:user, nickname: "moot")
kawen = insert(:user, nickname: "kawen", name: "fediverse expert moon")
- {:ok, user} = User.follow(user, moon)
+ {:ok, user, moon} = User.follow(user, moon)
assert [moon.id, kawen.id] == User.Search.search("moon") |> Enum.map(& &1.id)
@@ -579,29 +580,29 @@ defmodule Mix.Tasks.Pleroma.UserTest do
describe "bulk confirm and unconfirm" do
test "confirm all" do
- user1 = insert(:user, confirmation_pending: true)
- user2 = insert(:user, confirmation_pending: true)
+ user1 = insert(:user, is_confirmed: false)
+ user2 = insert(:user, is_confirmed: false)
- assert user1.confirmation_pending
- assert user2.confirmation_pending
+ refute user1.is_confirmed
+ refute user2.is_confirmed
Mix.Tasks.Pleroma.User.run(["confirm_all"])
user1 = User.get_cached_by_nickname(user1.nickname)
user2 = User.get_cached_by_nickname(user2.nickname)
- refute user1.confirmation_pending
- refute user2.confirmation_pending
+ assert user1.is_confirmed
+ assert user2.is_confirmed
end
test "unconfirm all" do
- user1 = insert(:user, confirmation_pending: false)
- user2 = insert(:user, confirmation_pending: false)
- admin = insert(:user, is_admin: true, confirmation_pending: false)
- mod = insert(:user, is_moderator: true, confirmation_pending: false)
+ user1 = insert(:user, is_confirmed: true)
+ user2 = insert(:user, is_confirmed: true)
+ admin = insert(:user, is_admin: true, is_confirmed: true)
+ mod = insert(:user, is_moderator: true, is_confirmed: true)
- refute user1.confirmation_pending
- refute user2.confirmation_pending
+ assert user1.is_confirmed
+ assert user2.is_confirmed
Mix.Tasks.Pleroma.User.run(["unconfirm_all"])
@@ -610,10 +611,10 @@ defmodule Mix.Tasks.Pleroma.UserTest do
admin = User.get_cached_by_nickname(admin.nickname)
mod = User.get_cached_by_nickname(mod.nickname)
- assert user1.confirmation_pending
- assert user2.confirmation_pending
- refute admin.confirmation_pending
- refute mod.confirmation_pending
+ refute user1.is_confirmed
+ refute user2.is_confirmed
+ assert admin.is_confirmed
+ assert mod.is_confirmed
end
end
end