def test__get_project_for_url_or_path(mocker): data_dict = mocker.MagicMock() _get_document = mocker.patch("openapi_python_client._get_document", return_value=data_dict) openapi = mocker.MagicMock() from_dict = mocker.patch( "openapi_python_client.parser.GeneratorData.from_dict", return_value=openapi) _Project = mocker.patch("openapi_python_client.Project") url = mocker.MagicMock() path = mocker.MagicMock() config = mocker.MagicMock() from openapi_python_client import MetaType, _get_project_for_url_or_path project = _get_project_for_url_or_path(url=url, path=path, meta=MetaType.POETRY, config=config) _get_document.assert_called_once_with(url=url, path=path) from_dict.assert_called_once_with(data_dict, config=config) _Project.assert_called_once_with(openapi=openapi, custom_template_path=None, meta=MetaType.POETRY, file_encoding="utf-8", config=config) assert project == _Project.return_value
def generate_client(openapi_schema: Dict) -> None: assert_valid_schema(openapi_schema) with NamedTemporaryFile("w", suffix=".json") as schema_file: json.dump(openapi_schema, schema_file) schema_file.flush() generator_config = Config( project_name_override="webknossos/client/_generated", package_name_override=".", ) generator_project = _get_project_for_url_or_path( url=None, path=Path(schema_file.name), meta=MetaType.POETRY, config=generator_config, ) assert isinstance(generator_project, Project), generator_project.detail _errors = generator_project.update() # pylint: disable=no-member
def test__get_project_for_url_or_path_document_error(mocker): error = GeneratorError() _get_document = mocker.patch("openapi_python_client._get_document", return_value=error) from_dict = mocker.patch( "openapi_python_client.parser.GeneratorData.from_dict") url = mocker.MagicMock() path = mocker.MagicMock() from openapi_python_client import _get_project_for_url_or_path project = _get_project_for_url_or_path(url=url, path=path) _get_document.assert_called_once_with(url=url, path=path) from_dict.assert_not_called() assert project == error
def test__get_project_for_url_or_path(mocker): data_dict = mocker.MagicMock() _get_json = mocker.patch("openapi_python_client._get_json", return_value=data_dict) openapi = mocker.MagicMock() from_dict = mocker.patch( "openapi_python_client.openapi_parser.OpenAPI.from_dict", return_value=openapi) _Project = mocker.patch("openapi_python_client._Project") url = mocker.MagicMock() path = mocker.MagicMock() from openapi_python_client import _get_project_for_url_or_path project = _get_project_for_url_or_path(url=url, path=path) _get_json.assert_called_once_with(url=url, path=path) from_dict.assert_called_once_with(data_dict) _Project.assert_called_once_with(openapi=openapi) assert project == _Project()
def test__get_project_for_url_or_path(mocker): data_dict = mocker.MagicMock() _get_document = mocker.patch("openapi_python_client._get_document", return_value=data_dict) openapi = mocker.MagicMock() from_dict = mocker.patch( "openapi_python_client.parser.GeneratorData.from_dict", return_value=openapi) _Project = mocker.patch("openapi_python_client.Project") url = mocker.MagicMock() path = mocker.MagicMock() from openapi_python_client import _get_project_for_url_or_path project = _get_project_for_url_or_path(url=url, path=path) _get_document.assert_called_once_with(url=url, path=path) from_dict.assert_called_once_with(data_dict) _Project.assert_called_once_with(openapi=openapi, custom_template_path=None) assert project == _Project()
def test__get_project_for_url_or_path_generator_error(mocker): data_dict = mocker.MagicMock() _get_document = mocker.patch("openapi_python_client._get_document", return_value=data_dict) error = GeneratorError() from_dict = mocker.patch( "openapi_python_client.parser.GeneratorData.from_dict", return_value=error) _Project = mocker.patch("openapi_python_client.Project") url = mocker.MagicMock() path = mocker.MagicMock() from openapi_python_client import MetaType, _get_project_for_url_or_path project = _get_project_for_url_or_path(url=url, path=path, meta=MetaType.POETRY) _get_document.assert_called_once_with(url=url, path=path) from_dict.assert_called_once_with(data_dict) _Project.assert_not_called() assert project == error