mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 06:30:52 +00:00
[Python] Fix flaky test with id collisions
This commit is contained in:
parent
3659767e0a
commit
be65a26db0
@ -9,12 +9,12 @@ $ nosetests -v
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
from petstore_api.rest import ApiException
|
from petstore_api.rest import ApiException
|
||||||
|
|
||||||
|
from .util import id_gen
|
||||||
|
|
||||||
class ApiExceptionTests(unittest.TestCase):
|
class ApiExceptionTests(unittest.TestCase):
|
||||||
|
|
||||||
@ -25,22 +25,19 @@ class ApiExceptionTests(unittest.TestCase):
|
|||||||
|
|
||||||
def setUpModels(self):
|
def setUpModels(self):
|
||||||
self.category = petstore_api.Category()
|
self.category = petstore_api.Category()
|
||||||
self.category.id = int(time.time())
|
self.category.id = id_gen()
|
||||||
self.category.name = "dog"
|
self.category.name = "dog"
|
||||||
self.tag = petstore_api.Tag()
|
self.tag = petstore_api.Tag()
|
||||||
self.tag.id = int(time.time())
|
self.tag.id = id_gen()
|
||||||
self.tag.name = "blank"
|
self.tag.name = "blank"
|
||||||
self.pet = petstore_api.Pet()
|
self.pet = petstore_api.Pet()
|
||||||
self.pet.id = int(time.time())
|
self.pet.id = id_gen()
|
||||||
self.pet.name = "hello kity"
|
self.pet.name = "hello kity"
|
||||||
self.pet.photo_urls = ["http://foo.bar.com/1", "http://foo.bar.com/2"]
|
self.pet.photo_urls = ["http://foo.bar.com/1", "http://foo.bar.com/2"]
|
||||||
self.pet.status = "sold"
|
self.pet.status = "sold"
|
||||||
self.pet.category = self.category
|
self.pet.category = self.category
|
||||||
self.pet.tags = [self.tag]
|
self.pet.tags = [self.tag]
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
def test_404_error(self):
|
def test_404_error(self):
|
||||||
self.pet_api.add_pet(body=self.pet)
|
self.pet_api.add_pet(body=self.pet)
|
||||||
self.pet_api.delete_pet(pet_id=self.pet.id)
|
self.pet_api.delete_pet(pet_id=self.pet.id)
|
||||||
|
@ -8,14 +8,14 @@ $ nosetests -v
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
from petstore_api.rest import ApiException
|
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):
|
class PetApiTests(unittest.TestCase):
|
||||||
|
|
||||||
@ -25,19 +25,15 @@ class PetApiTests(unittest.TestCase):
|
|||||||
self.setUpModels()
|
self.setUpModels()
|
||||||
self.setUpFiles()
|
self.setUpFiles()
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
# sleep 1 sec between two every 2 tests
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
def setUpModels(self):
|
def setUpModels(self):
|
||||||
self.category = petstore_api.Category()
|
self.category = petstore_api.Category()
|
||||||
self.category.id = int(time.time())
|
self.category.id = id_gen()
|
||||||
self.category.name = "dog"
|
self.category.name = "dog"
|
||||||
self.tag = petstore_api.Tag()
|
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.tag.name = "swagger-codegen-python-pet-tag"
|
||||||
self.pet = petstore_api.Pet()
|
self.pet = petstore_api.Pet()
|
||||||
self.pet.id = int(time.time())
|
self.pet.id = id_gen()
|
||||||
self.pet.name = "hello kity"
|
self.pet.name = "hello kity"
|
||||||
self.pet.photo_urls = ["http://foo.bar.com/1", "http://foo.bar.com/2"]
|
self.pet.photo_urls = ["http://foo.bar.com/1", "http://foo.bar.com/2"]
|
||||||
self.pet.status = "sold"
|
self.pet.status = "sold"
|
||||||
|
5
samples/client/petstore/python/tests/util.py
Normal file
5
samples/client/petstore/python/tests/util.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
def id_gen(bits=32):
|
||||||
|
""" Returns a n-bit randomly generated int """
|
||||||
|
return int(random.getrandbits(bits))
|
Loading…
x
Reference in New Issue
Block a user