logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

transfer_task_test.exs (4239B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Config.TransferTaskTest do
  5. use Pleroma.DataCase
  6. import ExUnit.CaptureLog
  7. import Pleroma.Factory
  8. alias Pleroma.Config.TransferTask
  9. setup do: clear_config(:configurable_from_database, true)
  10. test "transfer config values from db to env" do
  11. refute Application.get_env(:pleroma, :test_key)
  12. refute Application.get_env(:idna, :test_key)
  13. refute Application.get_env(:quack, :test_key)
  14. refute Application.get_env(:postgrex, :test_key)
  15. initial = Application.get_env(:logger, :level)
  16. insert(:config, key: :test_key, value: [live: 2, com: 3])
  17. insert(:config, group: :idna, key: :test_key, value: [live: 15, com: 35])
  18. insert(:config, group: :quack, key: :test_key, value: [:test_value1, :test_value2])
  19. insert(:config, group: :postgrex, key: :test_key, value: :value)
  20. insert(:config, group: :logger, key: :level, value: :debug)
  21. TransferTask.start_link([])
  22. assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
  23. assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
  24. assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
  25. assert Application.get_env(:logger, :level) == :debug
  26. assert Application.get_env(:postgrex, :test_key) == :value
  27. on_exit(fn ->
  28. Application.delete_env(:pleroma, :test_key)
  29. Application.delete_env(:idna, :test_key)
  30. Application.delete_env(:quack, :test_key)
  31. Application.delete_env(:postgrex, :test_key)
  32. Application.put_env(:logger, :level, initial)
  33. end)
  34. end
  35. test "transfer config values for 1 group and some keys" do
  36. level = Application.get_env(:quack, :level)
  37. meta = Application.get_env(:quack, :meta)
  38. insert(:config, group: :quack, key: :level, value: :info)
  39. insert(:config, group: :quack, key: :meta, value: [:none])
  40. TransferTask.start_link([])
  41. assert Application.get_env(:quack, :level) == :info
  42. assert Application.get_env(:quack, :meta) == [:none]
  43. default = Pleroma.Config.Holder.default_config(:quack, :webhook_url)
  44. assert Application.get_env(:quack, :webhook_url) == default
  45. on_exit(fn ->
  46. Application.put_env(:quack, :level, level)
  47. Application.put_env(:quack, :meta, meta)
  48. end)
  49. end
  50. test "transfer config values with full subkey update" do
  51. clear_config(:emoji)
  52. clear_config(:assets)
  53. insert(:config, key: :emoji, value: [groups: [a: 1, b: 2]])
  54. insert(:config, key: :assets, value: [mascots: [a: 1, b: 2]])
  55. TransferTask.start_link([])
  56. emoji_env = Application.get_env(:pleroma, :emoji)
  57. assert emoji_env[:groups] == [a: 1, b: 2]
  58. assets_env = Application.get_env(:pleroma, :assets)
  59. assert assets_env[:mascots] == [a: 1, b: 2]
  60. end
  61. describe "pleroma restart" do
  62. setup do
  63. on_exit(fn -> Restarter.Pleroma.refresh() end)
  64. end
  65. test "don't restart if no reboot time settings were changed" do
  66. clear_config(:emoji)
  67. insert(:config, key: :emoji, value: [groups: [a: 1, b: 2]])
  68. refute String.contains?(
  69. capture_log(fn -> TransferTask.start_link([]) end),
  70. "pleroma restarted"
  71. )
  72. end
  73. test "on reboot time key" do
  74. clear_config(:chat)
  75. insert(:config, key: :chat, value: [enabled: false])
  76. assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
  77. end
  78. test "on reboot time subkey" do
  79. clear_config(Pleroma.Captcha)
  80. insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
  81. assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
  82. end
  83. test "don't restart pleroma on reboot time key and subkey if there is false flag" do
  84. clear_config(:chat)
  85. clear_config(Pleroma.Captcha)
  86. insert(:config, key: :chat, value: [enabled: false])
  87. insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
  88. refute String.contains?(
  89. capture_log(fn -> TransferTask.load_and_update_env([], false) end),
  90. "pleroma restarted"
  91. )
  92. end
  93. end
  94. end