Example #1
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)
Example #2
0
    def test_09(self):
        """
        Test Case 09:
        Read simple configuration from string.

        Test is passed if expected information is present within
        :py:class:`magrathea.utils.compat.CompConfigParser` object.
        """
        test_string = "[test]\nfoo = bar"
        obj = CompConfigParser()
        obj.read_string(test_string)
        self.assertTrue(obj.has_section('test'))
        self.assertTrue(obj.has_option('test', 'foo'))
        self.assertEqual(obj.get('test', 'foo'), 'bar')
Example #3
0
    def test_08(self):
        """
        Test Case 08:
        Read simple configuration from file.

        Test is passed if expected information is present within
        :py:class:`magrathea.utils.compat.CompConfigParser` object.
        """
        test_string = "[test]\nfoo = bar"
        fp, name = tempfile.mkstemp()
        os.write(fp, to_bytes(test_string))
        os.close(fp)
        obj = CompConfigParser()
        obj.read(name)
        os.unlink(name)
        self.assertTrue(obj.has_section('test'))
        self.assertTrue(obj.has_option('test', 'foo'))
        self.assertEqual(obj.get('test', 'foo'), 'bar')