diff --git a/config/test.exs b/config/test.exs index 1d121e5e9..5724319a2 100644 --- a/config/test.exs +++ b/config/test.exs @@ -145,7 +145,8 @@ config :pleroma, :config_impl, Pleroma.UnstubbedConfigMock config :pleroma, Pleroma.PromEx, disabled: true -config Pleroma.User.Backup, :config_impl, Pleroma.UnstubbedConfigMock +# Mox definitions. Only read during compile time. +Application.put_env(Pleroma.User.Backup, :config_impl, Pleroma.UnstubbedConfigMock) if File.exists?("./config/test.secret.exs") do import_config "test.secret.exs" diff --git a/test/pleroma/user/backup_test.exs b/test/pleroma/user/backup_test.exs index 066bf6ba8..e5d4f3021 100644 --- a/test/pleroma/user/backup_test.exs +++ b/test/pleroma/user/backup_test.exs @@ -12,7 +12,9 @@ defmodule Pleroma.User.BackupTest do alias Pleroma.Bookmark alias Pleroma.Tests.ObanHelpers + alias Pleroma.UnstubbedConfigMock, as: ConfigMock alias Pleroma.User.Backup + alias Pleroma.User.Backup.ProcessorMock alias Pleroma.Web.CommonAPI alias Pleroma.Workers.BackupWorker @@ -20,6 +22,14 @@ defmodule Pleroma.User.BackupTest do clear_config([Pleroma.Upload, :uploader]) clear_config([Backup, :limit_days]) clear_config([Pleroma.Emails.Mailer, :enabled], true) + + ConfigMock + |> Mox.stub_with(Pleroma.Config) + + ProcessorMock + |> Mox.stub_with(Pleroma.User.Backup.Processor) + + :ok end test "it does not requrie enabled email" do @@ -302,24 +312,6 @@ defmodule Pleroma.User.BackupTest do end end - test "it handles unrecoverable exceptions" do - user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"}) - - assert {:ok, backup} = user |> Backup.new() |> Repo.insert() - - with_mock Backup, [:passthrough], do_process: fn _, _ -> raise "mock exception" end do - {:error, %{backup: backup, reason: :exit}} = Backup.process(backup) - - assert backup.state == :failed - end - - with_mock Backup, [:passthrough], do_process: fn _, _ -> Process.sleep(:timer.seconds(32)) end do - {:error, %{backup: backup, reason: :timeout}} = Backup.process(backup) - - assert backup.state == :failed - end - end - describe "it uploads and deletes a backup archive" do setup do clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com") 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 e1ab50542..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 @@ -15,6 +15,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do alias Pleroma.ModerationLog alias Pleroma.Repo alias Pleroma.Tests.ObanHelpers + alias Pleroma.UnstubbedConfigMock, as: ConfigMock alias Pleroma.User alias Pleroma.Web.CommonAPI @@ -1077,6 +1078,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do describe "/api/pleroma/backups" do test "it creates a backup", %{conn: conn} do + ConfigMock + |> Mox.stub_with(Pleroma.Config) + admin = %{id: admin_id, nickname: admin_nickname} = insert(:user, is_admin: true) token = insert(:oauth_admin_token, user: admin) user = %{id: user_id, nickname: user_nickname} = insert(:user) diff --git a/test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs index a758925b7..33e0ff84f 100644 --- a/test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs @@ -7,10 +7,15 @@ defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do alias Pleroma.User.Backup alias Pleroma.Web.PleromaAPI.BackupView + alias Pleroma.UnstubbedConfigMock, as: ConfigMock setup do clear_config([Pleroma.Upload, :uploader]) clear_config([Backup, :limit_days]) + + ConfigMock + |> Mox.stub_with(Pleroma.Config) + oauth_access(["read:backups"]) end