Fix generated test directory name conflicting with sample test directory name

This commit is contained in:
Scott Williams 2016-04-27 22:53:22 +01:00
parent 066baf3c16
commit 1674ec3799
24 changed files with 328 additions and 129 deletions

View File

@ -41,7 +41,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
modelDocTemplateFiles.put("model_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md");
testFolder = "tests";
testFolder = "test";
languageSpecificPrimitives.clear();
languageSpecificPrimitives.add("int");

View File

@ -5,7 +5,7 @@ This Python package is automatically generated by the [Swagger Codegen](https://
- API version: 1.0.0
- Package version: 1.0.0
- Build date: 2016-04-27T22:01:43.565+01:00
- Build date: 2016-04-27T22:50:21.115+01:00
- Build package: class io.swagger.codegen.languages.PythonClientCodegen
## Requirements.

View File

@ -1,2 +1,3 @@
swagger_client
test
tests

View File

@ -0,0 +1,107 @@
# coding: utf-8
"""
Copyright 2016 SmartBear Software
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.rest import ApiException
from swagger_client.apis.pet_api import PetApi
class TestPetApi(unittest.TestCase):
""" PetApi unit test stubs """
def setUp(self):
self.api = swagger_client.apis.pet_api.PetApi()
def tearDown(self):
pass
def test_add_pet(self):
"""
Test case for add_pet
Add a new pet to the store
"""
pass
def test_delete_pet(self):
"""
Test case for delete_pet
Deletes a pet
"""
pass
def test_find_pets_by_status(self):
"""
Test case for find_pets_by_status
Finds Pets by status
"""
pass
def test_find_pets_by_tags(self):
"""
Test case for find_pets_by_tags
Finds Pets by tags
"""
pass
def test_get_pet_by_id(self):
"""
Test case for get_pet_by_id
Find pet by ID
"""
pass
def test_update_pet(self):
"""
Test case for update_pet
Update an existing pet
"""
pass
def test_update_pet_with_form(self):
"""
Test case for update_pet_with_form
Updates a pet in the store with form data
"""
pass
def test_upload_file(self):
"""
Test case for upload_file
uploads an image
"""
pass
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,75 @@
# coding: utf-8
"""
Copyright 2016 SmartBear Software
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.rest import ApiException
from swagger_client.apis.store_api import StoreApi
class TestStoreApi(unittest.TestCase):
""" StoreApi unit test stubs """
def setUp(self):
self.api = swagger_client.apis.store_api.StoreApi()
def tearDown(self):
pass
def test_delete_order(self):
"""
Test case for delete_order
Delete purchase order by ID
"""
pass
def test_get_inventory(self):
"""
Test case for get_inventory
Returns pet inventories by status
"""
pass
def test_get_order_by_id(self):
"""
Test case for get_order_by_id
Find purchase order by ID
"""
pass
def test_place_order(self):
"""
Test case for place_order
Place an order for a pet
"""
pass
if __name__ == '__main__':
unittest.main()

View File

@ -1,107 +1,168 @@
# coding: utf-8
"""
Copyright 2016 SmartBear Software
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
ref: https://github.com/swagger-api/swagger-codegen
Run the tests.
$ pip install nose (optional)
$ cd swagger_client-python
$ nosetests -v
"""
from __future__ import absolute_import
import os
import sys
import time
import unittest
import swagger_client
from swagger_client.rest import ApiException
from swagger_client.apis.pet_api import PetApi
HOST = 'http://petstore.swagger.io/v2'
class TestPetApi(unittest.TestCase):
""" PetApi unit test stubs """
class PetApiTests(unittest.TestCase):
def setUp(self):
self.api = swagger_client.apis.pet_api.PetApi()
self.api_client = swagger_client.ApiClient(HOST)
self.pet_api = swagger_client.PetApi(self.api_client)
self.setUpModels()
self.setUpFiles()
def tearDown(self):
pass
# sleep 1 sec between two every 2 tests
time.sleep(1)
def test_add_pet(self):
"""
Test case for add_pet
def setUpModels(self):
self.category = swagger_client.Category()
self.category.id = int(time.time())
self.category.name = "dog"
self.tag = swagger_client.Tag()
self.tag.id = int(time.time())
self.tag.name = "swagger-codegen-python-pet-tag"
self.pet = swagger_client.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]
Add a new pet to the store
"""
pass
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_delete_pet(self):
"""
Test case for delete_pet
def test_create_api_instance(self):
pet_api = swagger_client.PetApi()
pet_api2 = swagger_client.PetApi()
api_client3 = swagger_client.ApiClient()
api_client3.user_agent = 'api client 3'
api_client4 = swagger_client.ApiClient()
api_client4.user_agent = 'api client 4'
pet_api3 = swagger_client.PetApi(api_client3)
Deletes a pet
"""
pass
# same default api client
self.assertEqual(pet_api.api_client, pet_api2.api_client)
# confirm using the default api client in the config module
self.assertEqual(pet_api.api_client, swagger_client.configuration.api_client)
# 2 different api clients are not the same
self.assertNotEqual(api_client3, api_client4)
# customized pet api not using the default api client
self.assertNotEqual(pet_api3.api_client, swagger_client.configuration.api_client)
# customized pet api not using the old pet api's api client
self.assertNotEqual(pet_api3.api_client, pet_api2.api_client)
def test_find_pets_by_status(self):
"""
Test case for find_pets_by_status
def test_async_request(self):
self.pet_api.add_pet(body=self.pet)
Finds Pets by status
"""
pass
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)
def test_find_pets_by_tags(self):
"""
Test case for find_pets_by_tags
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")
Finds Pets by tags
"""
pass
def test_add_pet_and_get_pet_by_id(self):
self.pet_api.add_pet(body=self.pet)
def test_get_pet_by_id(self):
"""
Test case for get_pet_by_id
Find pet by ID
"""
pass
fetched = self.pet_api.get_pet_by_id(pet_id=self.pet.id)
self.assertIsNotNone(fetched)
self.assertEqual(self.pet.id, fetched.id)
self.assertIsNotNone(fetched.category)
self.assertEqual(self.pet.category.name, fetched.category.name)
def test_update_pet(self):
"""
Test case for update_pet
self.pet.name = "hello kity with updated"
self.pet_api.update_pet(body=self.pet)
Update an existing pet
"""
pass
fetched = self.pet_api.get_pet_by_id(pet_id=self.pet.id)
self.assertIsNotNone(fetched)
self.assertEqual(self.pet.id, fetched.id)
self.assertEqual(self.pet.name, fetched.name)
self.assertIsNotNone(fetched.category)
self.assertEqual(fetched.category.name, self.pet.category.name)
def test_find_pets_by_status(self):
self.pet_api.add_pet(body=self.pet)
self.assertIn(
self.pet.id,
list(map(lambda x: getattr(x, 'id'), self.pet_api.find_pets_by_status(status=[self.pet.status])))
)
def test_find_pets_by_tags(self):
self.pet_api.add_pet(body=self.pet)
self.assertIn(
self.pet.id,
list(map(lambda x: getattr(x, 'id'), self.pet_api.find_pets_by_tags(tags=[self.tag.name])))
)
def test_update_pet_with_form(self):
"""
Test case for update_pet_with_form
self.pet_api.add_pet(body=self.pet)
Updates a pet in the store with form data
"""
pass
name = "hello kity with form updated"
status = "pending"
self.pet_api.update_pet_with_form(pet_id=self.pet.id, name=name, status=status)
fetched = self.pet_api.get_pet_by_id(pet_id=self.pet.id)
self.assertEqual(self.pet.id, fetched.id)
self.assertEqual(name, fetched.name)
self.assertEqual(status, fetched.status)
def test_upload_file(self):
"""
Test case for upload_file
# upload file with form parameter
try:
additional_metadata = "special"
self.pet_api.upload_file(
pet_id=self.pet.id,
additional_metadata=additional_metadata,
file=self.foo
)
except ApiException as e:
self.fail("upload_file() raised {0} unexpectedly".format(type(e)))
uploads an image
"""
pass
# upload only file
try:
self.pet_api.upload_file(pet_id=self.pet.id, file=self.foo)
except ApiException as e:
self.fail("upload_file() raised {0} unexpectedly".format(type(e)))
def test_delete_pet(self):
self.pet_api.add_pet(body=self.pet)
self.pet_api.delete_pet(pet_id=self.pet.id, api_key="special-key")
try:
self.pet_api.get_pet_by_id(pet_id=self.pet.id)
raise "expected an error"
except ApiException as e:
self.assertEqual(404, e.status)
if __name__ == '__main__':
unittest.main()
unittest.main()

