From 45f1808dc4ba6b605b30cd587cf9d9ee7d6af888 Mon Sep 17 00:00:00 2001 From: kneeyo1 Date: Mon, 13 May 2024 16:32:01 -0700 Subject: [PATCH] added test cases --- src/sentry/runner/commands/configoptions.py | 4 ++- tests/sentry/runner/commands/badsync.yaml | 2 ++ .../runner/commands/test_configoptions.py | 26 ++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/sentry/runner/commands/badsync.yaml diff --git a/src/sentry/runner/commands/configoptions.py b/src/sentry/runner/commands/configoptions.py index 18a26652a6f144..b122dff38ada0e 100644 --- a/src/sentry/runner/commands/configoptions.py +++ b/src/sentry/runner/commands/configoptions.py @@ -276,7 +276,9 @@ def sync(ctx: click.Context) -> None: presenter_delegator.unset(opt.name) else: if ( - options.can_update(opt.name, opt.value, options.UpdateChannel.AUTOMATOR) + options.can_update( + opt.name, options.get(opt.name), options.UpdateChannel.AUTOMATOR + ) == options.NotWritableReason.OPTION_ON_DISK ): continue diff --git a/tests/sentry/runner/commands/badsync.yaml b/tests/sentry/runner/commands/badsync.yaml new file mode 100644 index 00000000000000..67e2ab76dc78ef --- /dev/null +++ b/tests/sentry/runner/commands/badsync.yaml @@ -0,0 +1,2 @@ +options: + set_on_disk_option: 'hello' diff --git a/tests/sentry/runner/commands/test_configoptions.py b/tests/sentry/runner/commands/test_configoptions.py index c3ba7eeb52e2d8..5ce2c6d1fcf0ec 100644 --- a/tests/sentry/runner/commands/test_configoptions.py +++ b/tests/sentry/runner/commands/test_configoptions.py @@ -2,9 +2,15 @@ from pathlib import Path import pytest +from django.conf import settings from sentry import options -from sentry.options.manager import FLAG_AUTOMATOR_MODIFIABLE, FLAG_IMMUTABLE, UpdateChannel +from sentry.options.manager import ( + FLAG_AUTOMATOR_MODIFIABLE, + FLAG_IMMUTABLE, + FLAG_PRIORITIZE_DISK, + UpdateChannel, +) from sentry.runner.commands.configoptions import configoptions from sentry.runner.commands.presenters.consolepresenter import ConsolePresenter from sentry.testutils.cases import CliTestCase @@ -24,6 +30,12 @@ def register_options(self) -> Generator[None, None, None]: options.register("change_channel_option", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE) options.register("to_unset_option", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE) options.register("invalid_type", default=15, flags=FLAG_AUTOMATOR_MODIFIABLE) + options.register( + "set_on_disk_option", + default="", + flags=FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE, + ) + settings.SENTRY_OPTIONS["set_on_disk_option"] = "test" yield @@ -36,6 +48,8 @@ def register_options(self) -> Generator[None, None, None]: options.unregister("change_channel_option") options.unregister("to_unset_option") options.unregister("invalid_type") + options.unregister("set_on_disk_option") + del settings.SENTRY_OPTIONS["set_on_disk_option"] @pytest.fixture(autouse=True) def set_options(self) -> None: @@ -184,6 +198,16 @@ def test_sync(self): assert not options.isset("to_unset_option") + def test_bad_sync(self): + rv = self.invoke( + "-f", + "tests/sentry/runner/commands/badsync.yaml", + "sync", + ) + assert rv.exit_code == 2, rv.output + + assert ConsolePresenter.ERROR_MSG % ("set_on_disk_option", "option_on_disk") in rv.output + def test_bad_patch(self): rv = self.invoke( "--file=tests/sentry/runner/commands/badpatch.yaml",