1 defmodule Pleroma.DataCase do
3 This module defines the setup for tests requiring
4 access to the application's data layer.
6 You may define functions here to be used as helpers in
9 Finally, if the test case interacts with the database,
10 it cannot be async. For this reason, every test runs
11 inside a transaction which is reset at the beginning
12 of the test unless the test case is marked as async.
15 use ExUnit.CaseTemplate
24 import Pleroma.DataCase
29 Cachex.clear(:user_cache)
30 :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
32 unless tags[:async] do
33 Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
39 def ensure_local_uploader(_context) do
40 uploader = Pleroma.Config.get([Pleroma.Upload, :uploader])
41 filters = Pleroma.Config.get([Pleroma.Upload, :filters])
43 unless uploader == Pleroma.Uploaders.Local || filters != [] do
44 Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
45 Pleroma.Config.put([Pleroma.Upload, :filters], [])
48 Pleroma.Config.put([Pleroma.Upload, :uploader], uploader)
49 Pleroma.Config.put([Pleroma.Upload, :filters], filters)
57 A helper that transform changeset errors to a map of messages.
59 changeset = Accounts.create_user(%{password: "short"})
60 assert "password is too short" in errors_on(changeset).password
61 assert %{password: ["password is too short"]} = errors_on(changeset)
64 def errors_on(changeset) do
65 Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
66 Enum.reduce(opts, message, fn {key, value}, acc ->
67 String.replace(acc, "%{#{key}}", to_string(value))