예제 #1
0
def test__reformat(mocker):
    import subprocess

    from openapi_python_client import GeneratorData, MetaType, Project

    sub_run = mocker.patch("subprocess.run")
    openapi = mocker.MagicMock(autospec=GeneratorData, title="My Test API")
    project = Project(openapi=openapi, meta=MetaType.POETRY)
    project.project_dir = mocker.MagicMock(autospec=pathlib.Path)

    project._reformat()

    sub_run.assert_has_calls([
        mocker.call(
            "autoflake -i -r --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports .",
            cwd=project.package_dir,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        ),
        mocker.call(
            "isort .",
            cwd=project.project_dir,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        ),
        mocker.call("black .",
                    cwd=project.project_dir,
                    shell=True,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE),
    ])
def test__reformat(mocker):
    import subprocess

    from openapi_python_client import GeneratorData, Project

    sub_run = mocker.patch("subprocess.run")
    openapi = mocker.MagicMock(autospec=GeneratorData, title="My Test API")
    project = Project(openapi=openapi)
    project.project_dir = mocker.MagicMock(autospec=pathlib.Path)

    project._reformat()

    sub_run.assert_has_calls([
        mocker.call(
            "isort .",
            cwd=project.project_dir,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        ),
        mocker.call("black .",
                    cwd=project.project_dir,
                    shell=True,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE),
    ])
예제 #3
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()
예제 #4
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
예제 #5
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