logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: 6e3267d1bd5494c8eec7a1b53062f1b51cebf5d6
parent c068a218eac02044cb5823abb1917051e1815b4f
Author: Lain Soykaf <lain@lain.com>
Date:   Sun, 10 Dec 2023 19:19:56 +0400

Tests: Fix all the tests.

Diffstat:

Mconfig/test.exs3++-
Mtest/pleroma/user/backup_test.exs28++++++++++------------------
Mtest/pleroma/web/admin_api/controllers/admin_api_controller_test.exs4++++
Mtest/pleroma/web/pleroma_api/controllers/backup_controller_test.exs5+++++
4 files changed, 21 insertions(+), 19 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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