From 5fbda0e2069797cdd9b2c515c029ad32678f86fd Mon Sep 17 00:00:00 2001 From: geekerzp Date: Wed, 3 Jun 2015 10:46:32 +0800 Subject: [PATCH] added test case for 404 response of python client --- .../SwaggerPetstore/rest.py | 6 ++++ .../tests/test_api_exception.py | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_exception.py diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/rest.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/rest.py index 44a1022906..e7051886dc 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/rest.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/rest.py @@ -1,4 +1,10 @@ # coding: utf-8 + +""" +Credit: this file (rest.py) is modified based on rest.py in Dropbox Python SDK: +https://www.dropbox.com/developers/core/sdks/python +""" + import sys import io import json diff --git a/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_exception.py b/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_exception.py new file mode 100644 index 0000000000..6e30675398 --- /dev/null +++ b/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_exception.py @@ -0,0 +1,31 @@ +# coding: utf-8 + +""" +Run the tests. +$ pip install nose (optional) +$ cd SwaggerPetstore-python +$ nosetests -v +""" + +import os +import time +import unittest + +import SwaggerPetstore +from SwaggerPetstore.rest import ApiException + + +class ApiExceptionTests(unittest.TestCase): + + def setUp(self): + self.api_client = SwaggerPetstore.ApiClient() + self.pet_api = SwaggerPetstore.PetApi(self.api_client) + + def tearDown(self): + time.sleep(1) + + def test_404_error(self): + self.pet_api.delete_pet(pet_id=1234) + + with self.assertRaisesRegexp(ApiException, "Pet not found"): + self.pet_api.get_pet_by_id(pet_id=1234)