1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ConnCase do
7 This module defines the test case to be used by
8 tests that require setting up a connection.
10 Such tests rely on `Phoenix.ConnTest` and also
11 import other functionality to make it easier
12 to build common datastructures and query the data layer.
14 Finally, if the test case interacts with the database,
15 it cannot be async. For this reason, every test runs
16 inside a transaction which is reset at the beginning
17 of the test unless the test case is marked as async.
20 use ExUnit.CaseTemplate
24 # Import conveniences for testing with connections
26 use Pleroma.Tests.Helpers
27 import Pleroma.Web.Router.Helpers
29 # The default endpoint for testing
30 @endpoint Pleroma.Web.Endpoint
35 Cachex.clear(:user_cache)
36 Cachex.clear(:object_cache)
37 :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
39 unless tags[:async] do
40 Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
43 if tags[:needs_streamer] do
44 start_supervised(Pleroma.Web.Streamer.supervisor())
47 {:ok, conn: Phoenix.ConnTest.build_conn()}