Skip to content

Commit

Permalink
Update UnknownSettingNameError message text to explain why the settin…
Browse files Browse the repository at this point in the history
…g name is invalid, and include the text "for this helper" to reinforce that multiple helpers might exist (in case the wrong helper is being used)
  • Loading branch information
Andy Babic committed Aug 26, 2018
1 parent 696d8af commit 736f634
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions cogwheels/helpers/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,12 @@ def is_overridden(self, setting_name):

def _raise_invalid_setting_name_error(self, setting_name):
raise UnknownSettingNameError(
"'{}' is not a valid setting name. Valid settings names for "
"{} are: {}." .format(
setting_name,
self.__module__,
', '.join("'%s'" % v for v in self._defaults.keys())
"'{setting_name}' is not a valid setting name for this helper, as "
"no such variable can be found in {defaults_module_path}. Valid "
"setting names are: {valid_names}.".format(
setting_name=setting_name,
defaults_module_path=self._defaults_module_path,
valid_names=', '.join("'%s'" % v for v in self._defaults.keys())
)
)

Expand Down
8 changes: 4 additions & 4 deletions cogwheels/helpers/tests/test_helper_attribute_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestDirectAttributeShortcut(AppSettingTestCase):

@patch.object(BaseAppSettingsHelper, 'get')
def test_raises_unknownsettingnameerror_if_no_default_defined(self, mocked_method):
expected_message = "'UNKNOWN_SETTING' is not a valid setting name"
expected_message = "'UNKNOWN_SETTING' is not a valid setting name for this helper"
with self.assertRaisesRegex(UnknownSettingNameError, expected_message):
self.appsettingshelper.UNKNOWN_SETTING
mocked_method.assert_not_called()
Expand Down Expand Up @@ -41,7 +41,7 @@ class TestModelsShortcut(AppSettingTestCase):
"""
@patch.object(BaseAppSettingsHelper, 'get_model')
def test_raises_unknownsettingnameerror_if_no_default_defined(self, mocked_method):
expected_message = "'UNKNOWN_SETTING' is not a valid setting name"
expected_message = "'UNKNOWN_SETTING' is not a valid setting name for this helper"
with self.assertRaisesRegex(UnknownSettingNameError, expected_message):
self.appsettingshelper.models.UNKNOWN_SETTING
mocked_method.assert_not_called()
Expand Down Expand Up @@ -90,7 +90,7 @@ class TestModulesShortcut(AppSettingTestCase):
"""
@patch.object(BaseAppSettingsHelper, 'get_module')
def test_raises_unknownsettingnameerror_if_no_default_defined(self, mocked_method):
expected_message = "'UNKNOWN_SETTING' is not a valid setting name"
expected_message = "'UNKNOWN_SETTING' is not a valid setting name for this helper"
with self.assertRaisesRegex(UnknownSettingNameError, expected_message):
self.appsettingshelper.modules.UNKNOWN_SETTING
mocked_method.assert_not_called()
Expand Down Expand Up @@ -138,7 +138,7 @@ class TestObjectsShortcut(AppSettingTestCase):
"""
@patch.object(BaseAppSettingsHelper, 'get_object')
def test_raises_unknownsettingnameerror_if_setting_not_in_defaults(self, mocked_method):
expected_message = "'UNKNOWN_SETTING' is not a valid setting name"
expected_message = "'UNKNOWN_SETTING' is not a valid setting name for this helper"
with self.assertRaisesRegex(UnknownSettingNameError, expected_message):
self.appsettingshelper.objects.UNKNOWN_SETTING
mocked_method.assert_not_called()
Expand Down

0 comments on commit 736f634

Please sign in to comment.