Ejemplo n.º 1
0
    def test_should_execute_command_show_help_for_missing_flag(self):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor("auth")

        # when
        self.auth_command.execute_command(command_descriptor)

        # then
        self.assertEqual(len(self.authentication_service_mock.mock_calls), 0)
Ejemplo n.º 2
0
    def test_should_execute_command_show_help_text(self, print_mock):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor("help")

        # when
        self.help_command.execute_command(command_descriptor)

        # then
        self.assertGreaterEqual(print_mock.call_count, 3)
Ejemplo n.º 3
0
    def test_should_execute_command_with_success(self):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor("stop app1")

        # when
        self.stop_application_command.execute_command(command_descriptor)

        # then
        self.domino_service_mock.execute_lifecycle_command.assert_called_once_with(DominoCommand.STOP, "app1")
Ejemplo n.º 4
0
    def test_should_execute_command_say_goodbye(self, print_mock):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor("exit")

        # when
        self.exit_command.execute_command(command_descriptor)

        # then
        print_mock.assert_called_once_with("Bye!")
Ejemplo n.º 5
0
    def run_loop(self) -> None:
        """
        Runs CLI command execution loop until an exit command terminates it.
        """
        while True:
            command = CommandDescriptor(input(_PROMPT))
            continue_loop = self._command_processor.execute_command(command)

            if not continue_loop:
                break
Ejemplo n.º 6
0
    def test_should_execute_command_to_start_wizard(self):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor("wizard wiz1")

        # when
        self.wizard_command.execute_command(command_descriptor)

        # then
        self.configuration_wizard_service_mock.run_wizard.assert_called_once_with("wiz1")
Ejemplo n.º 7
0
    def test_should_execute_command_fail_on_validation(self, print_mock):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor("stop")

        # when
        self.stop_application_command.execute_command(command_descriptor)

        # then
        self.assertEqual(self.domino_service_mock.call_count, 0)
        print_mock.assert_called_once_with("Application name required")
Ejemplo n.º 8
0
    def test_should_execute_command_with_success(self):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor("info app1")

        # when
        self.info_command.execute_command(command_descriptor)

        # then
        self.domino_service_mock.execute_lifecycle_command.assert_called_once_with(
            DominoCommand.INFO, "app1")
Ejemplo n.º 9
0
    def test_should_execute_command_fail_on_validation(self, print_mock):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor("wizard")

        # when
        self.wizard_command.execute_command(command_descriptor)

        # then
        print_mock.assert_called_once_with("Wizard name required")
        self.assertEqual(self.configuration_wizard_service_mock.show_available_wizards.call_count, 1)
        self.assertEqual(self.configuration_wizard_service_mock.run_wizard.call_count, 0)
Ejemplo n.º 10
0
    def test_should_execute_command_for_specified_version(self):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor(
            "deploy app1 1.0.0")

        # when
        self.deploy_application_command.execute_command(command_descriptor)

        # then
        self.domino_service_mock.execute_lifecycle_command.assert_called_once_with(
            DominoCommand.DEPLOY_VERSION, "app1", "1.0.0")
Ejemplo n.º 11
0
    def test_should_execute_default_command(self) -> None:

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor("unknown")

        # when
        result: bool = self.command_processor.execute_command(
            command_descriptor)

        # then
        self.assertTrue(result)
        self.assertTrue(self.command_default_mock.execute_command.called)
Ejemplo n.º 12
0
    def test_should_execute_command_for_opening_session(self):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor(
            "auth --open-session")

        # when
        self.auth_command.execute_command(command_descriptor)

        # then
        self.assertEqual(len(self.authentication_service_mock.mock_calls), 1)
        self.assertEqual(
            self.authentication_service_mock.open_session.call_count, 1)
Ejemplo n.º 13
0
    def test_should_execute_command_for_generating_token(self):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor(
            "auth --generate-token")

        # when
        self.auth_command.execute_command(command_descriptor)

        # then
        self.assertEqual(len(self.authentication_service_mock.mock_calls), 1)
        self.assertEqual(
            self.authentication_service_mock.generate_token.call_count, 1)
Ejemplo n.º 14
0
    def test_should_execute_command_for_encryption(self):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor(
            "auth --encrypt-password")

        # when
        self.auth_command.execute_command(command_descriptor)

        # then
        self.assertEqual(len(self.authentication_service_mock.mock_calls), 1)
        self.assertEqual(
            self.authentication_service_mock.encrypt_password.call_count, 1)
Ejemplo n.º 15
0
    def test_should_execute_exit_command(self) -> None:

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor("exit")
        self.command_exit_mock.is_applicable.return_value = True

        # when
        result: bool = self.command_processor.execute_command(
            command_descriptor)

        # then
        self.assertFalse(result)
        self.assertTrue(self.command_exit_mock.execute_command.called)
Ejemplo n.º 16
0
    def test_should_execute_command_fail_on_validation(self, print_mock):

        # given
        command_descriptor: CommandDescriptor = CommandDescriptor(
            "deploy app1")

        # when
        self.deploy_application_command.execute_command(command_descriptor)

        # then
        self.assertEqual(self.domino_service_mock.call_count, 0)
        print_mock.assert_called_once_with(
            "Application name and 'latest' keyword or explicit version is required"
        )
Ejemplo n.º 17
0
    def applicability_check(self, command_under_test: AbstractCommand,
                            applicable_for: str):

        # given
        for (command, expected_applicability
             ) in CommandBaseTest._prepare_parameters(applicable_for):
            with self.subTest("test_applicability",
                              command=command,
                              expected_applicability=expected_applicability):

                # when
                result: bool = command_under_test.is_applicable(
                    CommandDescriptor(command))

                # then
                self.assertEqual(result, expected_applicability)