From 2753285b7722fdb47f0ebb2180e997cf72f65d1a Mon Sep 17 00:00:00 2001 From: Alex S Date: Sun, 29 Sep 2019 11:17:38 +0300 Subject: config editing through database --- test/tasks/config_test.exs | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'test/tasks') diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index fab9d6e9a..055f678b9 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -9,16 +9,14 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do setup_all do Mix.shell(Mix.Shell.Process) - temp_file = "config/temp.exported_from_db.secret.exs" on_exit(fn -> Mix.shell(Mix.Shell.IO) Application.delete_env(:pleroma, :first_setting) Application.delete_env(:pleroma, :second_setting) - :ok = File.rm(temp_file) end) - {:ok, temp_file: temp_file} + :ok end clear_config_all([:instance, :dynamic_configuration]) do @@ -28,38 +26,44 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do test "settings are migrated to db" do assert Repo.all(Config) == [] - Application.put_env(:pleroma, :first_setting, key: "value", key2: [Pleroma.Repo]) - Application.put_env(:pleroma, :second_setting, key: "value2", key2: [Pleroma.Activity]) + Application.put_env(:pleroma, :first_setting, key: "value", key2: [Repo]) + Application.put_env(:pleroma, :second_setting, key: "value2", key2: ["Activity"]) Mix.Tasks.Pleroma.Config.run(["migrate_to_db"]) - first_db = Config.get_by_params(%{group: "pleroma", key: ":first_setting"}) - second_db = Config.get_by_params(%{group: "pleroma", key: ":second_setting"}) - refute Config.get_by_params(%{group: "pleroma", key: "Pleroma.Repo"}) + config1 = Config.get_by_params(%{group: ":pleroma", key: ":first_setting"}) + config2 = Config.get_by_params(%{group: ":pleroma", key: ":second_setting"}) + refute Config.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"}) - assert Config.from_binary(first_db.value) == [key: "value", key2: [Pleroma.Repo]] - assert Config.from_binary(second_db.value) == [key: "value2", key2: [Pleroma.Activity]] + assert Config.from_binary(config1.value) == [key: "value", key2: [Repo]] + assert Config.from_binary(config2.value) == [key: "value2", key2: ["Activity"]] end - test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do + test "settings are migrated to file and deleted from db" do + env = "temp" + config_file = "config/#{env}.exported_from_db.secret.exs" + + on_exit(fn -> + :ok = File.rm(config_file) + end) + Config.create(%{ - group: "pleroma", + group: ":pleroma", key: ":setting_first", - value: [key: "value", key2: [Pleroma.Activity]] + value: [key: "value", key2: ["Activity"]] }) Config.create(%{ - group: "pleroma", + group: ":pleroma", key: ":setting_second", - value: [key: "valu2", key2: [Pleroma.Repo]] + value: [key: "value2", key2: [Repo]] }) - Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "temp", "true"]) + Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", env, "-d"]) assert Repo.all(Config) == [] - assert File.exists?(temp_file) - {:ok, file} = File.read(temp_file) + file = File.read!(config_file) assert file =~ "config :pleroma, :setting_first," assert file =~ "config :pleroma, :setting_second," end -- cgit v1.2.3 From 0656816c77875d87d64d89e0e549f73104104cfb Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 6 Dec 2019 08:21:30 +0300 Subject: tests for setttings without an explicit key --- test/tasks/config_test.exs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/tasks') diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index 055f678b9..dfe3904ca 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -24,19 +24,24 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do end test "settings are migrated to db" do + initial = Application.get_all_env(:quack) + on_exit(fn -> Application.put_all_env([{:quack, initial}]) end) assert Repo.all(Config) == [] Application.put_env(:pleroma, :first_setting, key: "value", key2: [Repo]) Application.put_env(:pleroma, :second_setting, key: "value2", key2: ["Activity"]) + Application.put_env(:quack, :level, :info) Mix.Tasks.Pleroma.Config.run(["migrate_to_db"]) config1 = Config.get_by_params(%{group: ":pleroma", key: ":first_setting"}) config2 = Config.get_by_params(%{group: ":pleroma", key: ":second_setting"}) + config3 = Config.get_by_params(%{group: ":quack", key: ":level"}) refute Config.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"}) assert Config.from_binary(config1.value) == [key: "value", key2: [Repo]] assert Config.from_binary(config2.value) == [key: "value2", key2: ["Activity"]] + assert Config.from_binary(config3.value) == :info end test "settings are migrated to file and deleted from db" do @@ -59,6 +64,8 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do value: [key: "value2", key2: [Repo]] }) + Config.create(%{group: ":quack", key: ":level", value: :info}) + Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", env, "-d"]) assert Repo.all(Config) == [] @@ -66,6 +73,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do file = File.read!(config_file) assert file =~ "config :pleroma, :setting_first," assert file =~ "config :pleroma, :setting_second," + assert file =~ "config :quack, :level, :info" end test "load a settings with large values and pass to file", %{temp_file: temp_file} do -- cgit v1.2.3 From fea734ca703b686701b87c8c4c4969deb05d1f92 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 6 Dec 2019 17:50:53 +0300 Subject: errors on endpoints --- test/tasks/config_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/tasks') diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index dfe3904ca..74451a9e8 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -24,8 +24,8 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do end test "settings are migrated to db" do - initial = Application.get_all_env(:quack) - on_exit(fn -> Application.put_all_env([{:quack, initial}]) end) + initial = Application.get_env(:quack, :level) + on_exit(fn -> Application.put_env(:quack, :level, initial) end) assert Repo.all(Config) == [] Application.put_env(:pleroma, :first_setting, key: "value", key2: [Repo]) -- cgit v1.2.3 From e412d2f1525b2ee38b1544f69b9e8ba60419a348 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 10 Dec 2019 09:54:10 +0300 Subject: test fixes after rebase --- test/tasks/config_test.exs | 215 +++++++++++++++++++++++---------------------- 1 file changed, 110 insertions(+), 105 deletions(-) (limited to 'test/tasks') diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index 74451a9e8..c95db534d 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -44,115 +44,120 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do assert Config.from_binary(config3.value) == :info end - test "settings are migrated to file and deleted from db" do - env = "temp" - config_file = "config/#{env}.exported_from_db.secret.exs" - - on_exit(fn -> - :ok = File.rm(config_file) - end) - - Config.create(%{ - group: ":pleroma", - key: ":setting_first", - value: [key: "value", key2: ["Activity"]] - }) - - Config.create(%{ - group: ":pleroma", - key: ":setting_second", - value: [key: "value2", key2: [Repo]] - }) - - Config.create(%{group: ":quack", key: ":level", value: :info}) - - Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", env, "-d"]) - - assert Repo.all(Config) == [] - - file = File.read!(config_file) - assert file =~ "config :pleroma, :setting_first," - assert file =~ "config :pleroma, :setting_second," - assert file =~ "config :quack, :level, :info" - end - - test "load a settings with large values and pass to file", %{temp_file: temp_file} do - Config.create(%{ - group: "pleroma", - key: ":instance", - value: [ - name: "Pleroma", - email: "example@example.com", - notify_email: "noreply@example.com", - description: "A Pleroma instance, an alternative fediverse server", - limit: 5_000, - chat_limit: 5_000, - remote_limit: 100_000, - upload_limit: 16_000_000, - avatar_upload_limit: 2_000_000, - background_upload_limit: 4_000_000, - banner_upload_limit: 4_000_000, - poll_limits: %{ - max_options: 20, - max_option_chars: 200, - min_expiration: 0, - max_expiration: 365 * 24 * 60 * 60 - }, - registrations_open: true, - federating: true, - federation_incoming_replies_max_depth: 100, - federation_reachability_timeout_days: 7, - federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher], - allow_relay: true, - rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy, - public: true, - quarantined_instances: [], - managed_config: true, - static_dir: "instance/static/", - allowed_post_formats: ["text/plain", "text/html", "text/markdown", "text/bbcode"], - mrf_transparency: true, - mrf_transparency_exclusions: [], - autofollowed_nicknames: [], - max_pinned_statuses: 1, - no_attachment_links: true, - welcome_user_nickname: nil, - welcome_message: nil, - max_report_comment_size: 1000, - safe_dm_mentions: false, - healthcheck: false, - remote_post_retention_days: 90, - skip_thread_containment: true, - limit_to_local_content: :unauthenticated, - dynamic_configuration: false, - user_bio_length: 5000, - user_name_length: 100, - max_account_fields: 10, - max_remote_account_fields: 20, - account_field_name_length: 512, - account_field_value_length: 2048, - external_user_synchronization: true, - extended_nickname_format: true, - multi_factor_authentication: [ - totp: [ - # digits 6 or 8 - digits: 6, - period: 30 - ], - backup_codes: [ - number: 2, - length: 6 + describe "with deletion temp file" do + setup do + temp_file = "config/temp.exported_from_db.secret.exs" + + on_exit(fn -> + :ok = File.rm(temp_file) + end) + + {:ok, temp_file: temp_file} + end + + test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do + Config.create(%{ + group: ":pleroma", + key: ":setting_first", + value: [key: "value", key2: ["Activity"]] + }) + + Config.create(%{ + group: ":pleroma", + key: ":setting_second", + value: [key: "value2", key2: [Repo]] + }) + + Config.create(%{group: ":quack", key: ":level", value: :info}) + + Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"]) + + assert Repo.all(Config) == [] + + file = File.read!(temp_file) + assert file =~ "config :pleroma, :setting_first," + assert file =~ "config :pleroma, :setting_second," + assert file =~ "config :quack, :level, :info" + end + + test "load a settings with large values and pass to file", %{temp_file: temp_file} do + Config.create(%{ + group: ":pleroma", + key: ":instance", + value: [ + name: "Pleroma", + email: "example@example.com", + notify_email: "noreply@example.com", + description: "A Pleroma instance, an alternative fediverse server", + limit: 5_000, + chat_limit: 5_000, + remote_limit: 100_000, + upload_limit: 16_000_000, + avatar_upload_limit: 2_000_000, + background_upload_limit: 4_000_000, + banner_upload_limit: 4_000_000, + poll_limits: %{ + max_options: 20, + max_option_chars: 200, + min_expiration: 0, + max_expiration: 365 * 24 * 60 * 60 + }, + registrations_open: true, + federating: true, + federation_incoming_replies_max_depth: 100, + federation_reachability_timeout_days: 7, + federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher], + allow_relay: true, + rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy, + public: true, + quarantined_instances: [], + managed_config: true, + static_dir: "instance/static/", + allowed_post_formats: ["text/plain", "text/html", "text/markdown", "text/bbcode"], + mrf_transparency: true, + mrf_transparency_exclusions: [], + autofollowed_nicknames: [], + max_pinned_statuses: 1, + no_attachment_links: true, + welcome_user_nickname: nil, + welcome_message: nil, + max_report_comment_size: 1000, + safe_dm_mentions: false, + healthcheck: false, + remote_post_retention_days: 90, + skip_thread_containment: true, + limit_to_local_content: :unauthenticated, + dynamic_configuration: false, + user_bio_length: 5000, + user_name_length: 100, + max_account_fields: 10, + max_remote_account_fields: 20, + account_field_name_length: 512, + account_field_value_length: 2048, + external_user_synchronization: true, + extended_nickname_format: true, + multi_factor_authentication: [ + totp: [ + # digits 6 or 8 + digits: 6, + period: 30 + ], + backup_codes: [ + number: 2, + length: 6 + ] ] ] - ] - }) + }) - Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "temp", "true"]) + Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"]) - assert Repo.all(Config) == [] - assert File.exists?(temp_file) - {:ok, file} = File.read(temp_file) + assert Repo.all(Config) == [] + assert File.exists?(temp_file) + {:ok, file} = File.read(temp_file) - assert file == - "use Mix.Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n no_attachment_links: true,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n dynamic_configuration: false,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n" + assert file == + "use Mix.Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n no_attachment_links: true,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n dynamic_configuration: false,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n" + end end end -- cgit v1.2.3 From 7d128ca2083d83486a05d8c4456aa4090006e781 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 10 Jan 2020 19:34:19 +0300 Subject: dynamic_configuration renaming and moving it from instance settings --- test/tasks/config_test.exs | 7 +++---- test/tasks/instance_test.exs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'test/tasks') diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index c95db534d..b967dfdde 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -19,8 +19,8 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do :ok end - clear_config_all([:instance, :dynamic_configuration]) do - Pleroma.Config.put([:instance, :dynamic_configuration], true) + clear_config_all([:configurable_from_database]) do + Pleroma.Config.put([:configurable_from_database], true) end test "settings are migrated to db" do @@ -127,7 +127,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do remote_post_retention_days: 90, skip_thread_containment: true, limit_to_local_content: :unauthenticated, - dynamic_configuration: false, user_bio_length: 5000, user_name_length: 100, max_account_fields: 10, @@ -157,7 +156,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do {:ok, file} = File.read(temp_file) assert file == - "use Mix.Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n no_attachment_links: true,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n dynamic_configuration: false,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n" + "use Mix.Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n no_attachment_links: true,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n" end end end diff --git a/test/tasks/instance_test.exs b/test/tasks/instance_test.exs index 6d7eed4c1..d69275726 100644 --- a/test/tasks/instance_test.exs +++ b/test/tasks/instance_test.exs @@ -78,7 +78,7 @@ defmodule Pleroma.InstanceTest do assert generated_config =~ "database: \"dbname\"" assert generated_config =~ "username: \"dbuser\"" assert generated_config =~ "password: \"dbpass\"" - assert generated_config =~ "dynamic_configuration: true" + assert generated_config =~ "configurable_from_database: true" assert generated_config =~ "http: [ip: {127, 0, 0, 1}, port: 4000]" assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql() end -- cgit v1.2.3 From 59ba5c80b97b3cef2286716573d9697e82dd2a94 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Wed, 15 Jan 2020 17:10:33 +0300 Subject: little cleanup --- test/tasks/config_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/tasks') diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index b967dfdde..099b3d8e3 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -19,8 +19,8 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do :ok end - clear_config_all([:configurable_from_database]) do - Pleroma.Config.put([:configurable_from_database], true) + clear_config_all(:configurable_from_database) do + Pleroma.Config.put(:configurable_from_database, true) end test "settings are migrated to db" do -- cgit v1.2.3 From 29155137fdae15fccfaa68fb9c954e98078ce0c4 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Thu, 16 Jan 2020 08:50:27 +0300 Subject: renaming Pleroma.Web.AdminAPI.Config -> Pleroma.ConfigDB --- test/tasks/config_test.exs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'test/tasks') diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index 099b3d8e3..7759f0586 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -4,8 +4,8 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do use Pleroma.DataCase + alias Pleroma.ConfigDB alias Pleroma.Repo - alias Pleroma.Web.AdminAPI.Config setup_all do Mix.shell(Mix.Shell.Process) @@ -26,7 +26,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do test "settings are migrated to db" do initial = Application.get_env(:quack, :level) on_exit(fn -> Application.put_env(:quack, :level, initial) end) - assert Repo.all(Config) == [] + assert Repo.all(ConfigDB) == [] Application.put_env(:pleroma, :first_setting, key: "value", key2: [Repo]) Application.put_env(:pleroma, :second_setting, key: "value2", key2: ["Activity"]) @@ -34,14 +34,14 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do Mix.Tasks.Pleroma.Config.run(["migrate_to_db"]) - config1 = Config.get_by_params(%{group: ":pleroma", key: ":first_setting"}) - config2 = Config.get_by_params(%{group: ":pleroma", key: ":second_setting"}) - config3 = Config.get_by_params(%{group: ":quack", key: ":level"}) - refute Config.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"}) + config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"}) + config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"}) + config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"}) + refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"}) - assert Config.from_binary(config1.value) == [key: "value", key2: [Repo]] - assert Config.from_binary(config2.value) == [key: "value2", key2: ["Activity"]] - assert Config.from_binary(config3.value) == :info + assert ConfigDB.from_binary(config1.value) == [key: "value", key2: [Repo]] + assert ConfigDB.from_binary(config2.value) == [key: "value2", key2: ["Activity"]] + assert ConfigDB.from_binary(config3.value) == :info end describe "with deletion temp file" do @@ -56,23 +56,23 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do end test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do - Config.create(%{ + ConfigDB.create(%{ group: ":pleroma", key: ":setting_first", value: [key: "value", key2: ["Activity"]] }) - Config.create(%{ + ConfigDB.create(%{ group: ":pleroma", key: ":setting_second", value: [key: "value2", key2: [Repo]] }) - Config.create(%{group: ":quack", key: ":level", value: :info}) + ConfigDB.create(%{group: ":quack", key: ":level", value: :info}) Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"]) - assert Repo.all(Config) == [] + assert Repo.all(ConfigDB) == [] file = File.read!(temp_file) assert file =~ "config :pleroma, :setting_first," @@ -81,7 +81,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do end test "load a settings with large values and pass to file", %{temp_file: temp_file} do - Config.create(%{ + ConfigDB.create(%{ group: ":pleroma", key: ":instance", value: [ @@ -151,7 +151,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"]) - assert Repo.all(Config) == [] + assert Repo.all(ConfigDB) == [] assert File.exists?(temp_file) {:ok, file} = File.read(temp_file) -- cgit v1.2.3 From 60ba2339a244290f7353e8026032b1a5d185227c Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 17 Jan 2020 11:45:44 +0300 Subject: saving to DB only added by user settings --- test/tasks/config_test.exs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'test/tasks') diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index 7759f0586..ff921ecfa 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -4,6 +4,9 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do use Pleroma.DataCase + + import ExUnit.CaptureLog + alias Pleroma.ConfigDB alias Pleroma.Repo @@ -23,16 +26,17 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do Pleroma.Config.put(:configurable_from_database, true) end + test "warning if file with custom settings doesn't exist" do + assert capture_log(fn -> Mix.Tasks.Pleroma.Config.run(["migrate_to_db"]) end) =~ + "to migrate settings, you must define custom settings in config/test.secret.exs" + end + test "settings are migrated to db" do initial = Application.get_env(:quack, :level) on_exit(fn -> Application.put_env(:quack, :level, initial) end) assert Repo.all(ConfigDB) == [] - Application.put_env(:pleroma, :first_setting, key: "value", key2: [Repo]) - Application.put_env(:pleroma, :second_setting, key: "value2", key2: ["Activity"]) - Application.put_env(:quack, :level, :info) - - Mix.Tasks.Pleroma.Config.run(["migrate_to_db"]) + Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs") config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"}) config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"}) -- cgit v1.2.3 From efb8ef5abee1a8defa2bfba40ad1065db4c09ddf Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Sat, 18 Jan 2020 16:55:33 +0300 Subject: releases support --- test/tasks/config_test.exs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'test/tasks') diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index ff921ecfa..2e56e6cfe 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -5,8 +5,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do use Pleroma.DataCase - import ExUnit.CaptureLog - alias Pleroma.ConfigDB alias Pleroma.Repo @@ -26,9 +24,14 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do Pleroma.Config.put(:configurable_from_database, true) end - test "warning if file with custom settings doesn't exist" do - assert capture_log(fn -> Mix.Tasks.Pleroma.Config.run(["migrate_to_db"]) end) =~ - "to migrate settings, you must define custom settings in config/test.secret.exs" + test "error if file with custom settings doesn't exist" do + Mix.Tasks.Pleroma.Config.run(["migrate_to_db"]) + + assert_receive {:mix_shell, :info, + [ + "To migrate settings, you must define custom settings in config/test.secret.exs." + ]}, + 15 end test "settings are migrated to db" do @@ -159,8 +162,15 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do assert File.exists?(temp_file) {:ok, file} = File.read(temp_file) + header = + if Code.ensure_loaded?(Config.Reader) do + "import Config" + else + "use Mix.Config" + end + assert file == - "use Mix.Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n no_attachment_links: true,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n" + "#{header}\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n no_attachment_links: true,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n" end end end -- cgit v1.2.3