def test_servercli(freetcpport): cliapp = CLIApplication('foo', 'tests.test_builtincli:app.climain') with Given(cliapp, f'serve --bind {freetcpport}', nowait=True) as s: url = f'http://localhost:{freetcpport}' time.sleep(1) r = requests.get(url) assert r.text == 'foo' s.kill()
def test_jwtcli(): cliapp = CLIApplication('example', 'tests.test_cli:app.climain') with Given(cliapp, 'jwt --help'): assert status == 0 assert stderr == '' when('jwt create \'{"foo": "bar"}\'') print(stderr) assert status == 0 assert len(stdout.split('.')) == 3
def test_versioncli(): cliapp = CLIApplication('foo', 'tests.test_builtincli_version:app.climain') with Given(cliapp, '--version'): assert status == 0 assert stdout.strip() == __version__ assert stderr == '' when('') assert status == 0 assert stderr == ''
def test_applicationcli(): cliapp = CLIApplication('example', 'tests.test_cli:app.climain') with Given(cliapp, 'db --help'): assert status == 0 assert stderr == '' when('db drop') when('db create') assert status == 0 assert stderr == '' when('db drop') assert status == 0 assert stderr == ''
def test_applicationcli_default(): cliapp = CLIApplication('foo', 'tests.test_applicationcli:app.climain') with Given(cliapp, '--help'): assert status == 0 when('foo') assert status == 0 assert stdout == 'foo\n' with tempfile.NamedTemporaryFile() as f: f.write(b'title: bar') f.flush() when(f'--configuration-file {f.name} foo') assert status == 0 assert stdout == 'bar\n'