forked from ungleich-public/cdist
Merge branch 'master' of git://github.com/asteven/cdist
This commit is contained in:
commit
9647933a40
20 changed files with 551 additions and 446 deletions
117
lib/cdist/test/object/__init__.py
Normal file
117
lib/cdist/test/object/__init__.py
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
# cdist is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# cdist is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
import shutil
|
||||
|
||||
import cdist.core
|
||||
|
||||
import os.path as op
|
||||
my_dir = op.abspath(op.dirname(__file__))
|
||||
fixtures = op.join(my_dir, 'fixtures')
|
||||
object_base_path = op.join(fixtures, 'object')
|
||||
type_base_path = op.join(fixtures, 'type')
|
||||
|
||||
class ObjectClassTestCase(unittest.TestCase):
|
||||
|
||||
def test_list_object_names(self):
|
||||
object_names = list(cdist.core.Object.list_object_names(object_base_path))
|
||||
self.assertEqual(object_names, ['__first/man', '__second/on-the', '__third/moon'])
|
||||
|
||||
def test_list_type_names(self):
|
||||
type_names = list(cdist.core.Object.list_type_names(object_base_path))
|
||||
self.assertEqual(type_names, ['__first', '__second', '__third'])
|
||||
|
||||
def test_list_objects(self):
|
||||
objects = list(cdist.core.Object.list_objects(object_base_path, type_base_path))
|
||||
objects_expected = [
|
||||
cdist.core.Object(cdist.core.Type(type_base_path, '__first'), object_base_path, 'man'),
|
||||
cdist.core.Object(cdist.core.Type(type_base_path, '__second'), object_base_path, 'on-the'),
|
||||
cdist.core.Object(cdist.core.Type(type_base_path, '__third'), object_base_path, 'moon'),
|
||||
]
|
||||
self.assertEqual(objects, objects_expected)
|
||||
|
||||
|
||||
class ObjectTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.cdist_type = cdist.core.Type(type_base_path, '__third')
|
||||
self.cdist_object = cdist.core.Object(self.cdist_type, object_base_path, 'moon')
|
||||
|
||||
def tearDown(self):
|
||||
self.cdist_object.changed = False
|
||||
self.cdist_object.prepared = False
|
||||
self.cdist_object.ran = False
|
||||
|
||||
def test_name(self):
|
||||
self.assertEqual(self.cdist_object.name, '__third/moon')
|
||||
|
||||
def test_object_id(self):
|
||||
self.assertEqual(self.cdist_object.object_id, 'moon')
|
||||
|
||||
def test_path(self):
|
||||
self.assertEqual(self.cdist_object.path, '__third/moon/.cdist')
|
||||
|
||||
def test_absolute_path(self):
|
||||
self.assertEqual(self.cdist_object.absolute_path, os.path.join(object_base_path, '__third/moon/.cdist'))
|
||||
|
||||
def test_code_local_path(self):
|
||||
self.assertEqual(self.cdist_object.code_local_path, '__third/moon/.cdist/code-local')
|
||||
|
||||
def test_code_remote_path(self):
|
||||
self.assertEqual(self.cdist_object.code_remote_path, '__third/moon/.cdist/code-remote')
|
||||
|
||||
def test_parameter_path(self):
|
||||
self.assertEqual(self.cdist_object.parameter_path, '__third/moon/.cdist/parameter')
|
||||
|
||||
def test_explorer_path(self):
|
||||
self.assertEqual(self.cdist_object.explorer_path, '__third/moon/.cdist/explorer')
|
||||
|
||||
def test_parameters(self):
|
||||
expected_parameters = {'planet': 'Saturn', 'name': 'Prometheus'}
|
||||
self.assertEqual(self.cdist_object.parameters, expected_parameters)
|
||||
|
||||
def test_requirements(self):
|
||||
expected = []
|
||||
self.assertEqual(list(self.cdist_object.requirements), expected)
|
||||
|
||||
def test_changed(self):
|
||||
self.assertFalse(self.cdist_object.changed)
|
||||
|
||||
def test_changed_after_changing(self):
|
||||
self.cdist_object.changed = True
|
||||
self.assertTrue(self.cdist_object.changed)
|
||||
|
||||
def test_prepared(self):
|
||||
self.assertFalse(self.cdist_object.prepared)
|
||||
|
||||
def test_prepared_after_changing(self):
|
||||
self.cdist_object.prepared = True
|
||||
self.assertTrue(self.cdist_object.prepared)
|
||||
|
||||
def test_ran(self):
|
||||
self.assertFalse(self.cdist_object.ran)
|
||||
|
||||
def test_ran_after_changing(self):
|
||||
self.cdist_object.ran = True
|
||||
self.assertTrue(self.cdist_object.ran)
|
||||
0
lib/cdist/test/object/fixtures/object/__first/.keep
Normal file
0
lib/cdist/test/object/fixtures/object/__first/.keep
Normal file
0
lib/cdist/test/object/fixtures/object/__second/.keep
Normal file
0
lib/cdist/test/object/fixtures/object/__second/.keep
Normal file
0
lib/cdist/test/object/fixtures/object/__third/.keep
Normal file
0
lib/cdist/test/object/fixtures/object/__third/.keep
Normal file
|
|
@ -0,0 +1 @@
|
|||
Prometheus
|
||||
|
|
@ -0,0 +1 @@
|
|||
Saturn
|
||||
0
lib/cdist/test/object/fixtures/type/__first/.keep
Normal file
0
lib/cdist/test/object/fixtures/type/__first/.keep
Normal file
0
lib/cdist/test/object/fixtures/type/__second/.keep
Normal file
0
lib/cdist/test/object/fixtures/type/__second/.keep
Normal file
0
lib/cdist/test/object/fixtures/type/__third/.keep
Normal file
0
lib/cdist/test/object/fixtures/type/__third/.keep
Normal file
|
|
@ -1,46 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
# cdist is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# cdist is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
import shutil
|
||||
|
||||
import os.path as op
|
||||
my_dir = op.abspath(op.dirname(__file__))
|
||||
base_path = op.join(my_dir, 'fixtures')
|
||||
|
||||
class ObjectTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# FIXME: use defined set of types for testing?
|
||||
# FIXME: generate object tree or use predefined?
|
||||
self.object_base_dir = tempfile.mkdtemp()
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.temp_dir)
|
||||
|
||||
'''
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(ObjectTestCase)
|
||||
|
||||
def suite():
|
||||
tests = []
|
||||
return unittest.TestSuite(map(ObjectTestCase, tests))
|
||||
'''
|
||||
|
|
@ -0,0 +1,146 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
# cdist is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# cdist is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import cdist.core
|
||||
|
||||
import os.path as op
|
||||
my_dir = op.abspath(op.dirname(__file__))
|
||||
fixtures = op.join(my_dir, 'fixtures')
|
||||
|
||||
|
||||
class TypeTestCase(unittest.TestCase):
|
||||
|
||||
def test_list_type_names(self):
|
||||
base_path = op.join(fixtures, 'list_types')
|
||||
type_names = cdist.core.Type.list_type_names(base_path)
|
||||
self.assertEqual(type_names, ['__first', '__second', '__third'])
|
||||
|
||||
def test_list_types(self):
|
||||
base_path = op.join(fixtures, 'list_types')
|
||||
types = list(cdist.core.Type.list_types(base_path))
|
||||
types_expected = [
|
||||
cdist.core.Type(base_path, '__first'),
|
||||
cdist.core.Type(base_path, '__second'),
|
||||
cdist.core.Type(base_path, '__third'),
|
||||
]
|
||||
self.assertEqual(types, types_expected)
|
||||
|
||||
def test_only_one_instance(self):
|
||||
base_path = fixtures
|
||||
cdist_type1 = cdist.core.Type(base_path, '__name_path')
|
||||
cdist_type2 = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(id(cdist_type1), id(cdist_type2))
|
||||
|
||||
def test_name(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.name, '__name_path')
|
||||
|
||||
def test_path(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.path, '__name_path')
|
||||
|
||||
def test_absolute_path(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.absolute_path, os.path.join(base_path, '__name_path'))
|
||||
|
||||
def test_manifest_path(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.manifest_path, os.path.join('__name_path', 'manifest'))
|
||||
|
||||
def test_explorer_path(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.explorer_path, os.path.join('__name_path', 'explorer'))
|
||||
|
||||
def test_gencode_local_path(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.gencode_local_path, os.path.join('__name_path', 'gencode-local'))
|
||||
|
||||
def test_gencode_remote_path(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.gencode_remote_path, os.path.join('__name_path', 'gencode-remote'))
|
||||
|
||||
def test_singleton_is_singleton(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__singleton')
|
||||
self.assertTrue(cdist_type.is_singleton)
|
||||
|
||||
def test_not_singleton_is_singleton(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__not_singleton')
|
||||
self.assertFalse(cdist_type.is_singleton)
|
||||
|
||||
def test_install_is_install(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__install')
|
||||
self.assertTrue(cdist_type.is_install)
|
||||
|
||||
def test_not_install_is_install(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__not_install')
|
||||
self.assertFalse(cdist_type.is_install)
|
||||
|
||||
def test_with_explorers(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__with_explorers')
|
||||
self.assertEqual(cdist_type.explorers, ['whatever'])
|
||||
|
||||
def test_without_explorers(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__without_explorers')
|
||||
self.assertEqual(cdist_type.explorers, [])
|
||||
|
||||
def test_with_required_parameters(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__with_required_parameters')
|
||||
self.assertEqual(cdist_type.required_parameters, ['required1', 'required2'])
|
||||
|
||||
def test_without_required_parameters(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__without_required_parameters')
|
||||
self.assertEqual(cdist_type.required_parameters, [])
|
||||
|
||||
def test_with_optional_parameters(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__with_optional_parameters')
|
||||
self.assertEqual(cdist_type.optional_parameters, ['optional1', 'optional2'])
|
||||
|
||||
def test_without_optional_parameters(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__without_optional_parameters')
|
||||
self.assertEqual(cdist_type.optional_parameters, [])
|
||||
|
||||
'''
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(ObjectTestCase)
|
||||
|
||||
def suite():
|
||||
tests = []
|
||||
return unittest.TestSuite(map(ObjectTestCase, tests))
|
||||
'''
|
||||
|
|
@ -1,146 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
# cdist is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# cdist is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import cdist.core
|
||||
|
||||
import os.path as op
|
||||
my_dir = op.abspath(op.dirname(__file__))
|
||||
fixtures = op.join(my_dir, 'fixtures')
|
||||
|
||||
|
||||
class TypeTestCase(unittest.TestCase):
|
||||
|
||||
def test_list_type_names(self):
|
||||
base_path = op.join(fixtures, 'list_types')
|
||||
type_names = cdist.core.Type.list_type_names(base_path)
|
||||
self.assertEqual(type_names, ['__first', '__second', '__third'])
|
||||
|
||||
def test_list_types(self):
|
||||
base_path = op.join(fixtures, 'list_types')
|
||||
types = list(cdist.core.Type.list_types(base_path))
|
||||
types_expected = [
|
||||
cdist.core.Type(base_path, '__first'),
|
||||
cdist.core.Type(base_path, '__second'),
|
||||
cdist.core.Type(base_path, '__third'),
|
||||
]
|
||||
self.assertEqual(types, types_expected)
|
||||
|
||||
def test_only_one_instance(self):
|
||||
base_path = fixtures
|
||||
cdist_type1 = cdist.core.Type(base_path, '__name_path')
|
||||
cdist_type2 = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(id(cdist_type1), id(cdist_type2))
|
||||
|
||||
def test_name(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.name, '__name_path')
|
||||
|
||||
def test_path(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.path, '__name_path')
|
||||
|
||||
def test_absolute_path(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.absolute_path, os.path.join(base_path, '__name_path'))
|
||||
|
||||
def test_manifest_path(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.manifest_path, os.path.join('__name_path', 'manifest'))
|
||||
|
||||
def test_explorer_path(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.explorer_path, os.path.join('__name_path', 'explorer'))
|
||||
|
||||
def test_gencode_local_path(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.gencode_local_path, os.path.join('__name_path', 'gencode-local'))
|
||||
|
||||
def test_gencode_remote_path(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__name_path')
|
||||
self.assertEqual(cdist_type.gencode_remote_path, os.path.join('__name_path', 'gencode-remote'))
|
||||
|
||||
def test_singleton_is_singleton(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__singleton')
|
||||
self.assertTrue(cdist_type.is_singleton)
|
||||
|
||||
def test_not_singleton_is_singleton(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__not_singleton')
|
||||
self.assertFalse(cdist_type.is_singleton)
|
||||
|
||||
def test_install_is_install(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__install')
|
||||
self.assertTrue(cdist_type.is_install)
|
||||
|
||||
def test_not_install_is_install(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__not_install')
|
||||
self.assertFalse(cdist_type.is_install)
|
||||
|
||||
def test_with_explorers(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__with_explorers')
|
||||
self.assertEqual(cdist_type.explorers, ['whatever'])
|
||||
|
||||
def test_without_explorers(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__without_explorers')
|
||||
self.assertEqual(cdist_type.explorers, [])
|
||||
|
||||
def test_with_required_parameters(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__with_required_parameters')
|
||||
self.assertEqual(cdist_type.required_parameters, ['required1', 'required2'])
|
||||
|
||||
def test_without_required_parameters(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__without_required_parameters')
|
||||
self.assertEqual(cdist_type.required_parameters, [])
|
||||
|
||||
def test_with_optional_parameters(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__with_optional_parameters')
|
||||
self.assertEqual(cdist_type.optional_parameters, ['optional1', 'optional2'])
|
||||
|
||||
def test_without_optional_parameters(self):
|
||||
base_path = fixtures
|
||||
cdist_type = cdist.core.Type(base_path, '__without_optional_parameters')
|
||||
self.assertEqual(cdist_type.optional_parameters, [])
|
||||
|
||||
'''
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(ObjectTestCase)
|
||||
|
||||
def suite():
|
||||
tests = []
|
||||
return unittest.TestSuite(map(ObjectTestCase, tests))
|
||||
'''
|
||||
Loading…
Add table
Add a link
Reference in a new issue