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.Tests.Helpers do
7 Helpers for use in tests.
10 defmacro clear_config(config_path) do
12 clear_config(unquote(config_path)) do
17 defmacro clear_config(config_path, do: yield) do
20 initial_setting = Pleroma.Config.get(unquote(config_path))
22 on_exit(fn -> Pleroma.Config.put(unquote(config_path), initial_setting) end)
28 defmacro clear_config_all(config_path) do
30 clear_config_all(unquote(config_path)) do
35 defmacro clear_config_all(config_path, do: yield) do
38 initial_setting = Pleroma.Config.get(unquote(config_path))
40 on_exit(fn -> Pleroma.Config.put(unquote(config_path), initial_setting) end)
46 defmacro __using__(_opts) do
48 import Pleroma.Tests.Helpers,
56 def collect_ids(collection) do
62 def refresh_record(%{id: id, __struct__: model} = _),
63 do: refresh_record(model, %{id: id})
65 def refresh_record(model, %{id: id} = _) do
66 Pleroma.Repo.get_by(model, id: id)
69 # Used for comparing json rendering during tests.
70 def render_json(view, template, assigns) do
71 assigns = Map.new(assigns)
73 view.render(template, assigns)
78 defmacro guards_config(config_path) do
80 initial_setting = Pleroma.Config.get(config_path)
82 Pleroma.Config.put(config_path, true)
83 on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)