View File

@ -1,75 +1,30 @@
# coding: utf-8
"""
Copyright 2016 SmartBear Software
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
ref: https://github.com/swagger-api/swagger-codegen
Run the tests.
$ pip install nose (optional)
$ cd SwaggerPetstore-python
$ nosetests -v
"""
from __future__ import absolute_import
import os
import sys
import time
import unittest
import swagger_client
from swagger_client.rest import ApiException
from swagger_client.apis.store_api import StoreApi
class TestStoreApi(unittest.TestCase):
""" StoreApi unit test stubs """
class StoreApiTests(unittest.TestCase):
def setUp(self):
self.api = swagger_client.apis.store_api.StoreApi()
self.store_api = swagger_client.StoreApi()
def tearDown(self):
pass
def test_delete_order(self):
"""
Test case for delete_order
Delete purchase order by ID
"""
pass
# sleep 1 sec between two every 2 tests
time.sleep(1)
def test_get_inventory(self):
"""
Test case for get_inventory
Returns pet inventories by status
"""
pass
def test_get_order_by_id(self):
"""
Test case for get_order_by_id
Find purchase order by ID
"""
pass
def test_place_order(self):
"""
Test case for place_order
Place an order for a pet
"""
pass
if __name__ == '__main__':
unittest.main()
data = self.store_api.get_inventory()
self.assertIsNotNone(data)
self.assertTrue(isinstance(data, dict))