diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java index 08d63c4267..1bc95cfdd6 100755 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java @@ -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"); diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md index df5514aac3..6640785fae 100644 --- a/samples/client/petstore/python/README.md +++ b/samples/client/petstore/python/README.md @@ -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. diff --git a/samples/client/petstore/python/swagger_client.egg-info/top_level.txt b/samples/client/petstore/python/swagger_client.egg-info/top_level.txt index 9a02a75c05..01f6691e7c 100644 --- a/samples/client/petstore/python/swagger_client.egg-info/top_level.txt +++ b/samples/client/petstore/python/swagger_client.egg-info/top_level.txt @@ -1,2 +1,3 @@ swagger_client +test tests diff --git a/samples/client/petstore/python/test/__init__.py b/samples/client/petstore/python/test/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/samples/client/petstore/python/tests/test_animal.py b/samples/client/petstore/python/test/test_animal.py similarity index 100% rename from samples/client/petstore/python/tests/test_animal.py rename to samples/client/petstore/python/test/test_animal.py diff --git a/samples/client/petstore/python/tests/test_api_response.py b/samples/client/petstore/python/test/test_api_response.py similarity index 100% rename from samples/client/petstore/python/tests/test_api_response.py rename to samples/client/petstore/python/test/test_api_response.py diff --git a/samples/client/petstore/python/tests/test_cat.py b/samples/client/petstore/python/test/test_cat.py similarity index 100% rename from samples/client/petstore/python/tests/test_cat.py rename to samples/client/petstore/python/test/test_cat.py diff --git a/samples/client/petstore/python/tests/test_category.py b/samples/client/petstore/python/test/test_category.py similarity index 100% rename from samples/client/petstore/python/tests/test_category.py rename to samples/client/petstore/python/test/test_category.py diff --git a/samples/client/petstore/python/tests/test_dog.py b/samples/client/petstore/python/test/test_dog.py similarity index 100% rename from samples/client/petstore/python/tests/test_dog.py rename to samples/client/petstore/python/test/test_dog.py diff --git a/samples/client/petstore/python/tests/test_fake_api.py b/samples/client/petstore/python/test/test_fake_api.py similarity index 100% rename from samples/client/petstore/python/tests/test_fake_api.py rename to samples/client/petstore/python/test/test_fake_api.py diff --git a/samples/client/petstore/python/tests/test_format_test.py b/samples/client/petstore/python/test/test_format_test.py similarity index 100% rename from samples/client/petstore/python/tests/test_format_test.py rename to samples/client/petstore/python/test/test_format_test.py diff --git a/samples/client/petstore/python/tests/test_model_200_response.py b/samples/client/petstore/python/test/test_model_200_response.py similarity index 100% rename from samples/client/petstore/python/tests/test_model_200_response.py rename to samples/client/petstore/python/test/test_model_200_response.py diff --git a/samples/client/petstore/python/tests/test_model_return.py b/samples/client/petstore/python/test/test_model_return.py similarity index 100% rename from samples/client/petstore/python/tests/test_model_return.py rename to samples/client/petstore/python/test/test_model_return.py diff --git a/samples/client/petstore/python/tests/test_name.py b/samples/client/petstore/python/test/test_name.py similarity index 100% rename from samples/client/petstore/python/tests/test_name.py rename to samples/client/petstore/python/test/test_name.py diff --git a/samples/client/petstore/python/tests/test_order.py b/samples/client/petstore/python/test/test_order.py similarity index 100% rename from samples/client/petstore/python/tests/test_order.py rename to samples/client/petstore/python/test/test_order.py diff --git a/samples/client/petstore/python/tests/test_pet.py b/samples/client/petstore/python/test/test_pet.py similarity index 100% rename from samples/client/petstore/python/tests/test_pet.py rename to samples/client/petstore/python/test/test_pet.py diff --git a/samples/client/petstore/python/test/test_pet_api.py b/samples/client/petstore/python/test/test_pet_api.py new file mode 100644 index 0000000000..81ee6c76e9 --- /dev/null +++ b/samples/client/petstore/python/test/test_pet_api.py @@ -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() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_special_model_name.py b/samples/client/petstore/python/test/test_special_model_name.py similarity index 100% rename from samples/client/petstore/python/tests/test_special_model_name.py rename to samples/client/petstore/python/test/test_special_model_name.py diff --git a/samples/client/petstore/python/test/test_store_api.py b/samples/client/petstore/python/test/test_store_api.py new file mode 100644 index 0000000000..e8dc0a64b1 --- /dev/null +++ b/samples/client/petstore/python/test/test_store_api.py @@ -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() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_tag.py b/samples/client/petstore/python/test/test_tag.py similarity index 100% rename from samples/client/petstore/python/tests/test_tag.py rename to samples/client/petstore/python/test/test_tag.py diff --git a/samples/client/petstore/python/tests/test_user.py b/samples/client/petstore/python/test/test_user.py similarity index 100% rename from samples/client/petstore/python/tests/test_user.py rename to samples/client/petstore/python/test/test_user.py diff --git a/samples/client/petstore/python/tests/test_user_api.py b/samples/client/petstore/python/test/test_user_api.py similarity index 100% rename from samples/client/petstore/python/tests/test_user_api.py rename to samples/client/petstore/python/test/test_user_api.py diff --git a/samples/client/petstore/python/tests/test_pet_api.py b/samples/client/petstore/python/tests/test_pet_api.py index 81ee6c76e9..300a7bee78 100644 --- a/samples/client/petstore/python/tests/test_pet_api.py +++ b/samples/client/petstore/python/tests/test_pet_api.py @@ -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() \ No newline at end of file + unittest.main() diff --git a/samples/client/petstore/python/tests/test_store_api.py b/samples/client/petstore/python/tests/test_store_api.py index e8dc0a64b1..42b92d0879 100644 --- a/samples/client/petstore/python/tests/test_store_api.py +++ b/samples/client/petstore/python/tests/test_store_api.py @@ -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() \ No newline at end of file + data = self.store_api.get_inventory() + self.assertIsNotNone(data) + self.assertTrue(isinstance(data, dict))