From 74596982bed526e1f8af8bb93520679dfd061a2f Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 16 Dec 2020 17:52:22 +0100 Subject: [PATCH] Test support: Add tag to stub pipeline mocks --- test/support/conn_case.ex | 10 +++++----- test/support/data_case.ex | 31 ++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 47cb65a80..00500f444 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -125,11 +125,11 @@ defmodule Pleroma.Web.ConnCase do end if tags[:needs_streamer] do - start_supervised(%{ - id: Pleroma.Web.Streamer.registry(), - start: - {Registry, :start_link, [[keys: :duplicate, name: Pleroma.Web.Streamer.registry()]]} - }) + Pleroma.DataCase.start_streamer() + end + + if tags[:stubbed_pipeline] do + Pleroma.DataCase.stub_pipeline() end {:ok, conn: Phoenix.ConnTest.build_conn()} diff --git a/test/support/data_case.ex b/test/support/data_case.ex index d5456521c..21e026ef9 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -55,16 +55,37 @@ defmodule Pleroma.DataCase do end if tags[:needs_streamer] do - start_supervised(%{ - id: Pleroma.Web.Streamer.registry(), - start: - {Registry, :start_link, [[keys: :duplicate, name: Pleroma.Web.Streamer.registry()]]} - }) + start_streamer() + end + + if tags[:stubbed_pipeline] do + stub_pipeline() end :ok end + def start_streamer do + start_supervised(%{ + id: Pleroma.Web.Streamer.registry(), + start: {Registry, :start_link, [[keys: :duplicate, name: Pleroma.Web.Streamer.registry()]]} + }) + end + + def stub_pipeline do + Mox.stub_with(Pleroma.Web.ActivityPub.SideEffectsMock, Pleroma.Web.ActivityPub.SideEffects) + + Mox.stub_with( + Pleroma.Web.ActivityPub.ObjectValidatorMock, + Pleroma.Web.ActivityPub.ObjectValidator + ) + + Mox.stub_with(Pleroma.Web.ActivityPub.MRFMock, Pleroma.Web.ActivityPub.MRF) + Mox.stub_with(Pleroma.Web.ActivityPub.ActivityPubMock, Pleroma.Web.ActivityPub.ActivityPub) + Mox.stub_with(Pleroma.Web.FederatorMock, Pleroma.Web.Federator) + Mox.stub_with(Pleroma.ConfigMock, Pleroma.Config) + end + def ensure_local_uploader(context) do test_uploader = Map.get(context, :uploader, Pleroma.Uploaders.Local) uploader = Pleroma.Config.get([Pleroma.Upload, :uploader])