11from pathlib import PosixPath
2+ from unittest .mock import MagicMock
23
34import pytest
45from typer .testing import CliRunner
@@ -18,17 +19,46 @@ def test_version(mocker):
1819
1920
2021@pytest .fixture
21- def _create_new_client (mocker ):
22+ def _create_new_client (mocker ) -> MagicMock :
2223 return mocker .patch ("openapi_python_client.create_new_client" )
2324
2425
26+ def test_config (mocker , _create_new_client ):
27+ load_config = mocker .patch ("openapi_python_client.load_config" )
28+ from openapi_python_client .cli import app
29+
30+ config_path = "config/path"
31+ path = "cool/path"
32+
33+ result = runner .invoke (app , [f"--config={ config_path } " , "generate" , f"--path={ path } " ], catch_exceptions = False )
34+
35+ assert result .exit_code == 0
36+ load_config .assert_called_once_with (path = PosixPath (config_path ))
37+ _create_new_client .assert_called_once_with (url = None , path = PosixPath (path ))
38+
39+
40+ def test_bad_config (mocker , _create_new_client ):
41+ load_config = mocker .patch ("openapi_python_client.load_config" , side_effect = ValueError ("Bad Config" ))
42+ from openapi_python_client .cli import app
43+
44+ config_path = "config/path"
45+ path = "cool/path"
46+
47+ result = runner .invoke (app , [f"--config={ config_path } " , "generate" , f"--path={ path } " ])
48+
49+ assert result .exit_code == 2
50+ assert "Unable to parse config" in result .stdout
51+ load_config .assert_called_once_with (path = PosixPath (config_path ))
52+ _create_new_client .assert_not_called ()
53+
54+
2555class TestGenerate :
2656 def test_generate_no_params (self , _create_new_client ):
2757 from openapi_python_client .cli import app
2858
2959 result = runner .invoke (app , ["generate" ])
3060
31- assert result .exit_code == 1
61+ assert result .exit_code == 1 , result . output
3262 _create_new_client .assert_not_called ()
3363
3464 def test_generate_url_and_path (self , _create_new_client ):
0 commit comments