Exemplo n.º 1
0
    def test_06(self):
        """
        Test Case 06:
        Test if ``DEFAULT_`` values really are immutable by trying to overwrite DEFAULT_CHARSET (property).

        Test is passed if :py:exc:`KeyError` is raised.
        """
        obj = ApplicationConf.get_instance()
        with self.assertRaises(KeyError):
            obj.DEFAULT_CHARSET = 'iso-8859-1'
Exemplo n.º 2
0
    def test_08(self):
        """
        Test Case 08:
        Test if ``DEFAULT_`` values really are immutable by trying to delete DEFAULT_CHARSET (dictionary)

        Test is passed if :py:exc:`KeyError` is raised.
        """
        obj = ApplicationConf.get_instance()
        with self.assertRaises(KeyError):
            del obj['DEFAULT_CHARSET']
Exemplo n.º 3
0
    def test_04(self):
        """
        Test Case 04:
        Test the :py:class:`~magrathea.conf.ApplicationConf` class interface via dictionary interface.

        Test is passed if expected key is found and has the right value.
        """
        obj = ApplicationConf.get_instance()
        self.assertIn('DEFAULT_CHARSET', obj)
        self.assertEqual(obj['DEFAULT_CHARSET'], 'utf-8')
Exemplo n.º 4
0
    def test_03(self):
        """
        Test Case 03:
        Test the :py:class:`~magrathea.conf.ApplicationConf` class interface via property interface.

        Test is passed if expected property is found and has the right value.
        """
        obj = ApplicationConf.get_instance()
        self.assertTrue(hasattr(obj, 'DEFAULT_CHARSET'))
        self.assertEqual(obj.DEFAULT_CHARSET, 'utf-8')
Exemplo n.º 5
0
    def test_05(self):
        """
        Test Case 05:
        Test if the :py:class:`~magrathea.conf.ApplicationConf` class interface provides also a non-default.

        Test is passed if both, default an non-default keys exist and have the same value.
        """
        obj = ApplicationConf.get_instance()
        self.assertTrue(hasattr(obj, 'DEFAULT_CHARSET'))
        self.assertTrue(hasattr(obj, 'CHARSET'))
        self.assertEqual(obj.DEFAULT_CHARSET, obj.CHARSET)
Exemplo n.º 6
0
    def test_10(self):
        """
        Test Case 10:
        Test if non-default values are mutable by setting CHARSET (dictionary interface).

        Test is passed if no exception is raised and CHARSET points to the new value.
        """
        obj = ApplicationConf.get_instance()
        flag = True
        try:
            obj['CHARSET'] = 'iso-8859-1'
        except KeyError:
            flag = False
        self.assertTrue(flag)
        self.assertEqual(obj['CHARSET'], 'iso-8859-1')
Exemplo n.º 7
0
    def test_11(self):
        """
        Test Case 11:
        Test if non-default values can be reset by deleting them (dictionary interface).

        Test is passed if no exception is raised and CHARSET points to DEFAULT_CHARSET again.
        """
        obj = ApplicationConf.get_instance()
        flag = True
        try:
            obj['CHARSET'] = 'iso-8859-1'
            del obj['CHARSET']
        except KeyError:
            flag = False
        self.assertTrue(flag)
        self.assertEqual(obj['CHARSET'], obj['DEFAULT_CHARSET'])
Exemplo n.º 8
0
    def test_12(self):
        """
        Test Case 12:
        Test if independent values can be deleted (dictionary interface).

        Test is passed if no exception is raised and member is no longer present.
        """
        obj = ApplicationConf.get_instance()
        flag = True
        try:
            obj['foo'] = 'bar'
            self.assertIn('foo', obj)
            self.assertTrue(hasattr(obj, 'foo'))
            del obj['foo']
        except KeyError:
            flag = False
        self.assertTrue(flag)
        self.assertNotIn('foo', obj)
        self.assertFalse(hasattr(obj, 'foo'))
Exemplo n.º 9
0
    def test_07(self):
        """
        Test Case 07:
        Deploy a template into a temporary directory.

        Test is passed if deployment doesn't raise exception and all expected files exist.
        """
        def _filter(item):
            _file_map = {
                'makefile': 'Makefile',
                'cmakelists.txt': 'CMakeLists.txt',
                'readme': 'README'
            }
            if item in _file_map:
                return _file_map[item]
            return item

        td = tempfile.mkdtemp()
        obj = Template(template='planet', path=td)
        obj.deploy()
        cp = CompConfigParser(allow_no_value=True)
        cf = ApplicationConf.get_instance()
        with comp_open(os.path.join(get_conf('DEFAULT_TEMPLATE_PATH'), 'planet', '__init__.ini'), mode='r') as fp:
            content = fp.read()
            content = content.format(**cf)
        cp.read_string(content)
        flag = True
        if cp.has_section('dirs'):
            for directory in cp.options('dirs'):
                flag = flag and os.path.exists(os.path.join(obj.path, directory))
        if cp.has_section('files'):
            for file in cp.options('files'):
                flag = flag and os.path.exists(os.path.join(obj.path, _filter(file)))
        if cp.has_section('binaries'):
            for binary in cp.options('binaries'):
                flag = flag and os.path.exists(os.path.join(obj.path, _filter(binary)))
        shutil.rmtree(td)
        self.assertTrue(flag)