diff --git a/samples/client/petstore/python/tests/test_api_exception.py b/samples/client/petstore/python/tests/test_api_exception.py index 8df2b681f01..d1f9dbaa6f2 100644 --- a/samples/client/petstore/python/tests/test_api_exception.py +++ b/samples/client/petstore/python/tests/test_api_exception.py @@ -9,12 +9,12 @@ $ nosetests -v import os import sys -import time import unittest import petstore_api from petstore_api.rest import ApiException +from .util import id_gen class ApiExceptionTests(unittest.TestCase): @@ -25,22 +25,19 @@ class ApiExceptionTests(unittest.TestCase): def setUpModels(self): self.category = petstore_api.Category() - self.category.id = int(time.time()) + self.category.id = id_gen() self.category.name = "dog" self.tag = petstore_api.Tag() - self.tag.id = int(time.time()) + self.tag.id = id_gen() self.tag.name = "blank" self.pet = petstore_api.Pet() - self.pet.id = int(time.time()) + self.pet.id = id_gen() 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.add_pet(body=self.pet) self.pet_api.delete_pet(pet_id=self.pet.id) diff --git a/samples/client/petstore/python/tests/test_pet_api.py b/samples/client/petstore/python/tests/test_pet_api.py index e2ed0ec267c..2f48ce8d335 100644 --- a/samples/client/petstore/python/tests/test_pet_api.py +++ b/samples/client/petstore/python/tests/test_pet_api.py @@ -8,14 +8,14 @@ $ nosetests -v """ import os -import time import unittest import petstore_api from petstore_api.rest import ApiException -HOST = 'http://petstore.swagger.io/v2' +from .util import id_gen +HOST = 'http://petstore.swagger.io/v2' class PetApiTests(unittest.TestCase): @@ -25,19 +25,15 @@ class PetApiTests(unittest.TestCase): self.setUpModels() self.setUpFiles() - def tearDown(self): - # sleep 1 sec between two every 2 tests - time.sleep(1) - def setUpModels(self): self.category = petstore_api.Category() - self.category.id = int(time.time()) + self.category.id = id_gen() self.category.name = "dog" self.tag = petstore_api.Tag() - self.tag.id = int(time.time()) + self.tag.id = id_gen() self.tag.name = "swagger-codegen-python-pet-tag" self.pet = petstore_api.Pet() - self.pet.id = int(time.time()) + self.pet.id = id_gen() self.pet.name = "hello kity" self.pet.photo_urls = ["http://foo.bar.com/1", "http://foo.bar.com/2"] self.pet.status = "sold" diff --git a/samples/client/petstore/python/tests/util.py b/samples/client/petstore/python/tests/util.py new file mode 100644 index 00000000000..6aeea16f63e --- /dev/null +++ b/samples/client/petstore/python/tests/util.py @@ -0,0 +1,5 @@ +import random + +def id_gen(bits=32): + """ Returns a n-bit randomly generated int """ + return int(random.getrandbits(bits))