forked from loafle/openapi-generator-original
Merge pull request #680 from geekerzp/develop_2.0_python_testing
Bug fix for deserialize model issue and added unit tests for python client
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
"""Add all of the modules in the current directory to __all__"""
|
||||
import os
|
||||
|
||||
{{#models}}{{#model}}
|
||||
from .{{classVarName}} import {{classname}}
|
||||
{{/model}}{{/models}}
|
||||
|
||||
__all__ = []
|
||||
|
||||
for module in os.listdir(os.path.dirname(__file__)):
|
||||
|
||||
@@ -17,8 +17,7 @@ import datetime
|
||||
import mimetypes
|
||||
import random
|
||||
import string
|
||||
|
||||
from models import *
|
||||
import models
|
||||
|
||||
|
||||
class ApiClient(object):
|
||||
@@ -211,7 +210,7 @@ class ApiClient(object):
|
||||
if (objClass in ['int', 'float', 'long', 'dict', 'list', 'str', 'bool', 'datetime']):
|
||||
objClass = eval(objClass)
|
||||
else: # not a native type, must be model class
|
||||
objClass = eval(objClass + '.' + objClass)
|
||||
objClass = eval('models.' + objClass)
|
||||
|
||||
if objClass in [int, long, float, dict, list, str, bool]:
|
||||
return objClass(obj)
|
||||
|
||||
@@ -2,6 +2,18 @@
|
||||
"""Add all of the modules in the current directory to __all__"""
|
||||
import os
|
||||
|
||||
|
||||
from .user import User
|
||||
|
||||
from .category import Category
|
||||
|
||||
from .pet import Pet
|
||||
|
||||
from .tag import Tag
|
||||
|
||||
from .order import Order
|
||||
|
||||
|
||||
__all__ = []
|
||||
|
||||
for module in os.listdir(os.path.dirname(__file__)):
|
||||
|
||||
@@ -17,8 +17,7 @@ import datetime
|
||||
import mimetypes
|
||||
import random
|
||||
import string
|
||||
|
||||
from models import *
|
||||
import models
|
||||
|
||||
|
||||
class ApiClient(object):
|
||||
@@ -211,7 +210,7 @@ class ApiClient(object):
|
||||
if (objClass in ['int', 'float', 'long', 'dict', 'list', 'str', 'bool', 'datetime']):
|
||||
objClass = eval(objClass)
|
||||
else: # not a native type, must be model class
|
||||
objClass = eval(objClass + '.' + objClass)
|
||||
objClass = eval('models.' + objClass)
|
||||
|
||||
if objClass in [int, long, float, dict, list, str, bool]:
|
||||
return objClass(obj)
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>PythonPetstoreClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>Python Swagger Petstore Client</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>nose-install</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>pip</executable>
|
||||
<arguments>
|
||||
<argument>install</argument>
|
||||
<argument>nose</argument>
|
||||
<argument>--user</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>nose-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>nosetests</executable>
|
||||
<arguments>
|
||||
<argument>-v</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
@@ -0,0 +1,113 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
Run the tests.
|
||||
$ pip install nose (optional)
|
||||
$ cd SwaggerPetstore-python
|
||||
$ nosetests -v
|
||||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
import unittest
|
||||
import urllib2
|
||||
|
||||
import SwaggerPetstore
|
||||
|
||||
HOST = 'http://petstore.swagger.io/v2'
|
||||
|
||||
|
||||
class PetApiTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.api_client = SwaggerPetstore.ApiClient(HOST)
|
||||
self.pet_api = SwaggerPetstore.PetApi(self.api_client)
|
||||
self.setUpModels()
|
||||
self.setUpFiles()
|
||||
|
||||
def tearDown(self):
|
||||
# sleep 1 sec between two every 2 tests
|
||||
time.sleep(1)
|
||||
|
||||
def setUpModels(self):
|
||||
self.category = SwaggerPetstore.Category()
|
||||
self.category.id = 1010
|
||||
self.category.name = "dog"
|
||||
self.tag = SwaggerPetstore.Tag()
|
||||
self.tag.id = 1010
|
||||
self.tag.name = "blank"
|
||||
self.pet = SwaggerPetstore.Pet()
|
||||
self.pet.id = 1010
|
||||
self.pet.name = "hello kity"
|
||||
self.pet.photo_urls = ["sample urls"]
|
||||
self.pet.status = "sold"
|
||||
self.pet.category = self.category
|
||||
self.pet.tags = [self.tag]
|
||||
|
||||
def setUpFiles(self):
|
||||
self.test_file_dir = os.path.join(os.path.dirname(__file__), "..", "testfiles")
|
||||
self.test_file_dir = os.path.realpath(self.test_file_dir)
|
||||
self.foo = os.path.join(self.test_file_dir, "foo.png")
|
||||
|
||||
def test_1_add_pet(self):
|
||||
try:
|
||||
self.pet_api.add_pet(body=self.pet)
|
||||
except (urllib2.HTTPError, urllib2.URLError) as e:
|
||||
self.fail("add_pet() raised {0} unexpectedly".format(type(e)))
|
||||
|
||||
def test_2_get_pet_by_id(self):
|
||||
self.assertEqual(
|
||||
dir(self.pet_api.get_pet_by_id(pet_id=self.pet.id)),
|
||||
dir(self.pet)
|
||||
)
|
||||
|
||||
def test_3_update_pet(self):
|
||||
try:
|
||||
self.pet.name = "hello kity with updated"
|
||||
self.pet_api.update_pet(body=self.pet)
|
||||
except (urllib2.HTTPError, urllib2.URLError) as e:
|
||||
self.fail("update_pet() raised {0} unexpectedly".format(type(e)))
|
||||
|
||||
def test_4_find_pets_by_status(self):
|
||||
self.assertIn(
|
||||
dir(self.pet),
|
||||
map(dir, self.pet_api.find_pets_by_status(status=["sold"]))
|
||||
)
|
||||
|
||||
def test_5_find_pets_by_tags(self):
|
||||
self.assertIn(
|
||||
dir(self.pet),
|
||||
map(dir, self.pet_api.find_pets_by_tags(tags=["blank"]))
|
||||
)
|
||||
|
||||
def test_6_update_pet_with_form(self):
|
||||
try:
|
||||
name = "hello kity with form updated"
|
||||
status = "pending"
|
||||
self.pet_api.update_pet_with_form(
|
||||
pet_id=self.pet.id, name=name, status=status
|
||||
)
|
||||
except (urllib2.HTTPError, urllib2.URLError) as e:
|
||||
self.fail("update_pet_with_form() raised {0} unexpectedly".format(type(e)))
|
||||
|
||||
def test_7_upload_file(self):
|
||||
try:
|
||||
additional_metadata = "special"
|
||||
self.pet_api.upload_file(
|
||||
pet_id=self.pet.id,
|
||||
additional_metadata=additional_metadata,
|
||||
file=self.foo
|
||||
)
|
||||
except (urllib2.HTTPError, urllib2.URLError) as e:
|
||||
self.fail("upload_file() raised {0} unexpectedly".format(type(e)))
|
||||
|
||||
def test_8_delete_pet(self):
|
||||
try:
|
||||
api_key = "special-key"
|
||||
self.pet_api.delete_pet(pet_id=self.pet.id, api_key=api_key)
|
||||
except (urllib2.HTTPError, urllib2.URLError) as e:
|
||||
self.fail("delete_pet() raised {0} unexpectedly".format(type(e)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user