async def test_names(self, loop): async with API(SPEC, verbose=True, loop=loop) as api: with coserver(): await api.getHeartbeat() for attr in ('getHeartbeat', 'addUserToCohort', 'returnCohortSettings'): self.assertTrue(hasattr(api, attr))
def test_names(self): api = API(SPEC, verbose=True) with coserver(): api.getHeartbeat() for attr in ('getHeartbeat', 'addUserToCohort', 'returnCohortSettings'): self.assertTrue(hasattr(api, attr))
async def test_bad_status(self, loop): with coserver(): async with API('http://localhost:8888/api.yaml', verbose=True, loop=loop) as api: try: await api.getBadStatus() raise AssertionError("WAT") except AssertionError: pass
async def test_bad_status2(self, loop): with coserver(): async with API('http://localhost:8888/api.yaml', verbose=True, loop=loop) as api: try: await api.getHeartbeat(response={'status': 209}) raise AssertionError("WAT") except AssertionError: pass
async def test_bad_headers(self, loop): headers = {'Content-Type': 'nevergonnahappen'} with coserver(): async with API('http://localhost:8888/api.yaml', verbose=True, loop=loop) as api: try: await api.getHeartbeat(response={'headers': headers}) raise AssertionError("WAT") except AssertionError: pass
def test_scenario(self): options = ('smwogger', '--test', _SCENARIO, 'http://localhost:8888/api.json') with coserver(), set_args(*options) as out: try: main() except SystemExit: pass stdout = out[0].read().strip() self.assertEqual(stdout, WANTED2)
def test_main(self): options = 'smwogger', 'http://localhost:8888/api.json', '--verbose' with coserver(), set_args(*options) as out: try: main() except SystemExit: pass stdout = out[0].read().strip() self.assertEqual(stdout, WANTED) stderr = out[1].read().strip() self.assertTrue("Content-Type: application/json" in stderr)
def test_read_spec_from_url(self): headers = {'Something': 'here'} with coserver(): api = API('http://localhost:8888/api.yaml', verbose=True) api.getDefault() api = API('http://localhost:8888/api.json', verbose=True) api.getDefault() res = api.getHeartbeat(request={'headers': headers}) echoed_headers = res.json()['headers'] self.assertEqual(echoed_headers['Something'], 'here')
async def test_read_spec_from_url(self, loop): headers = {'Something': 'here'} with coserver(): async with API('http://localhost:8888/api.yaml', verbose=True, loop=loop) as api: await api.getDefault() async with API('http://localhost:8888/api.json', verbose=True, loop=loop) as api: await api.getDefault() res = await api.getHeartbeat(request={'headers': headers}) data = await res.json() echoed_headers = data['headers'] self.assertEqual(echoed_headers['Something'], 'here')
async def test_default(self, loop): async with API(SPEC, loop=loop) as api: with coserver(): await api.getDefault()
def test_bad_status(self): with coserver(): api = API('http://localhost:8888/api.yaml', verbose=True) self.assertRaises(AssertionError, api.getBadStatus)
def test_default(self): api = API(SPEC) with coserver(): api.getDefault()