コード例 #1
0
    def test__create_package(self, mocker):
        from openapi_python_client import Project

        project = Project(openapi=mocker.MagicMock(title="My Test API"))
        project.package_dir = mocker.MagicMock()
        package_init_template = mocker.MagicMock()
        project.env = mocker.MagicMock()
        project.env.get_template.return_value = package_init_template
        package_init_path = mocker.MagicMock(autospec=pathlib.Path)
        pytyped_path = mocker.MagicMock(autospec=pathlib.Path)
        paths = {
            "__init__.py": package_init_path,
            "py.typed": pytyped_path,
        }

        project.package_dir.__truediv__.side_effect = lambda x: paths[x]

        project._create_package()

        project.package_dir.mkdir.assert_called_once()
        project.env.get_template.assert_called_once_with("package_init.pyi")
        package_init_template.render.assert_called_once_with(
            description=project.package_description)
        package_init_path.write_text.assert_called_once_with(
            package_init_template.render())
        pytyped_path.write_text.assert_called_once_with(
            "# Marker file for PEP 561")
コード例 #2
0
    def test_build_no_meta(self, mocker):
        from openapi_python_client import MetaType, Project

        project = Project(openapi=mocker.MagicMock(title="My Test API"),
                          meta=MetaType.NONE)
        project.project_dir = mocker.MagicMock()
        project.package_dir = mocker.MagicMock()
        project._build_metadata = mocker.MagicMock()
        project._build_models = mocker.MagicMock()
        project._build_api = mocker.MagicMock()
        project._create_package = mocker.MagicMock()
        project._reformat = mocker.MagicMock()
        project._get_errors = mocker.MagicMock()

        project.build()

        project.project_dir.mkdir.assert_not_called()
コード例 #3
0
    def test_update(self, mocker):
        from openapi_python_client import Project, shutil

        rmtree = mocker.patch.object(shutil, "rmtree")
        project = Project(openapi=mocker.MagicMock(title="My Test API"))
        project.package_dir = mocker.MagicMock()
        project._build_metadata = mocker.MagicMock()
        project._build_models = mocker.MagicMock()
        project._build_api = mocker.MagicMock()
        project._create_package = mocker.MagicMock()
        project._reformat = mocker.MagicMock()
        project._get_errors = mocker.MagicMock()

        result = project.update()

        rmtree.assert_called_once_with(project.package_dir)
        project._create_package.assert_called_once()
        project._build_models.assert_called_once()
        project._build_api.assert_called_once()
        project._reformat.assert_called_once()
        project._get_errors.assert_called_once()
        assert result == project._get_errors.return_value
コード例 #4
0
    def test_build(self, mocker):
        from openapi_python_client import Project

        project = Project(openapi=mocker.MagicMock(title="My Test API"))
        project.project_dir = mocker.MagicMock()
        project.package_dir = mocker.MagicMock()
        project._build_metadata = mocker.MagicMock()
        project._build_models = mocker.MagicMock()
        project._build_api = mocker.MagicMock()
        project._create_package = mocker.MagicMock()
        project._reformat = mocker.MagicMock()
        project._get_errors = mocker.MagicMock()

        result = project.build()

        project.project_dir.mkdir.assert_called_once()
        project._create_package.assert_called_once()
        project._build_metadata.assert_called_once()
        project._build_models.assert_called_once()
        project._build_api.assert_called_once()
        project._reformat.assert_called_once()
        project._get_errors.assert_called_once()
        assert result == project._get_errors.return_value