def test_extend_serverless_yml( self, caplog: LogCaptureFixture, mocker: MockerFixture, runway_context: MockRunwayContext, tmp_path: Path, ) -> None: """Test extend_serverless_yml.""" # pylint: disable=no-member mock_merge = mocker.patch("runway.module.serverless.merge_dicts") caplog.set_level(logging.DEBUG, logger="runway") mock_func = MagicMock() mock_merge.return_value = {"key": "val"} mocker.patch.object(Serverless, "npm_install", MagicMock()) mocker.patch.object(Serverless, "sls_print", MagicMock(return_value="original")) mocker.patch.object(ServerlessOptions, "update_args", MagicMock()) options = {"extend_serverless_yml": {"new-key": "val"}} obj = Serverless(runway_context, module_root=tmp_path, options=options) assert not obj.extend_serverless_yml(mock_func) obj.npm_install.assert_called_once() obj.sls_print.assert_called_once() mock_merge.assert_called_once_with("original", options["extend_serverless_yml"]) mock_func.assert_called_once_with(skip_install=True) obj.options.update_args.assert_called_once_with("config", ANY) tmp_file = obj.options.update_args.call_args[0][1] # 'no way to check the prefix since it will be a uuid' assert tmp_file.endswith(".tmp.serverless.yml") assert not (tmp_path / tmp_file ).exists(), 'should always be deleted after calling "func"' caplog.clear() mocker.patch("pathlib.Path.unlink", MagicMock(side_effect=OSError("test OSError"))) assert not obj.extend_serverless_yml(mock_func) assert ("{}:encountered an error when trying to delete the " "temporary Serverless config".format(tmp_path.name) in caplog.messages)
def test_extend_serverless_yml(self, mock_merge, caplog, monkeypatch, runway_context, tmp_path): """Test extend_serverless_yml.""" # pylint: disable=no-member caplog.set_level(logging.DEBUG, logger="runway") mock_func = MagicMock() mock_merge.return_value = {"key": "val"} monkeypatch.setattr(Serverless, "npm_install", MagicMock()) monkeypatch.setattr(Serverless, "sls_print", MagicMock(return_value="original")) monkeypatch.setattr(ServerlessOptions, "update_args", MagicMock()) options = {"extend_serverless_yml": {"new-key": "val"}} obj = Serverless(runway_context, tmp_path, options={"options": options}) assert not obj.extend_serverless_yml(mock_func) obj.npm_install.assert_called_once() obj.sls_print.assert_called_once() mock_merge.assert_called_once_with("original", options["extend_serverless_yml"]) mock_func.assert_called_once_with(skip_install=True) obj.options.update_args.assert_called_once_with("config", ANY) tmp_file = obj.options.update_args.call_args[0][1] # 'no way to check the prefix since it will be a uuid' assert tmp_file.endswith(".tmp.serverless.yml") assert not (tmp_path / tmp_file ).exists(), 'should always be deleted after calling "func"' caplog.clear() monkeypatch.setattr( "{}.Path.unlink".format("pathlib" if sys.version_info.major == 3 else "pathlib2"), MagicMock(side_effect=OSError("test OSError")), ) assert not obj.extend_serverless_yml(mock_func) assert ("{}:encountered an error when trying to delete the " "temporary Serverless config".format(tmp_path.name) in caplog.messages)
def test_extend_serverless_yml(self, mock_merge, caplog, monkeypatch, runway_context, tmp_path): """Test extend_serverless_yml.""" # pylint: disable=no-member caplog.set_level(logging.DEBUG, logger='runway') mock_func = MagicMock() mock_merge.return_value = {'key': 'val'} monkeypatch.setattr(Serverless, 'npm_install', MagicMock()) monkeypatch.setattr(Serverless, 'sls_print', MagicMock(return_value='original')) monkeypatch.setattr(ServerlessOptions, 'update_args', MagicMock()) options = {'extend_serverless_yml': {'new-key': 'val'}} obj = Serverless(runway_context, tmp_path, options={'options': options}) assert not obj.extend_serverless_yml(mock_func) obj.npm_install.assert_called_once() obj.sls_print.assert_called_once() mock_merge.assert_called_once_with('original', options['extend_serverless_yml']) mock_func.assert_called_once_with(skip_install=True) obj.options.update_args.assert_called_once_with('config', ANY) tmp_file = obj.options.update_args.call_args[0][1] # 'no way to check the prefix since it will be a uuid' assert tmp_file.endswith('.tmp.serverless.yml') assert not (tmp_path / tmp_file).exists(), \ 'should always be deleted after calling "func"' caplog.clear() monkeypatch.setattr( '{}.Path.unlink'.format('pathlib' if sys.version_info.major == 3 else 'pathlib2'), MagicMock(side_effect=OSError('test OSError'))) assert not obj.extend_serverless_yml(mock_func) assert '{}: test OSError'.format(tmp_path.name) in caplog.messages