Ejemplo n.º 1
0
 def test_warn_on_boto_env_vars_no_warn(self, caplog: LogCaptureFixture,
                                        env_vars: Dict[str, str]) -> None:
     """Test warn_on_boto_env_vars no warn."""
     caplog.set_level(logging.WARNING, logger=MODULE)
     RunwayModuleNpm.warn_on_boto_env_vars(env_vars)
     assert ("AWS_DEFAULT_PROFILE environment variable is set "
             "during use of nodejs-based module and AWS_PROFILE is "
             "not set -- you likely want to set AWS_PROFILE instead"
             ) not in caplog.messages
Ejemplo n.º 2
0
 def test_warn_on_boto_env_vars(self, caplog: LogCaptureFixture) -> None:
     """Test warn_on_boto_env_vars."""
     caplog.set_level(logging.WARNING, logger=MODULE)
     RunwayModuleNpm.warn_on_boto_env_vars(
         {"AWS_DEFAULT_PROFILE": "something"})
     assert ("AWS_DEFAULT_PROFILE environment variable is set "
             "during use of nodejs-based module and AWS_PROFILE is "
             "not set -- you likely want to set AWS_PROFILE instead"
             ) in caplog.messages
Ejemplo n.º 3
0
 def test_check_for_npm_missing(self, caplog: LogCaptureFixture,
                                mocker: MockerFixture) -> None:
     """Test check_for_npm missing."""
     caplog.set_level(logging.ERROR, logger=MODULE)
     mock_which = mocker.patch(f"{MODULE}.which", return_value=False)
     with pytest.raises(NpmNotFound):
         RunwayModuleNpm.check_for_npm()
     mock_which.assert_called_once_with("npm")
     assert caplog.messages == [
         '"npm" not found in path or is not executable; please ensure it is '
         "installed correctly"
     ]
Ejemplo n.º 4
0
 def test_npm_install_install(
     self,
     caplog: LogCaptureFixture,
     colorize: bool,
     fake_process: FakeProcess,
     is_noninteractive: bool,
     mocker: MockerFixture,
     runway_context: MockRunwayContext,
     tmp_path: Path,
     use_ci: bool,
 ) -> None:
     """Test npm_install install."""
     caplog.set_level(logging.INFO, logger=MODULE)
     mocker.patch(f"{MODULE}.use_npm_ci", return_value=use_ci)
     mocker.patch.object(RunwayModuleNpm, "check_for_npm")
     mocker.patch.object(RunwayModuleNpm, "warn_on_boto_env_vars")
     runway_context.env.ci = is_noninteractive
     runway_context.env.vars["RUNWAY_COLORIZE"] = str(colorize)
     cmd: List[Any] = [NPM_BIN, "install"]
     if not colorize:
         cmd.append("--no-color")
     fake_process.register_subprocess(cmd, returncode=0)
     RunwayModuleNpm(runway_context, module_root=tmp_path).npm_install()
     assert "running npm install..." in caplog.messages
     assert fake_process.call_count(cmd) == 1
Ejemplo n.º 5
0
 def test_log_npm_command(
     self,
     caplog: LogCaptureFixture,
     mocker: MockerFixture,
     runway_context: MockRunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test log_npm_command."""
     caplog.set_level(logging.DEBUG, logger=MODULE)
     mock_format_npm_command_for_logging = mocker.patch(
         f"{MODULE}.format_npm_command_for_logging", return_value="success")
     mocker.patch.object(RunwayModuleNpm, "check_for_npm")
     mocker.patch.object(RunwayModuleNpm, "warn_on_boto_env_vars")
     obj = RunwayModuleNpm(runway_context, module_root=tmp_path)
     obj.log_npm_command(["test"])
     assert "node command: success" in caplog.messages
     mock_format_npm_command_for_logging.assert_called_once_with(["test"])
Ejemplo n.º 6
0
    def test_package_json_missing(
        self,
        caplog: LogCaptureFixture,
        mocker: MockerFixture,
        runway_context: MockRunwayContext,
        tmp_path: Path,
    ) -> None:
        """Test package_json_missing."""
        caplog.set_level(logging.DEBUG, logger=MODULE)
        mocker.patch.object(RunwayModuleNpm, "check_for_npm")
        mocker.patch.object(RunwayModuleNpm, "warn_on_boto_env_vars")
        obj = RunwayModuleNpm(context=runway_context, module_root=tmp_path)

        assert obj.package_json_missing()
        assert ["module is missing package.json"] == caplog.messages

        (tmp_path / "package.json").touch()
        assert not obj.package_json_missing()
Ejemplo n.º 7
0
 def test_init_npm_not_found(self, mocker: MockerFixture,
                             runway_context: MockRunwayContext,
                             tmp_path: Path) -> None:
     """Test __init__ raise NpmNotFound."""
     mock_check_for_npm = mocker.patch.object(RunwayModuleNpm,
                                              "check_for_npm",
                                              side_effect=NpmNotFound)
     mock_warn_on_boto_env_vars = mocker.patch.object(
         RunwayModuleNpm, "warn_on_boto_env_vars")
     with pytest.raises(NpmNotFound):
         RunwayModuleNpm(runway_context, module_root=tmp_path)
     mock_check_for_npm.assert_called_once()
     mock_warn_on_boto_env_vars.assert_not_called()
Ejemplo n.º 8
0
 def test_npm_install_skip(
     self,
     caplog: LogCaptureFixture,
     mocker: MockerFixture,
     runway_context: MockRunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test npm_install skip."""
     caplog.set_level(logging.INFO, logger=MODULE)
     mocker.patch.object(RunwayModuleNpm, "check_for_npm")
     mocker.patch.object(RunwayModuleNpm, "warn_on_boto_env_vars")
     RunwayModuleNpm(runway_context,
                     module_root=tmp_path,
                     options={
                         "skip_npm_ci": True
                     }).npm_install()
     assert "skipped npm ci/npm install" in caplog.messages
Ejemplo n.º 9
0
 def test_init(self, mocker: MockerFixture,
               runway_context: MockRunwayContext, tmp_path: Path) -> None:
     """Test __init__."""
     mock_check_for_npm = mocker.patch.object(RunwayModuleNpm,
                                              "check_for_npm")
     mock_warn_on_boto_env_vars = mocker.patch.object(
         RunwayModuleNpm, "warn_on_boto_env_vars")
     obj = RunwayModuleNpm(
         runway_context,
         module_root=tmp_path,
         options={"options": "test"},
         parameters={"parameters": "test"},
     )
     assert obj.ctx == runway_context
     assert not obj.explicitly_enabled
     assert obj.logger
     assert obj.name == tmp_path.name
     assert obj.options == {"options": "test"}
     assert obj.parameters == {"parameters": "test"}
     assert obj.path == tmp_path
     mock_check_for_npm.assert_called_once_with(logger=obj.logger)
     mock_warn_on_boto_env_vars.assert_called_once_with(
         runway_context.env.vars, logger=obj.logger)
Ejemplo n.º 10
0
 def test_check_for_npm(self, mocker: MockerFixture) -> None:
     """Test check_for_npm."""
     mock_which = mocker.patch(f"{MODULE}.which", return_value=True)
     assert not RunwayModuleNpm.check_for_npm()
     mock_which.assert_called_once_with("npm")