From a989b793de5790987e1a6a82a7da37be673b11f8 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Tue, 12 Dec 2023 19:35:08 +0400 Subject: [PATCH] Revert "Tests: fix more tests" This reverts commit 05352330bb536a13dee6df20c2d0b3fa75dbd50e. --- .../pleroma/application_requirements_test.exs | 21 +++---------------- test/pleroma/emails/mailer_test.exs | 21 +++---------------- test/pleroma/user/welcome_email_test.exs | 5 ----- .../controllers/admin_api_controller_test.exs | 6 +----- .../controllers/invite_controller_test.exs | 5 ----- .../controllers/account_controller_test.exs | 14 ++----------- .../twitter_api/password_controller_test.exs | 6 ------ .../web/twitter_api/twitter_api_test.exs | 13 ++---------- 8 files changed, 11 insertions(+), 80 deletions(-) diff --git a/test/pleroma/application_requirements_test.exs b/test/pleroma/application_requirements_test.exs index 9f55e5a1e..2f5b049a3 100644 --- a/test/pleroma/application_requirements_test.exs +++ b/test/pleroma/application_requirements_test.exs @@ -7,11 +7,9 @@ defmodule Pleroma.ApplicationRequirementsTest do import ExUnit.CaptureLog import Mock - import Mox alias Pleroma.ApplicationRequirements alias Pleroma.Repo - alias Pleroma.UnstubbedConfigMock, as: ConfigMock describe "check_repo_pool_size!/1" do test "raises if the pool size is unexpected" do @@ -39,11 +37,7 @@ test "doesn't raise if the pool size is unexpected but the respective flag is se test "warns if welcome email enabled but mail disabled" do clear_config([:welcome, :email, :enabled], true) - - ConfigMock - |> stub(:get, fn - [Pleroma.Emails.Mailer, :enabled] -> false - end) + clear_config([Pleroma.Emails.Mailer, :enabled], false) assert capture_log(fn -> assert Pleroma.ApplicationRequirements.verify!() == :ok @@ -65,11 +59,7 @@ test "warns if welcome email enabled but mail disabled" do test "warns if account confirmation is required but mailer isn't enabled" do clear_config([:instance, :account_activation_required], true) - - ConfigMock - |> stub(:get, fn - [Pleroma.Emails.Mailer, :enabled] -> false - end) + clear_config([Pleroma.Emails.Mailer, :enabled], false) assert capture_log(fn -> assert Pleroma.ApplicationRequirements.verify!() == :ok @@ -84,12 +74,7 @@ test "doesn't do anything if account confirmation is disabled" do test "doesn't do anything if account confirmation is required and mailer is enabled" do clear_config([:instance, :account_activation_required], true) - - ConfigMock - |> stub(:get, fn - [Pleroma.Emails.Mailer, :enabled] -> true - end) - + clear_config([Pleroma.Emails.Mailer, :enabled], true) assert Pleroma.ApplicationRequirements.verify!() == :ok end end diff --git a/test/pleroma/emails/mailer_test.exs b/test/pleroma/emails/mailer_test.exs index 947eecdbc..7a718c653 100644 --- a/test/pleroma/emails/mailer_test.exs +++ b/test/pleroma/emails/mailer_test.exs @@ -3,12 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Emails.MailerTest do - use Pleroma.DataCase, async: true - + use Pleroma.DataCase alias Pleroma.Emails.Mailer - alias Pleroma.UnstubbedConfigMock, as: ConfigMock - import Mox import Swoosh.TestAssertions @email %Swoosh.Email{ @@ -17,22 +14,10 @@ defmodule Pleroma.Emails.MailerTest do subject: "Pleroma test email", to: [{"Test User", "user1@example.com"}] } - - setup do - ConfigMock - |> stub(:get, fn - [Mailer, :enabled] -> true - end) - - :ok - end + setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true) test "not send email when mailer is disabled" do - ConfigMock - |> stub(:get, fn - [Mailer, :enabled] -> false - end) - + clear_config([Pleroma.Emails.Mailer, :enabled], false) Mailer.deliver(@email) :timer.sleep(100) diff --git a/test/pleroma/user/welcome_email_test.exs b/test/pleroma/user/welcome_email_test.exs index 9c070c117..a7b932c7e 100644 --- a/test/pleroma/user/welcome_email_test.exs +++ b/test/pleroma/user/welcome_email_test.exs @@ -14,11 +14,6 @@ defmodule Pleroma.User.WelcomeEmailTest do setup do: clear_config([:welcome]) - setup do - Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig) - :ok - end - describe "send_email/1" do test "send a welcome email" do user = insert(:user, name: "Jimm") diff --git a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs index 5742c4c16..a7ee8359d 100644 --- a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs @@ -991,11 +991,7 @@ test "it requires privileged role :users_manage_credentials", %{conn: conn} do describe "PATCH /resend_confirmation_email" do test "it resend emails for two users", %{conn: conn, admin: admin} do - ConfigMock - |> Mox.stub_with(Pleroma.Test.StaticConfig) - clear_config([:instance, :admin_privileges], [:users_manage_credentials]) - [first_user, second_user] = insert_pair(:user, is_confirmed: false) ret_conn = @@ -1083,7 +1079,7 @@ test "it requires privileged role :statistics_read", %{conn: conn} do describe "/api/pleroma/backups" do test "it creates a backup", %{conn: conn} do ConfigMock - |> Mox.stub_with(Pleroma.Test.StaticConfig) + |> Mox.stub_with(Pleroma.Config) admin = %{id: admin_id, nickname: admin_nickname} = insert(:user, is_admin: true) token = insert(:oauth_admin_token, user: admin) diff --git a/test/pleroma/web/admin_api/controllers/invite_controller_test.exs b/test/pleroma/web/admin_api/controllers/invite_controller_test.exs index bfb9304f8..8051cb2e9 100644 --- a/test/pleroma/web/admin_api/controllers/invite_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/invite_controller_test.exs @@ -5,11 +5,9 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do use Pleroma.Web.ConnCase, async: false - import Mox import Pleroma.Factory alias Pleroma.Repo - alias Pleroma.UnstubbedConfigMock, as: ConfigMock alias Pleroma.UserInviteToken setup do @@ -21,9 +19,6 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do |> assign(:user, admin) |> assign(:token, token) - ConfigMock - |> stub_with(Pleroma.Test.StaticConfig) - {:ok, %{admin: admin, token: token, conn: conn}} end diff --git a/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs index d1f92cc11..8f000760f 100644 --- a/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs @@ -5,13 +5,11 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do use Pleroma.Web.ConnCase - alias Pleroma.Test.StaticConfig, as: Config + alias Pleroma.Config alias Pleroma.Tests.ObanHelpers - alias Pleroma.UnstubbedConfigMock, as: ConfigMock alias Pleroma.User alias Pleroma.Web.CommonAPI - import Mox import Pleroma.Factory import Swoosh.TestAssertions @@ -27,15 +25,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do [user: user] end - setup do - ConfigMock - |> stub(:get, fn - [:instance, :account_activation_required] -> true - path -> Config.get(path) - end) - - :ok - end + setup do: clear_config([:instance, :account_activation_required], true) test "resend account confirmation email", %{conn: conn, user: user} do conn diff --git a/test/pleroma/web/twitter_api/password_controller_test.exs b/test/pleroma/web/twitter_api/password_controller_test.exs index af8b5d852..26cca1345 100644 --- a/test/pleroma/web/twitter_api/password_controller_test.exs +++ b/test/pleroma/web/twitter_api/password_controller_test.exs @@ -11,15 +11,9 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do alias Pleroma.Tests.ObanHelpers alias Pleroma.User alias Pleroma.Web.OAuth.Token - import Pleroma.Factory import Swoosh.TestAssertions - setup do - Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig) - :ok - end - describe "GET /api/pleroma/password_reset/token" do test "it returns error when token invalid", %{conn: conn} do response = diff --git a/test/pleroma/web/twitter_api/twitter_api_test.exs b/test/pleroma/web/twitter_api/twitter_api_test.exs index 0aa2e81ee..b3cd80146 100644 --- a/test/pleroma/web/twitter_api/twitter_api_test.exs +++ b/test/pleroma/web/twitter_api/twitter_api_test.exs @@ -16,11 +16,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do :ok end - setup do - Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig) - :ok - end - test "it registers a new user and returns the user." do data = %{ :username => "lain", @@ -53,10 +48,6 @@ test "it registers a new user with empty string in bio and returns the user" do test "it sends confirmation email if :account_activation_required is specified in instance config" do clear_config([:instance, :account_activation_required], true) - Pleroma.UnstubbedConfigMock - |> Mox.expect(:get, fn [:instance, :account_activation_required] -> true end) - |> Mox.expect(:get, fn [Pleroma.Emails.Mailer, :enabled] -> true end) - data = %{ :username => "lain", :email => "lain@wired.jp", @@ -73,8 +64,8 @@ test "it sends confirmation email if :account_activation_required is specified i email = Pleroma.Emails.UserEmail.account_confirmation_email(user) - notify_email = Pleroma.Test.StaticConfig.get([:instance, :notify_email]) - instance_name = Pleroma.Test.StaticConfig.get([:instance, :name]) + notify_email = Pleroma.Config.get([:instance, :notify_email]) + instance_name = Pleroma.Config.get([:instance, :name]) Swoosh.TestAssertions.assert_email_sent( from: {instance_name, notify_email},