import logging from click.testing import CliRunner from connexion import App, __version__ from connexion.cli import main import pytest from conftest import FIXTURES_FOLDER from mock import MagicMock @pytest.fixture() def mock_app_run(monkeypatch): test_server = MagicMock(wraps=App(__name__)) test_server.run = MagicMock(return_value=True) test_app = MagicMock(return_value=test_server) monkeypatch.setattr('connexion.cli.App', test_app) return test_server def test_run_missing_spec(): runner = CliRunner() result = runner.invoke(main, ['run'], catch_exceptions=False) assert "Missing argument" in result.output def test_run_simple_spec(mock_app_run): spec_file = str(FIXTURES_FOLDER / 'simple/swagger.yaml') default_port = 5000 default_server = 'gevent' runner = CliRunner() result = runner.invoke(main, ['run', spec_file], catch_exceptions=False) mock_app_run.run.assert_called_with(port=default_port, server=default_server) assert 'Running at' in result.output def test_run_in_debug_mode(mock_app_run, monkeypatch): spec_file = str(FIXTURES_FOLDER / 'simple/swagger.yaml') logging_config = MagicMock(name='connexion.cli.logging.basicConfig') monkeypatch.setattr('connexion.cli.logging.basicConfig', logging_config) runner = CliRunner() result = runner.invoke(main, ['run', spec_file, '-d'], catch_exceptions=False) logging_config.assert_called_with(level=logging.DEBUG)