-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify BaseAppSettingsHelper.__init__() (#14)
Simplifying BaseAppSettingsHelper.__init__(): - Remed support for 'prefix', 'defaults_path' and 'deprecations' to be specified at initialisation - Simplified _set_prefix() - Updated _load_defaults() to set self._defaults_module_path itself and remove _set_defaults_module_path() - Renamed perepare_deprecation_data() to prepare_deprecation_data(), and reference the 'deprecations' class attribute directly, instead of setting and reading from a '_deprecations' attribute DeprecatedAppSetting changes: - In deprecation warning message formats, use '{removing_in_version}' instead of '{removed_in_version}' and use '{prefixed_setting_name}' and {prefixed_replacement_name}' instead of joining {prefix}, {setting_name} and {replacement_name} throughout - Renamed get_removed_in_version_text() to get_removing_in_version_text() - Added prefixed_setting_name() and prefixed_replacement_name() property methods - Updated BaseAppSettingsHelper._prepare_deprecation_data() to use get_prefix() when setting the prefix value for each DeprecatedAppSetting instance
- Loading branch information
Showing
4 changed files
with
99 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,34 @@ | ||
from django.test import TestCase | ||
|
||
from cogwheels.helpers import BaseAppSettingsHelper, DeprecatedAppSetting | ||
from cogwheels import BaseAppSettingsHelper | ||
|
||
|
||
class TestSettingsHelper(BaseAppSettingsHelper): | ||
defaults_path = 'cogwheels.tests.conf.defaults' | ||
prefix = 'TEST_' | ||
deprecations = () | ||
pass | ||
|
||
|
||
class TestHelperInit(TestCase): | ||
class TestSettingsHelperInit(TestCase): | ||
|
||
def test_providing_prefix_overrides_the_class_attribute_value(self): | ||
test_val = 'ABRACADABRA' | ||
self.assertEqual( | ||
TestSettingsHelper(prefix=test_val)._prefix, | ||
test_val | ||
) | ||
def setUp(self): | ||
# Reset TestSettingsHelper class attributes before each test | ||
TestSettingsHelper.defaults_path = 'cogwheels.tests.conf.defaults' | ||
TestSettingsHelper.prefix = None | ||
TestSettingsHelper.deprecations = () | ||
|
||
def test_prefix_value_is_converted_to_uppercase(self): | ||
def test_set_prefix_converts_specified_value_to_uppercase(self): | ||
lowercase_prefix = 'beep' | ||
uppercase_prefix = 'BEEP' | ||
self.assertEqual( | ||
TestSettingsHelper(prefix=lowercase_prefix)._prefix, | ||
uppercase_prefix | ||
) | ||
|
||
def test_prefix_attribute_never_has_trailing_underscores(self): | ||
self.assertEqual(TestSettingsHelper()._prefix, 'TEST') | ||
self.assertEqual(TestSettingsHelper(prefix="ABRACADABRA_")._prefix, 'ABRACADABRA') | ||
self.assertEqual(TestSettingsHelper(prefix="BEEP_BOOP___")._prefix, 'BEEP_BOOP') | ||
|
||
def test_providing_defaults_path_overrides_the_class_attribute_value(self): | ||
test_val = 'cogwheels' | ||
self.assertIs( | ||
TestSettingsHelper(defaults_path=test_val)._defaults_module_path, | ||
test_val | ||
) | ||
|
||
def test_providing_deprecations_overrides_the_class_attribute_value(self): | ||
test_val = ( | ||
DeprecatedAppSetting('STRING_SETTING'), | ||
) | ||
self.assertIs( | ||
TestSettingsHelper(deprecations=test_val)._deprecations, | ||
test_val | ||
) | ||
|
||
def test_raises_import_error_if_defaults_module_cannot_be_imported(self): | ||
|
||
TestSettingsHelper.prefix = lowercase_prefix | ||
obj = TestSettingsHelper() | ||
self.assertEqual(obj._prefix, uppercase_prefix) | ||
|
||
def test_set_prefix_strips_trailing_underscores_from_specified_value(self): | ||
TestSettingsHelper.prefix = 'TEST___' | ||
obj = TestSettingsHelper() | ||
self.assertEqual(obj._prefix, 'TEST') | ||
|
||
def test_importerror_raised_if_defaults_module_does_not_exist(self): | ||
TestSettingsHelper.defaults_path = 'invalid.module.path' | ||
with self.assertRaises(ImportError): | ||
TestSettingsHelper(defaults_path='invalid.module.path') | ||
TestSettingsHelper() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters