mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
added test case for 500 response of python client
This commit is contained in:
parent
8ef4c4401e
commit
813c0119aa
@ -190,7 +190,10 @@ class ApiException(Exception):
|
||||
"""
|
||||
Custom error response messages
|
||||
"""
|
||||
return "({0})\nReason: {1}\nHeader: {2}\nBody: {3}\n".\
|
||||
return "({0})\n"\
|
||||
"Reason: {1}\n"\
|
||||
"HTTP response headers: {2}\n"\
|
||||
"HTTP response body: {3}\n".\
|
||||
format(self.status, self.reason, self.headers, self.body)
|
||||
|
||||
class RESTClient(object):
|
||||
|
@ -1,6 +1,12 @@
|
||||
# coding: utf-8
|
||||
|
||||
from six import iteritems
|
||||
|
||||
def remove_none(obj):
|
||||
"""
|
||||
Remove None from `list`, `tuple`, `set`.
|
||||
Remove None value from `dict`.
|
||||
"""
|
||||
if isinstance(obj, (list, tuple, set)):
|
||||
return type(obj)(remove_none(x) for x in obj if x is not None)
|
||||
elif isinstance(obj, dict):
|
||||
@ -8,10 +14,3 @@ def remove_none(obj):
|
||||
for k, v in iteritems(obj) if k is not None and v is not None)
|
||||
else:
|
||||
return obj
|
||||
|
||||
|
||||
def inspect_vars(obj):
|
||||
if not hasattr(obj, '__dict__'):
|
||||
return obj
|
||||
else:
|
||||
return {k: inspect_vars(getattr(obj, k)) for k in dir(obj)}
|
||||
|
@ -190,7 +190,10 @@ class ApiException(Exception):
|
||||
"""
|
||||
Custom error response messages
|
||||
"""
|
||||
return "({0})\nReason: {1}\nHeader: {2}\nBody: {3}\n".\
|
||||
return "({0})\n"\
|
||||
"Reason: {1}\n"\
|
||||
"HTTP response headers: {2}\n"\
|
||||
"HTTP response body: {3}\n".\
|
||||
format(self.status, self.reason, self.headers, self.body)
|
||||
|
||||
class RESTClient(object):
|
||||
|
@ -1,6 +1,12 @@
|
||||
# coding: utf-8
|
||||
|
||||
from six import iteritems
|
||||
|
||||
def remove_none(obj):
|
||||
"""
|
||||
Remove None from `list`, `tuple`, `set`.
|
||||
Remove None value from `dict`.
|
||||
"""
|
||||
if isinstance(obj, (list, tuple, set)):
|
||||
return type(obj)(remove_none(x) for x in obj if x is not None)
|
||||
elif isinstance(obj, dict):
|
||||
@ -8,10 +14,3 @@ def remove_none(obj):
|
||||
for k, v in iteritems(obj) if k is not None and v is not None)
|
||||
else:
|
||||
return obj
|
||||
|
||||
|
||||
def inspect_vars(obj):
|
||||
if not hasattr(obj, '__dict__'):
|
||||
return obj
|
||||
else:
|
||||
return {k: inspect_vars(getattr(obj, k)) for k in dir(obj)}
|
||||
|
@ -20,12 +20,57 @@ class ApiExceptionTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.api_client = SwaggerPetstore.ApiClient()
|
||||
self.pet_api = SwaggerPetstore.PetApi(self.api_client)
|
||||
self.setUpModels()
|
||||
|
||||
def setUpModels(self):
|
||||
self.category = SwaggerPetstore.Category()
|
||||
self.category.id = int(time.time())
|
||||
self.category.name = "dog"
|
||||
self.tag = SwaggerPetstore.Tag()
|
||||
self.tag.id = int(time.time())
|
||||
self.tag.name = "blank"
|
||||
self.pet = SwaggerPetstore.Pet()
|
||||
self.pet.id = int(time.time())
|
||||
self.pet.name = "hello kity"
|
||||
self.pet.photo_urls = ["http://foo.bar.com/1", "http://foo.bar.com/2"]
|
||||
self.pet.status = "sold"
|
||||
self.pet.category = self.category
|
||||
self.pet.tags = [self.tag]
|
||||
|
||||
def tearDown(self):
|
||||
time.sleep(1)
|
||||
|
||||
def test_404_error(self):
|
||||
self.pet_api.delete_pet(pet_id=1234)
|
||||
self.pet_api.add_pet(body=self.pet)
|
||||
self.pet_api.delete_pet(pet_id=self.pet.id)
|
||||
|
||||
with self.assertRaisesRegexp(ApiException, "Pet not found"):
|
||||
self.pet_api.get_pet_by_id(pet_id=1234)
|
||||
self.pet_api.get_pet_by_id(pet_id=self.pet.id)
|
||||
|
||||
try:
|
||||
self.pet_api.get_pet_by_id(pet_id=self.pet.id)
|
||||
except ApiException as e:
|
||||
self.assertEqual(e.status, 404)
|
||||
self.assertEqual(e.reason, "Not Found")
|
||||
self.assertDictEqual(e.body, {'message': 'Pet not found', 'code': 1, 'type': 'error'})
|
||||
|
||||
def test_500_error(self):
|
||||
self.pet_api.add_pet(body=self.pet)
|
||||
|
||||
with self.assertRaisesRegexp(ApiException, "Internal Server Error"):
|
||||
self.pet_api.upload_file(
|
||||
pet_id=self.pet.id,
|
||||
additional_metadata="special",
|
||||
file=None
|
||||
)
|
||||
|
||||
try:
|
||||
self.pet_api.upload_file(
|
||||
pet_id=self.pet.id,
|
||||
additional_metadata="special",
|
||||
file=None
|
||||
)
|
||||
except ApiException as e:
|
||||
self.assertEqual(e.status, 500)
|
||||
self.assertEqual(e.reason, "Internal Server Error")
|
||||
self.assertRegexpMatches(e.body, "Error 500 Internal Server Error")
|
||||
|
Loading…
Reference in New Issue
Block a user