Tests: Fix all the tests.
This commit is contained in:
parent
c068a218ea
commit
6e3267d1bd
|
@ -145,7 +145,8 @@
|
||||||
|
|
||||||
config :pleroma, Pleroma.PromEx, disabled: true
|
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
|
if File.exists?("./config/test.secret.exs") do
|
||||||
import_config "test.secret.exs"
|
import_config "test.secret.exs"
|
||||||
|
|
|
@ -12,7 +12,9 @@ defmodule Pleroma.User.BackupTest do
|
||||||
|
|
||||||
alias Pleroma.Bookmark
|
alias Pleroma.Bookmark
|
||||||
alias Pleroma.Tests.ObanHelpers
|
alias Pleroma.Tests.ObanHelpers
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User.Backup
|
alias Pleroma.User.Backup
|
||||||
|
alias Pleroma.User.Backup.ProcessorMock
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Workers.BackupWorker
|
alias Pleroma.Workers.BackupWorker
|
||||||
|
|
||||||
|
@ -20,6 +22,14 @@ defmodule Pleroma.User.BackupTest do
|
||||||
clear_config([Pleroma.Upload, :uploader])
|
clear_config([Pleroma.Upload, :uploader])
|
||||||
clear_config([Backup, :limit_days])
|
clear_config([Backup, :limit_days])
|
||||||
clear_config([Pleroma.Emails.Mailer, :enabled], true)
|
clear_config([Pleroma.Emails.Mailer, :enabled], true)
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> Mox.stub_with(Pleroma.Config)
|
||||||
|
|
||||||
|
ProcessorMock
|
||||||
|
|> Mox.stub_with(Pleroma.User.Backup.Processor)
|
||||||
|
|
||||||
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it does not requrie enabled email" do
|
test "it does not requrie enabled email" do
|
||||||
|
@ -302,24 +312,6 @@ test "it handles errors" do
|
||||||
end
|
end
|
||||||
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
|
describe "it uploads and deletes a backup archive" do
|
||||||
setup do
|
setup do
|
||||||
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
|
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
|
||||||
|
|
|
@ -15,6 +15,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
||||||
alias Pleroma.ModerationLog
|
alias Pleroma.ModerationLog
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.Tests.ObanHelpers
|
alias Pleroma.Tests.ObanHelpers
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
|
@ -1077,6 +1078,9 @@ test "it requires privileged role :statistics_read", %{conn: conn} do
|
||||||
|
|
||||||
describe "/api/pleroma/backups" do
|
describe "/api/pleroma/backups" do
|
||||||
test "it creates a backup", %{conn: conn} 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)
|
admin = %{id: admin_id, nickname: admin_nickname} = insert(:user, is_admin: true)
|
||||||
token = insert(:oauth_admin_token, user: admin)
|
token = insert(:oauth_admin_token, user: admin)
|
||||||
user = %{id: user_id, nickname: user_nickname} = insert(:user)
|
user = %{id: user_id, nickname: user_nickname} = insert(:user)
|
||||||
|
|
|
@ -7,10 +7,15 @@ defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
|
||||||
|
|
||||||
alias Pleroma.User.Backup
|
alias Pleroma.User.Backup
|
||||||
alias Pleroma.Web.PleromaAPI.BackupView
|
alias Pleroma.Web.PleromaAPI.BackupView
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
clear_config([Pleroma.Upload, :uploader])
|
clear_config([Pleroma.Upload, :uploader])
|
||||||
clear_config([Backup, :limit_days])
|
clear_config([Backup, :limit_days])
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> Mox.stub_with(Pleroma.Config)
|
||||||
|
|
||||||
oauth_access(["read:backups"])
|
oauth_access(["read:backups"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue