Beispiel #1
0
    def test_gen_cmd(self, mock_cmd, command, monkeypatch, runway_context,
                     tmp_path):
        """Test gen_cmd."""
        # pylint: disable=no-member
        monkeypatch.setattr(Serverless, 'log_npm_command', MagicMock())
        monkeypatch.setattr(runway_context, 'no_color', False)
        mock_cmd.return_value = ['success']
        obj = Serverless(runway_context, tmp_path,
                         {'options': {
                             'args': ['--config', 'test']
                         }})
        expected_opts = [
            command, '--region', runway_context.env_region, '--stage',
            runway_context.env_name, '--config', 'test', '--extra-arg'
        ]

        assert obj.gen_cmd(command, args_list=['--extra-arg']) == ['success']
        mock_cmd.assert_called_once_with(command='sls',
                                         command_opts=expected_opts,
                                         path=tmp_path)
        obj.log_npm_command.assert_called_once_with(['success'])
        mock_cmd.reset_mock()

        obj.context.env_vars['CI'] = '1'
        monkeypatch.setattr(runway_context, 'no_color', True)
        expected_opts.append('--no-color')
        if command not in ['remove', 'print']:
            expected_opts.append('--conceal')
        assert obj.gen_cmd(command, args_list=['--extra-arg']) == ['success']
        mock_cmd.assert_called_once_with(command='sls',
                                         command_opts=expected_opts,
                                         path=tmp_path)
Beispiel #2
0
    def test_gen_cmd(
        self,
        command: str,
        mocker: MockerFixture,
        runway_context: MockRunwayContext,
        tmp_path: Path,
    ) -> None:
        """Test gen_cmd."""
        # pylint: disable=no-member
        mock_cmd = mocker.patch(
            "runway.module.serverless.generate_node_command",
            return_value=["success"])
        mocker.patch.object(runway_context, "no_color", False)
        obj = Serverless(runway_context,
                         module_root=tmp_path,
                         options={"args": ["--config", "test"]})
        expected_opts = [
            command,
            "--region",
            runway_context.env.aws_region,
            "--stage",
            runway_context.env.name,
            "--config",
            "test",
            "--extra-arg",
        ]

        assert obj.gen_cmd(command, args_list=["--extra-arg"]) == ["success"]
        mock_cmd.assert_called_once_with(command="sls",
                                         command_opts=expected_opts,
                                         logger=obj.logger,
                                         path=tmp_path)
        mock_cmd.reset_mock()

        obj.ctx.env.vars["CI"] = "1"
        mocker.patch.object(runway_context, "no_color", True)
        expected_opts.append("--no-color")
        if command not in ["remove", "print"]:
            expected_opts.append("--conceal")
        assert obj.gen_cmd(command, args_list=["--extra-arg"]) == ["success"]
        mock_cmd.assert_called_once_with(command="sls",
                                         command_opts=expected_opts,
                                         logger=obj.logger,
                                         path=tmp_path)
Beispiel #3
0
    def test_gen_cmd(self, mock_cmd, command, monkeypatch, runway_context,
                     tmp_path):
        """Test gen_cmd."""
        # pylint: disable=no-member
        monkeypatch.setattr(runway_context, "no_color", False)
        mock_cmd.return_value = ["success"]
        obj = Serverless(runway_context, tmp_path,
                         {"options": {
                             "args": ["--config", "test"]
                         }})
        expected_opts = [
            command,
            "--region",
            runway_context.env_region,
            "--stage",
            runway_context.env_name,
            "--config",
            "test",
            "--extra-arg",
        ]

        assert obj.gen_cmd(command, args_list=["--extra-arg"]) == ["success"]
        mock_cmd.assert_called_once_with(command="sls",
                                         command_opts=expected_opts,
                                         logger=obj.logger,
                                         path=tmp_path)
        mock_cmd.reset_mock()

        obj.context.env_vars["CI"] = "1"
        monkeypatch.setattr(runway_context, "no_color", True)
        expected_opts.append("--no-color")
        if command not in ["remove", "print"]:
            expected_opts.append("--conceal")
        assert obj.gen_cmd(command, args_list=["--extra-arg"]) == ["success"]
        mock_cmd.assert_called_once_with(command="sls",
                                         command_opts=expected_opts,
                                         logger=obj.logger,
                                         path=tmp_path)