Tag Mock-tests as "mocked" and run them seperately

This commit is contained in:
FloatingGhost 2023-08-04 12:50:50 +01:00
parent 9aaf5c9332
commit 64e233ca20
49 changed files with 58 additions and 7 deletions

View file

@ -110,4 +110,5 @@ pipeline:
- mix ecto.create - mix ecto.create
- mix ecto.migrate - mix ecto.migrate
- mkdir -p test/tmp - mkdir -p test/tmp
- mix test --preload-modules --exclude erratic --exclude federated - mix test --preload-modules --exclude erratic --exclude federated --exclude mocked
- mix test --preload-modules --only mocked

View file

@ -117,6 +117,8 @@ def refetch_object(%Object{data: %{"id" => id}} = object) do
# Note: will create a Create activity, which we need internally at the moment. # Note: will create a Create activity, which we need internally at the moment.
def fetch_object_from_id(id, options \\ []) do def fetch_object_from_id(id, options \\ []) do
with %URI{} = uri <- URI.parse(id), with %URI{} = uri <- URI.parse(id),
# let's check the URI is even vaguely valid first
{:scheme, true} <- {:scheme, uri.scheme == "http" or uri.scheme == "https"},
# If we have instance restrictions, apply them here to prevent fetching from unwanted instances # If we have instance restrictions, apply them here to prevent fetching from unwanted instances
{:ok, nil} <- Pleroma.Web.ActivityPub.MRF.SimplePolicy.check_reject(uri), {:ok, nil} <- Pleroma.Web.ActivityPub.MRF.SimplePolicy.check_reject(uri),
{:ok, _} <- Pleroma.Web.ActivityPub.MRF.SimplePolicy.check_accept(uri), {:ok, _} <- Pleroma.Web.ActivityPub.MRF.SimplePolicy.check_accept(uri),
@ -135,6 +137,9 @@ def fetch_object_from_id(id, options \\ []) do
{:allowed_depth, false} -> {:allowed_depth, false} ->
{:error, "Max thread distance exceeded."} {:error, "Max thread distance exceeded."}
{:scheme, false} ->
{:error, "URI Scheme Invalid"}
{:containment, _} -> {:containment, _} ->
{:error, "Object containment failed."} {:error, "Object containment failed."}

View file

@ -9,7 +9,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.MigrateTest do
test "ecto.migrate info message" do test "ecto.migrate info message" do
level = Logger.level() level = Logger.level()
Logger.configure(level: :warn) Logger.configure(level: :warning)
assert capture_log(fn -> assert capture_log(fn ->
Mix.Tasks.Pleroma.Ecto.Migrate.run() Mix.Tasks.Pleroma.Ecto.Migrate.run()

View file

@ -5,6 +5,7 @@
defmodule Mix.Tasks.Pleroma.UploadsTest do defmodule Mix.Tasks.Pleroma.UploadsTest do
alias Pleroma.Upload alias Pleroma.Upload
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
import Mock import Mock

View file

@ -15,6 +15,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
@moduletag :mocked
import ExUnit.CaptureIO import ExUnit.CaptureIO
import Mock import Mock

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Activity.Ir.TopicsTest do defmodule Pleroma.Activity.Ir.TopicsTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Activity.Ir.Topics alias Pleroma.Activity.Ir.Topics

View file

@ -3,7 +3,8 @@ defmodule Pleroma.Akkoma.Translators.ArgosTranslateTest do
import Mock import Mock
use Pleroma.DataCase, async: true use Pleroma.DataCase, async: false
@moduletag :mocked
setup do setup do
clear_config([:argos_translate, :command_argos_translate], "argos-translate_test") clear_config([:argos_translate, :command_argos_translate], "argos-translate_test")

View file

@ -6,6 +6,7 @@ defmodule Pleroma.ApplicationRequirementsTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
import ExUnit.CaptureLog import ExUnit.CaptureLog
@moduletag :mocked
import Mock import Mock
alias Pleroma.ApplicationRequirements alias Pleroma.ApplicationRequirements

View file

@ -428,13 +428,13 @@ test "complex keyword with nested mixed childs" do
test "common keyword" do test "common keyword" do
assert ConfigDB.to_elixir_types([ assert ConfigDB.to_elixir_types([
%{"tuple" => [":level", ":warn"]}, %{"tuple" => [":level", ":warning"]},
%{"tuple" => [":meta", [":all"]]}, %{"tuple" => [":meta", [":all"]]},
%{"tuple" => [":path", ""]}, %{"tuple" => [":path", ""]},
%{"tuple" => [":val", nil]}, %{"tuple" => [":val", nil]},
%{"tuple" => [":webhook_url", "https://hooks.slack.com/services/YOUR-KEY-HERE"]} %{"tuple" => [":webhook_url", "https://hooks.slack.com/services/YOUR-KEY-HERE"]}
]) == [ ]) == [
level: :warn, level: :warning,
meta: [:all], meta: [:all],
path: "", path: "",
val: nil, val: nil,

View file

@ -4,6 +4,7 @@
defmodule Pleroma.NotificationTest do defmodule Pleroma.NotificationTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
import Pleroma.Factory import Pleroma.Factory
import Mock import Mock

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Object.FetcherTest do defmodule Pleroma.Object.FetcherTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Instances alias Pleroma.Instances

View file

@ -6,6 +6,7 @@ defmodule Pleroma.Search.ElasticsearchTest do
require Pleroma.Constants require Pleroma.Constants
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
import Pleroma.Factory import Pleroma.Factory

View file

@ -6,6 +6,7 @@ defmodule Pleroma.Search.MeilisearchTest do
require Pleroma.Constants require Pleroma.Constants
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
import Pleroma.Factory import Pleroma.Factory

View file

@ -4,6 +4,7 @@
defmodule Pleroma.SignatureTest do defmodule Pleroma.SignatureTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
import ExUnit.CaptureLog import ExUnit.CaptureLog
import Pleroma.Factory import Pleroma.Factory

View file

@ -4,6 +4,8 @@
defmodule Pleroma.Upload.Filter.MogrifunTest do defmodule Pleroma.Upload.Filter.MogrifunTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
import Mock import Mock
alias Pleroma.Upload alias Pleroma.Upload

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Upload.Filter.MogrifyTest do defmodule Pleroma.Upload.Filter.MogrifyTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
import Mock import Mock
alias Pleroma.Upload.Filter alias Pleroma.Upload.Filter

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Uploaders.S3Test do defmodule Pleroma.Uploaders.S3Test do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
alias Pleroma.Uploaders.S3 alias Pleroma.Uploaders.S3

View file

@ -5,6 +5,7 @@
defmodule Pleroma.User.BackupTest do defmodule Pleroma.User.BackupTest do
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
import Mock import Mock
import Pleroma.Factory import Pleroma.Factory

View file

@ -6,6 +6,7 @@ defmodule Pleroma.UserRelationshipTest do
alias Pleroma.UserRelationship alias Pleroma.UserRelationship
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
import Mock import Mock
import Pleroma.Factory import Pleroma.Factory

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.ActivityPub.ActivityPubTest do defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
alias Pleroma.Activity alias Pleroma.Activity

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
use ExUnit.Case, async: false use ExUnit.Case, async: false
@moduletag :mocked
use Pleroma.Tests.Helpers use Pleroma.Tests.Helpers
alias Pleroma.HTTP alias Pleroma.HTTP

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.ActivityPub.PublisherTest do defmodule Pleroma.Web.ActivityPub.PublisherTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
import ExUnit.CaptureLog import ExUnit.CaptureLog
import Pleroma.Factory import Pleroma.Factory

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.ActivityPub.RelayTest do defmodule Pleroma.Web.ActivityPub.RelayTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.User alias Pleroma.User

View file

@ -5,6 +5,7 @@
defmodule Pleroma.Web.ActivityPub.SideEffectsTest do defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Notification alias Pleroma.Notification

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Notification alias Pleroma.Notification
alias Pleroma.Repo alias Pleroma.Repo

View file

@ -5,6 +5,7 @@
defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Object alias Pleroma.Object

View file

@ -5,7 +5,7 @@
defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Object alias Pleroma.Object
alias Pleroma.Tests.ObanHelpers alias Pleroma.Tests.ObanHelpers
@ -536,7 +536,7 @@ test "returns non-modified object" do
test "returns nil when cannot normalize object" do test "returns nil when cannot normalize object" do
assert capture_log(fn -> assert capture_log(fn ->
refute Transmogrifier.get_obj_helper("test-obj-id") refute Transmogrifier.get_obj_helper("test-obj-id")
end) =~ "Unsupported URI scheme" end) =~ "URI Scheme Invalid"
end end
@tag capture_log: true @tag capture_log: true

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
import Pleroma.Factory import Pleroma.Factory
import Mock import Mock

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.AdminAPI.UserControllerTest do defmodule Pleroma.Web.AdminAPI.UserControllerTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
import Mock import Mock

View file

@ -5,6 +5,7 @@
defmodule Pleroma.Web.CommonAPITest do defmodule Pleroma.Web.CommonAPITest do
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Conversation.Participation alias Pleroma.Conversation.Participation

View file

@ -10,6 +10,7 @@ defmodule Pleroma.Web.FederatorTest do
alias Pleroma.Workers.PublisherWorker alias Pleroma.Workers.PublisherWorker
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
import Pleroma.Factory import Pleroma.Factory

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
import Mock import Mock

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Endpoint alias Pleroma.Web.Endpoint

View file

@ -7,6 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
alias Pleroma.User alias Pleroma.User
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
import Mock import Mock
import Pleroma.Factory import Pleroma.Factory

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
alias Pleroma.User alias Pleroma.User
alias Pleroma.UserRelationship alias Pleroma.UserRelationship

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.MediaProxy.InvalidationTest do defmodule Pleroma.Web.MediaProxy.InvalidationTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
@moduletag :mocked
alias Pleroma.Web.MediaProxy.Invalidation alias Pleroma.Web.MediaProxy.Invalidation

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
import Mock import Mock

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.Web.OAuth.Token alias Pleroma.Web.OAuth.Token
import Pleroma.Factory import Pleroma.Factory

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
import Mock import Mock
import Tesla.Mock import Tesla.Mock

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
import Mock import Mock
import Tesla.Mock import Tesla.Mock

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
alias Pleroma.Tests.ObanHelpers alias Pleroma.Tests.ObanHelpers

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.Plugs.AdminSecretAuthenticationPlugTest do defmodule Pleroma.Web.Plugs.AdminSecretAuthenticationPlugTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
import Mock import Mock
import Pleroma.Factory import Pleroma.Factory

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
import Mock import Mock
@dir "test/tmp/instance_static" @dir "test/tmp/instance_static"

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.Web.Plugs.HTTPSignaturePlug alias Pleroma.Web.Plugs.HTTPSignaturePlug
alias Pleroma.Instances.Instance alias Pleroma.Instances.Instance

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.Plugs.OAuthScopesPlugTest do defmodule Pleroma.Web.Plugs.OAuthScopesPlugTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug

View file

@ -12,6 +12,7 @@ defmodule Pleroma.Web.Plugs.PlugHelperTest do
import Mock import Mock
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
describe "when plug is skipped, " do describe "when plug is skipped, " do
setup_with_mocks( setup_with_mocks(

View file

@ -15,6 +15,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
import Pleroma.Factory import Pleroma.Factory
setup_all do: clear_config([:static_fe, :enabled], true) setup_all do: clear_config([:static_fe, :enabled], true)
setup do: clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
setup %{conn: conn} do setup %{conn: conn} do
conn = put_req_header(conn, "accept", "text/html") conn = put_req_header(conn, "accept", "text/html")

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
use Pleroma.Web.ConnCase, async: false use Pleroma.Web.ConnCase, async: false
@moduletag :mocked
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
alias Pleroma.Tests.ObanHelpers alias Pleroma.Tests.ObanHelpers

View file

@ -5,6 +5,7 @@
defmodule Pleroma.Workers.ReceiverWorkerTest do defmodule Pleroma.Workers.ReceiverWorkerTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
@moduletag :mocked
import Mock import Mock
import Pleroma.Factory import Pleroma.Factory