Fix mutable defaults in tests
Some test methods have mutables objects as default types. It potentially can lead to unpredictable errors in tests and it is considered as bad practice in python. So the patch replaces these defaults with None and introduces default values in method body. Change-Id: If523d8ddfb4c176ad2ba81c15858b78bbd89c80b
This commit is contained in:
parent
e79f39ebc0
commit
fd175a8dcc
|
@ -34,7 +34,9 @@ class JsonPatchValidatorMixin(object):
|
|||
ALLOWED = ["replace", "test", "remove", "add", "copy"]
|
||||
PATH_REGEX_COMPILED = re.compile("^/[^/]+(/[^/]+)*$")
|
||||
|
||||
def __init__(self, methods_allowed=["replace", "remove"]):
|
||||
def __init__(self, methods_allowed=None):
|
||||
if methods_allowed is None:
|
||||
methods_allowed = ["replace", "remove"]
|
||||
self.schema = self._gen_schema(methods_allowed)
|
||||
self.methods_allowed = [m for m in methods_allowed
|
||||
if m in self.ALLOWED]
|
||||
|
|
|
@ -604,8 +604,10 @@ def artifact_get(client, artifact_id,
|
|||
|
||||
@_get_client
|
||||
def artifact_get_all(client, marker=None, limit=None, sort_key=None,
|
||||
sort_dir=None, filters={},
|
||||
sort_dir=None, filters=None,
|
||||
show_level=artifacts.Showlevel.NONE, session=None):
|
||||
if filters is None:
|
||||
filters = {}
|
||||
return client.artifact_create(marker, limit, sort_key,
|
||||
sort_dir, filters, show_level)
|
||||
|
||||
|
|
|
@ -235,7 +235,10 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||
return response.text
|
||||
|
||||
def _check_artifact_post(self, url, data, status=201,
|
||||
headers={'Content-Type': 'application/json'}):
|
||||
headers=None):
|
||||
if headers is None:
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
return self._check_artifact_method("post", url, data, status=status,
|
||||
headers=headers)
|
||||
|
||||
|
|
|
@ -29,7 +29,9 @@ from glance.tests.unit import utils as unit_test_utils
|
|||
|
||||
|
||||
class ImageStub(object):
|
||||
def __init__(self, image_id, extra_properties={}, visibility='private'):
|
||||
def __init__(self, image_id, extra_properties=None, visibility='private'):
|
||||
if extra_properties is None:
|
||||
extra_properties = {}
|
||||
self.image_id = image_id
|
||||
self.visibility = visibility
|
||||
self.status = 'active'
|
||||
|
|
|
@ -19,7 +19,10 @@ import glance.tests.utils as utils
|
|||
|
||||
|
||||
class TestValidator(jpv.JsonPatchValidatorMixin):
|
||||
def __init__(self, methods_allowed=["replace", "add"]):
|
||||
def __init__(self, methods_allowed=None):
|
||||
if methods_allowed is None:
|
||||
methods_allowed = ["replace", "add"]
|
||||
|
||||
super(TestValidator, self).__init__(methods_allowed)
|
||||
|
||||
|
||||
|
|
|
@ -64,7 +64,10 @@ def sort_url_by_qs_keys(url):
|
|||
|
||||
|
||||
def get_fake_request(path='', method='POST', is_admin=False, user=USER1,
|
||||
roles=['member'], tenant=TENANT1):
|
||||
roles=None, tenant=TENANT1):
|
||||
if roles is None:
|
||||
roles = ['member']
|
||||
|
||||
req = wsgi.Request.blank(path)
|
||||
req.method = method
|
||||
|
||||
|
|
|
@ -71,8 +71,11 @@ class TestImageActionsController(base.IsolatedUnitTest):
|
|||
self.controller.gateway.store_utils = self.store_utils
|
||||
store.create_stores()
|
||||
|
||||
def _get_fake_context(self, user=USER1, tenant=TENANT1, roles=['member'],
|
||||
def _get_fake_context(self, user=USER1, tenant=TENANT1, roles=None,
|
||||
is_admin=False):
|
||||
if roles is None:
|
||||
roles = ['member']
|
||||
|
||||
kwargs = {
|
||||
'user': user,
|
||||
'tenant': tenant,
|
||||
|
|
Loading…
Reference in New Issue