fixed error handling in async requests in python client (#5308)

This commit is contained in:
baartosz
2017-04-06 09:55:53 +01:00
committed by wing328
parent f9825b01d3
commit 13cccccb67
9 changed files with 346 additions and 567 deletions

View File

@@ -140,23 +140,48 @@ class PetApiTests(unittest.TestCase):
self.assertNotEqual(pet_api.api_client.configuration.host, pet_api2.api_client.configuration.host)
def test_async_request(self):
thread = self.pet_api.add_pet(body=self.pet, async=True)
response = thread.get()
self.assertIsNone(response)
thread = self.pet_api.get_pet_by_id(self.pet.id, async=True)
result = thread.get()
self.assertIsInstance(result, petstore_api.Pet)
def test_async_with_result(self):
self.pet_api.add_pet(body=self.pet, async=False)
thread = self.pet_api.get_pet_by_id(self.pet.id, async=True)
thread2 = self.pet_api.get_pet_by_id(self.pet.id, async=True)
response = thread.get()
response2 = thread2.get()
self.assertEquals(response.id, self.pet.id)
self.assertIsNotNone(response2.id, self.pet.id)
def test_async_with_http_info(self):
self.pet_api.add_pet(body=self.pet)
def callback_function(data):
self.assertIsNotNone(data)
self.assertEqual(data.id, self.pet.id)
self.assertEqual(data.name, self.pet.name)
self.assertIsNotNone(data.category)
self.assertEqual(data.category.id, self.pet.category.id)
self.assertEqual(data.category.name, self.pet.category.name)
self.assertTrue(isinstance(data.tags, list))
self.assertEqual(data.tags[0].id, self.pet.tags[0].id)
self.assertEqual(data.tags[0].name, self.pet.tags[0].name)
thread = self.pet_api.get_pet_by_id_with_http_info(self.pet.id, async=True)
data, status, headers = thread.get()
thread = self.pet_api.get_pet_by_id(pet_id=self.pet.id, callback=callback_function)
thread.join(10)
if thread.isAlive():
self.fail("Request timeout")
self.assertIsInstance(data, petstore_api.Pet)
self.assertEquals(status, 200)
def test_async_exception(self):
self.pet_api.add_pet(body=self.pet)
thread = self.pet_api.get_pet_by_id("-9999999999999", async=True)
exception = None
try:
thread.get()
except ApiException as e:
exception = e
self.assertIsInstance(exception, ApiException)
self.assertEqual(exception.status, 404)
def test_add_pet_and_get_pet_by_id(self):
self.pet_api.add_pet(body=self.pet)
@@ -167,21 +192,6 @@ class PetApiTests(unittest.TestCase):
self.assertIsNotNone(fetched.category)
self.assertEqual(self.pet.category.name, fetched.category.name)
def test_async_add_pet_and_get_pet_by_id(self):
self.pet_api.add_pet(body=self.pet)
def callback_function(data):
# fetched = self.pet_api.get_pet_by_id(pet_id=self.pet.id)
self.assertIsNotNone(data)
self.assertEqual(self.pet.id, data.id)
self.assertIsNotNone(data.category)
self.assertEqual(self.pet.category.name, data.category.name)
thread = self.pet_api.get_pet_by_id(pet_id=self.pet.id, callback=callback_function)
thread.join(10)
if thread.isAlive():
self.fail("Request timeout")
def test_add_pet_and_get_pet_by_id_with_http_info(self):
self.pet_api.add_pet(body=self.pet)
@@ -191,21 +201,6 @@ class PetApiTests(unittest.TestCase):
self.assertIsNotNone(fetched[0].category)
self.assertEqual(self.pet.category.name, fetched[0].category.name)
def test_async_add_pet_and_get_pet_by_id_with_http_info(self):
self.pet_api.add_pet(body=self.pet)
def callback_function(data):
# fetched = self.pet_api.get_pet_by_id_with_http_info(pet_id=self.pet.id)
self.assertIsNotNone(data)
self.assertEqual(self.pet.id, data[0].id)
self.assertIsNotNone(data[0].category)
self.assertEqual(self.pet.category.name, data[0].category.name)
thread = self.pet_api.get_pet_by_id_with_http_info(pet_id=self.pet.id, callback=callback_function)
thread.join(10)
if thread.isAlive():
self.fail("Request timeout")
def test_update_pet(self):
self.pet.name = "hello kity with updated"
self.pet_api.update_pet(body=self.pet)