import pytest
from click.testing import CliRunner

from ab_openapi_python_generator.common import HTTPLibrary, library_config_dict
from ab_openapi_python_generator.generate_data import generate_data
from tests.conftest import test_data_folder
from tests.conftest import test_result_path


@pytest.fixture
def runner() -> CliRunner:
    """Fixture for invoking command-line interfaces."""
    return CliRunner()


@pytest.mark.parametrize(
    "library",
    [HTTPLibrary.httpx, HTTPLibrary.aiohttp, HTTPLibrary.requests],
)
def test_issue_117(runner: CliRunner, model_data_with_cleanup, library) -> None:
    """
    https://github.com/MarcoMuellner/openapi-python-generator/issues/117
    """
    generate_data(test_data_folder / "issue_117.json", test_result_path, library)

    if library_config_dict[library].include_sync:
        assert (test_result_path / "services" / "default_service.py").exists()
        assert (test_result_path / "services" / "default_service.py").read_text().find(
            'path = f"/bar-boz/{foo_bar}"'
        ) != -1

    if library_config_dict[library].include_async:
        assert (test_result_path / "services" / "async_default_service.py").exists()
        assert (
            test_result_path / "services" / "async_default_service.py"
        ).read_text().find('path = f"/bar-boz/{foo_bar}"') != -1
