Exemplo n.º 1
0
    def setUp(self):
        self.cmd = CommandContainer()
        self.sub_cmd_1 = CommandContainer()
        self.sub_cmd_2 = CommandContainer()

        self.cmd.add_command("sub_cmd_1", self.sub_cmd_1)
        self.cmd.add_command("sub_cmd_2", self.sub_cmd_2)
        pass
Exemplo n.º 2
0
    def setUp(self):
        self.cmd = CommandContainer()
        self.sub_cmd_1 = CommandContainer()
        self.sub_cmd_2 = CommandContainer()

        self.cmd.add_command("sub_cmd_1", self.sub_cmd_1)
        self.cmd.add_command("sub_cmd_2", self.sub_cmd_2)
        pass
Exemplo n.º 3
0
class TestBridgeGenerator(TestCase):

    def setUp(self):
        self.container = CommandContainer()
        self.container.add_command('test_resource', TestResource())

    def _commands(self):
        return KatelloBridgeGenerator(self.container).commands()

    def test_generator_loads_command(self):
        self.container.add_command('test_resource2', TestResource())
        assert_equals(len(self._commands()), 2)

    def test_generator_returns_list_of_commands(self):
        assert_is_instance(self._commands()[0], Command)

    def test_commands_has_name_set(self):
        assert_equals(self._commands()[0].name, 'test_resource')

    def test_commands_has_description_set(self):
        assert_equals(self._commands()[0].description, 'test_resource description')

    def test_commands_has_options_set(self):
        assert_equals(len(self._commands()[0].options), 1)

    def test_command_option_has_name_set(self):
        assert_equals(self._commands()[0].options[0].names.sort(), ['--name', '-n'].sort())

    def test_command_option_has_dest_set(self):
        assert_equals(self._commands()[0].options[0].dest, 'name')

    def test_command_option_has_name_set(self):
        assert_equals(self._commands()[0].options[0].names.sort(), ['--name', '-n'].sort())

    def test_command_option_has_description_set(self):
        assert_equals(self._commands()[0].options[0].description, "resource name (required)")

    def test_command_option_has_required_set(self):
        assert_true(self._commands()[0].options[0].required)

    def test_subcommands_are_recognized(self):
        self.container = CommandContainer()
        test_resource = TestResource()
        test_resource.add_command('test_resource_nested', TestResource())
        self.container.add_command('test_resource', test_resource)
        assert_equals(len(self._commands()[0].subcommands), 1)

    def test_actions_are_supported(self):
        self.container = CommandContainer()
        test_resource = TestResource()
        test_resource.add_command('test_action', TestAction())
        self.container.add_command('test_resource', test_resource)
        assert_equals(len(self._commands()[0].subcommands), 1)
Exemplo n.º 4
0
class AddSubcommandTest(TestCase):
    def setUp(self):
        self.cmd = CommandContainer()
        self.sub_cmd_1 = CommandContainer()
        self.sub_cmd_2 = CommandContainer()

        self.cmd.add_command("sub_cmd_1", self.sub_cmd_1)
        self.cmd.add_command("sub_cmd_2", self.sub_cmd_2)
        pass

    def test_it_returns_subcmd_count(self):
        self.assertTrue(len(self.cmd.get_command_names()) == 2)

    def test_it_returns_subcmd_names(self):
        self.assertTrue("sub_cmd_1" in self.cmd.get_command_names())
        self.assertTrue("sub_cmd_2" in self.cmd.get_command_names())
        self.assertFalse("sub_cmd_3" in self.cmd.get_command_names())

    def test_it_finds_subcmd(self):
        self.assertTrue(self.cmd.get_command("sub_cmd_1") == self.sub_cmd_1)

    def test_it_raises_exception_when_subcmd_not_noud(self):
        self.assertRaises(Exception, self.cmd.get_command, "unknown_sub_cmd")
Exemplo n.º 5
0
class AddSubcommandTest(TestCase):

    def setUp(self):
        self.cmd = CommandContainer()
        self.sub_cmd_1 = CommandContainer()
        self.sub_cmd_2 = CommandContainer()

        self.cmd.add_command("sub_cmd_1", self.sub_cmd_1)
        self.cmd.add_command("sub_cmd_2", self.sub_cmd_2)
        pass

    def test_it_returns_subcmd_count(self):
        self.assertTrue(len(self.cmd.get_command_names()) == 2)

    def test_it_returns_subcmd_names(self):
        self.assertTrue("sub_cmd_1" in self.cmd.get_command_names())
        self.assertTrue("sub_cmd_2" in self.cmd.get_command_names())
        self.assertFalse("sub_cmd_3" in self.cmd.get_command_names())

    def test_it_finds_subcmd(self):
        self.assertTrue(self.cmd.get_command("sub_cmd_1") == self.sub_cmd_1)

    def test_it_raises_exception_when_subcmd_not_noud(self):
        self.assertRaises(Exception, self.cmd.get_command, "unknown_sub_cmd")
Exemplo n.º 6
0
 def test_actions_are_supported(self):
     self.container = CommandContainer()
     test_resource = TestResource()
     test_resource.add_command('test_action', TestAction())
     self.container.add_command('test_resource', test_resource)
     assert_equals(len(self._commands()[0].subcommands), 1)
Exemplo n.º 7
0
 def test_subcommands_are_recognized(self):
     self.container = CommandContainer()
     test_resource = TestResource()
     test_resource.add_command('test_resource_nested', TestResource())
     self.container.add_command('test_resource', test_resource)
     assert_equals(len(self._commands()[0].subcommands), 1)
Exemplo n.º 8
0
 def setUp(self):
     self.container = CommandContainer()
     self.container.add_command('test_resource', TestResource())
Exemplo n.º 9
0
 def __init__(self):
     self.__collector = CommandContainer()