Ejemplo n.º 1
0
class OptionMetaSuite(TestCase):
    """ tests for ro rw hidden options """
    def setUp(self):
        self.s = Settings()
        self.meta = self.s.option_meta_suffix()

        # hide real config-parser:
        self.s.p = Mock()

    def test_no_meta_option(self):
        s = self.s

        section = 'core'
        option = 'url'

        option_meta = option + self.meta
        # setup mock
        s.p.getboolean = Mock(return_value=True)

        # there is no META-record for our option:
        s.p.has_option = Mock(
            side_effect=lambda s, o: not (s == section and o == option_meta))

        # by default all options are writable and readable
        self.assertTrue(s.is_option_writable(section, option))
        self.assertTrue(s.is_option_readable(section, option))

    def test_non_writable(self):
        s = self.s

        section = 'core'
        option = 'url'

        def mock_get_meta_ro(s, o):
            if (s == section and o == option_meta):
                return 'ro'
            return 11

        option_meta = option + self.meta
        # setup mock
        s.p.has_option = Mock(return_value=True)
        s.p.get = Mock(side_effect=mock_get_meta_ro)

        # by default all options are writable and readable
        self.assertFalse(s.is_option_writable(section, option))
        self.assertTrue(s.is_option_readable(section, option))