Example #1
0
    def test_option_global_only(self):
        """Test that `global_only` options are only set globally even if a profile specific scope is set."""
        option_name = 'user.email'
        option_value = '*****@*****.**'

        config = Config(self.config_filepath, self.config_dictionary)

        # Setting an option globally should be fine
        config.set_option(option_name, option_value, scope=None)
        self.assertEqual(config.get_option(option_name, scope=None, default=False), option_value)

        # Setting an option profile specific should actually not set it on the profile since it is `global_only`
        config.set_option(option_name, option_value, scope=None)
        self.assertEqual(config.get_option(option_name, scope=self.profile_name, default=False), None)
        self.assertEqual(config.get_option(option_name, scope=None, default=False), option_value)
Example #2
0
    def test_set_option_override(self):
        """Test that `global_only` options are only set globally even if a profile specific scope is set."""
        option_name = 'autofill.user.email'
        option_value_one = '*****@*****.**'
        option_value_two = '*****@*****.**'

        config = Config(self.config_filepath, self.config_dictionary)

        # Setting an option if it does not exist should work
        config.set_option(option_name, option_value_one)
        self.assertEqual(
            config.get_option(option_name, scope=None, default=False),
            option_value_one)

        # Setting it again will override it by default
        config.set_option(option_name, option_value_two)
        self.assertEqual(
            config.get_option(option_name, scope=None, default=False),
            option_value_two)

        # If we set override to False, it should not override, big surprise
        config.set_option(option_name, option_value_one, override=False)
        self.assertEqual(
            config.get_option(option_name, scope=None, default=False),
            option_value_two)
Example #3
0
    def test_option(self):
        """Test the setter, unsetter and getter of configuration options."""
        option_value = 131
        option_name = 'daemon.timeout'
        option = get_option(option_name)
        config = Config(self.config_filepath, self.config_dictionary)

        # Getting option that does not exist, should simply return the option default
        self.assertEqual(config.get_option(option_name, scope=self.profile_name), option.default)
        self.assertEqual(config.get_option(option_name, scope=None), option.default)

        # Unless we set default=False, in which case it should return None
        self.assertEqual(config.get_option(option_name, scope=self.profile_name, default=False), None)
        self.assertEqual(config.get_option(option_name, scope=None, default=False), None)

        # Setting an option profile configuration wide
        config.set_option(option_name, option_value)

        # Getting configuration wide should get new value but None for profile specific
        self.assertEqual(config.get_option(option_name, scope=None, default=False), option_value)
        self.assertEqual(config.get_option(option_name, scope=self.profile_name, default=False), None)

        # Setting an option profile specific
        config.set_option(option_name, option_value, scope=self.profile_name)
        self.assertEqual(config.get_option(option_name, scope=self.profile_name), option_value)

        # Unsetting profile specific
        config.unset_option(option_name, scope=self.profile_name)
        self.assertEqual(config.get_option(option_name, scope=self.profile_name, default=False), None)

        # Unsetting configuration wide
        config.unset_option(option_name, scope=None)
        self.assertEqual(config.get_option(option_name, scope=None, default=False), None)
        self.assertEqual(config.get_option(option_name, scope=None, default=True), option.default)

        # Setting a `None` like option
        option_value = 0
        config.set_option(option_name, option_value)
        self.assertEqual(config.get_option(option_name, scope=None, default=False), option_value)