コード例 #1
0
    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
コード例 #2
0
    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')
コード例 #3
0
    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')
コード例 #4
0
    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)
コード例 #5
0
    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
コード例 #6
0
    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)
コード例 #7
0
    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)
コード例 #8
0
    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)
コード例 #9
0
    def test_get_values_with_no_settings_class(self):
        _dyna_controller.reset()

        with self.assertRaises(NoMatchingSettingsClass):
            val = dyna_value('BAD')
コード例 #10
0
 def test_register_nomatch(self):
     _dyna_controller.reset()
     register_dyna_settings(ChildOK_NoMatch())
     self.assertIsNone(_dyna_controller.detected_settings)
コード例 #11
0
 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)
コード例 #12
0
    def test_get_values_with_no_settings_class(self):
        _dyna_controller.reset()

        with self.assertRaises(NoMatchingSettingsClass):
            val = dyna_value('BAD')
コード例 #13
0
 def test_register_nomatch(self):
     _dyna_controller.reset()
     register_dyna_settings(ChildOK_NoMatch())
     self.assertIsNone(_dyna_controller.detected_settings)
コード例 #14
0
 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)