diff options
Diffstat (limited to 'test/support')
| -rw-r--r-- | test/support/captcha_mock.ex | 2 | ||||
| -rw-r--r-- | test/support/conn_case.ex | 6 | ||||
| -rw-r--r-- | test/support/data_case.ex | 6 | ||||
| -rw-r--r-- | test/support/factory.ex | 41 | ||||
| -rw-r--r-- | test/support/helpers.ex | 2 | ||||
| -rw-r--r-- | test/support/http_request_mock.ex | 6 | ||||
| -rw-r--r-- | test/support/mrf_module_mock.ex | 2 | ||||
| -rw-r--r-- | test/support/oban_helpers.ex | 42 | ||||
| -rw-r--r-- | test/support/web_push_http_client_mock.ex | 2 | 
9 files changed, 102 insertions, 7 deletions
| diff --git a/test/support/captcha_mock.ex b/test/support/captcha_mock.ex index ef4e68bc5..65ca6b3bd 100644 --- a/test/support/captcha_mock.ex +++ b/test/support/captcha_mock.ex @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Captcha.Mock do diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index ec5892ff5..9897f72ce 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.ConnCase do @@ -40,6 +40,10 @@ defmodule Pleroma.Web.ConnCase do        Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})      end +    if tags[:needs_streamer] do +      start_supervised(Pleroma.Web.Streamer.supervisor()) +    end +      {:ok, conn: Phoenix.ConnTest.build_conn()}    end  end diff --git a/test/support/data_case.ex b/test/support/data_case.ex index f3d98e7e3..4ffcbac9e 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.DataCase do @@ -39,6 +39,10 @@ defmodule Pleroma.DataCase do        Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})      end +    if tags[:needs_streamer] do +      start_supervised(Pleroma.Web.Streamer.supervisor()) +    end +      :ok    end diff --git a/test/support/factory.ex b/test/support/factory.ex index 719115003..4f3244025 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -71,6 +71,47 @@ defmodule Pleroma.Factory do      }    end +  def audio_factory(attrs \\ %{}) do +    text = sequence(:text, &"lain radio episode #{&1}") + +    user = attrs[:user] || insert(:user) + +    data = %{ +      "type" => "Audio", +      "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(), +      "artist" => "lain", +      "title" => text, +      "album" => "lain radio", +      "to" => ["https://www.w3.org/ns/activitystreams#Public"], +      "published" => DateTime.utc_now() |> DateTime.to_iso8601(), +      "actor" => user.ap_id, +      "length" => 180_000 +    } + +    %Pleroma.Object{ +      data: merge_attributes(data, Map.get(attrs, :data, %{})) +    } +  end + +  def listen_factory do +    audio = insert(:audio) + +    data = %{ +      "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(), +      "type" => "Listen", +      "actor" => audio.data["actor"], +      "to" => audio.data["to"], +      "object" => audio.data, +      "published" => audio.data["published"] +    } + +    %Pleroma.Activity{ +      data: data, +      actor: data["actor"], +      recipients: data["to"] +    } +  end +    def direct_note_factory do      user2 = insert(:user) diff --git a/test/support/helpers.ex b/test/support/helpers.ex index a601b3ec8..ce39dd9d8 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Tests.Helpers do diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index 231e7c498..5506c0626 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule HttpRequestMock do @@ -1004,6 +1004,10 @@ defmodule HttpRequestMock do      {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sjw.json")}}    end +  def get("https://patch.cx/users/rin", _, _, _) do +    {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}} +  end +    def get(url, query, body, headers) do      {:error,       "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{ diff --git a/test/support/mrf_module_mock.ex b/test/support/mrf_module_mock.ex index 12c7e22bc..632c7ff1d 100644 --- a/test/support/mrf_module_mock.ex +++ b/test/support/mrf_module_mock.ex @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule MRFModuleMock do diff --git a/test/support/oban_helpers.ex b/test/support/oban_helpers.ex new file mode 100644 index 000000000..72792c064 --- /dev/null +++ b/test/support/oban_helpers.ex @@ -0,0 +1,42 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Tests.ObanHelpers do +  @moduledoc """ +  Oban test helpers. +  """ + +  alias Pleroma.Repo + +  def perform_all do +    Oban.Job +    |> Repo.all() +    |> perform() +  end + +  def perform(%Oban.Job{} = job) do +    res = apply(String.to_existing_atom("Elixir." <> job.worker), :perform, [job.args, job]) +    Repo.delete(job) +    res +  end + +  def perform(jobs) when is_list(jobs) do +    for job <- jobs, do: perform(job) +  end + +  def member?(%{} = job_args, jobs) when is_list(jobs) do +    Enum.any?(jobs, fn job -> +      member?(job_args, job.args) +    end) +  end + +  def member?(%{} = test_attrs, %{} = attrs) do +    Enum.all?( +      test_attrs, +      fn {k, _v} -> member?(test_attrs[k], attrs[k]) end +    ) +  end + +  def member?(x, y), do: x == y +end diff --git a/test/support/web_push_http_client_mock.ex b/test/support/web_push_http_client_mock.ex index d8accd21c..1d6ccff7e 100644 --- a/test/support/web_push_http_client_mock.ex +++ b/test/support/web_push_http_client_mock.ex @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.WebPushHttpClientMock do | 
