def test_environ_var_trump_fail(self): """ Verifies that if Trump is true, environment doesn't have the variable, production_value doesn't define it, and the class does not either, then exception is raised. :return: """ _dyna_controller.reset() register_dyna_settings(EnvSettingTrue()) with self.assertRaises(NoMatchingSettingsClass): bad = dyna_value('VOODOOUDO', production_value=None) print bad
def test_get_values(self): _dyna_controller.reset() register_dyna_settings(ChildOK_Match()) register_dyna_settings(ChildOK_NoMatch()) val = dyna_value('A', production_value='x') self.assertEqual(val, 'a') val = dyna_value('B', production_value='x') self.assertEqual(val, 'b') val = dyna_value('UNDEFINED', production_value='prod') self.assertEqual(val, 'prod')
def test_environ_var_trump_no_env_var(self): """ Verify that if trump is True but the environment var is not defined we'll still pick up the value if the class instance has defined it :return: """ _dyna_controller.reset() register_dyna_settings(EnvSettingTrue()) path = dyna_value('AINT_THAR', production_value=None) self.assertTrue(path)
def test_environ_var_trump_instance(self): """ Verify that, with a DynaSettings instance registered that sets trump True it behaves properly by obtaining the value from the environment variable. Should ignore both the production_value and the settings class definition. :return: """ _dyna_controller.reset() self.assertFalse(_dyna_controller.environ_vars_trump) register_dyna_settings(EnvSettingTrue()) import os path = os.environ.get('PATH') self.assertTrue(path) path_from_settings = dyna_value('PATH', production_value='Internal path') self.assertTrue(path_from_settings) self.assertEqual(path_from_settings, path)
def test_get_values_with_no_settings_class(self): _dyna_controller.reset() with self.assertRaises(NoMatchingSettingsClass): val = dyna_value('BAD')
def test_register_nomatch(self): _dyna_controller.reset() register_dyna_settings(ChildOK_NoMatch()) self.assertIsNone(_dyna_controller.detected_settings)
def test_register_match(self): _dyna_controller.reset() instance = ChildOK_Match() register_dyna_settings(instance) register_dyna_settings(ChildOK_NoMatch()) self.assertEqual(_dyna_controller.detected_settings, instance)