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.migrate
- 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 @@ defmodule Pleroma.Object.Fetcher do
# Note: will create a Create activity, which we need internally at the moment.
def fetch_object_from_id(id, options \\ []) do
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
{:ok, nil} <- Pleroma.Web.ActivityPub.MRF.SimplePolicy.check_reject(uri),
{:ok, _} <- Pleroma.Web.ActivityPub.MRF.SimplePolicy.check_accept(uri),
@ -135,6 +137,9 @@ defmodule Pleroma.Object.Fetcher do
{:allowed_depth, false} ->
{:error, "Max thread distance exceeded."}
{:scheme, false} ->
{:error, "URI Scheme Invalid"}
{:containment, _} ->
{:error, "Object containment failed."}

View file

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

View file

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

View file

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

View file

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

View file

@ -3,7 +3,8 @@ defmodule Pleroma.Akkoma.Translators.ArgosTranslateTest do
import Mock
use Pleroma.DataCase, async: true
use Pleroma.DataCase, async: false
@moduletag :mocked
setup do
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
import ExUnit.CaptureLog
@moduletag :mocked
import Mock
alias Pleroma.ApplicationRequirements

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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