Replace assertDictContainsSubset in tests
This method has been removed from Python [1]. Replace it using the <= operator to check if a dict is a subset of another. [1] https://github.com/python/cpython/pull/28268 Change-Id: I39c87ff7e12d182bb73c782dc77d672e3194a32d
This commit is contained in:
parent
454f1edb39
commit
fa75c998ae
@ -604,13 +604,13 @@ class TestDriverKubernetes(tests.DBTestCase):
|
||||
objs = json.loads(data.decode('utf8'))
|
||||
# We don't check the value of 'locked' because we may get a
|
||||
# cached value returned.
|
||||
self.assertDictContainsSubset({'id': '0000000000',
|
||||
'ipv6': None,
|
||||
'label': ['kubernetes-namespace'],
|
||||
'provider': 'kubespray',
|
||||
'public_ipv4': None,
|
||||
'connection_port': 'redacted',
|
||||
'state': 'ready'}, objs[0])
|
||||
self.assertTrue({'id': '0000000000',
|
||||
'ipv6': None,
|
||||
'label': ['kubernetes-namespace'],
|
||||
'provider': 'kubespray',
|
||||
'public_ipv4': None,
|
||||
'connection_port': 'redacted',
|
||||
'state': 'ready'}.items() <= objs[0].items())
|
||||
|
||||
def test_kubernetes_custom(self):
|
||||
# Test a pod with a custom spec
|
||||
|
@ -116,10 +116,10 @@ class TestWebApp(tests.DBTestCase):
|
||||
'application/json')
|
||||
data = f.read()
|
||||
objs = json.loads(data.decode('utf8'))
|
||||
self.assertDictContainsSubset({'id': image.build_id,
|
||||
'image': 'fake-image',
|
||||
'provider': 'fake-provider',
|
||||
'state': 'ready'}, objs[0])
|
||||
self.assertTrue({'id': image.build_id,
|
||||
'image': 'fake-image',
|
||||
'provider': 'fake-provider',
|
||||
'state': 'ready'}.items() <= objs[0].items())
|
||||
|
||||
def test_dib_image_list_json(self):
|
||||
configfile = self.setup_config('node.yaml')
|
||||
@ -146,9 +146,9 @@ class TestWebApp(tests.DBTestCase):
|
||||
objs = json.loads(data.decode('utf8'))
|
||||
# make sure this is valid json and has some of the
|
||||
# non-changing keys
|
||||
self.assertDictContainsSubset({'id': f'fake-image-{image.build_id}',
|
||||
'formats': ['qcow2'],
|
||||
'state': 'ready'}, objs[0])
|
||||
self.assertTrue({'id': f'fake-image-{image.build_id}',
|
||||
'formats': ['qcow2'],
|
||||
'state': 'ready'}.items() <= objs[0].items())
|
||||
|
||||
def test_image_status_json(self):
|
||||
configfile = self.setup_config("node.yaml")
|
||||
@ -178,9 +178,9 @@ class TestWebApp(tests.DBTestCase):
|
||||
|
||||
data = f.read()
|
||||
objs = json.loads(data.decode("utf8"))
|
||||
self.assertDictContainsSubset({"image": "fake-image",
|
||||
"paused": False,
|
||||
"build_request": None}, objs[0])
|
||||
self.assertTrue({"image": "fake-image",
|
||||
"paused": False,
|
||||
"build_request": None}.items() <= objs[0].items())
|
||||
|
||||
self.zk.submitBuildRequest("fake-image")
|
||||
|
||||
@ -188,9 +188,11 @@ class TestWebApp(tests.DBTestCase):
|
||||
f = request.urlopen(req)
|
||||
data = f.read()
|
||||
objs = json.loads(data.decode("utf8"))
|
||||
self.assertDictContainsSubset({"image": "fake-image",
|
||||
"paused": False,
|
||||
"build_request": "pending"}, objs[0])
|
||||
self.assertTrue({
|
||||
"image": "fake-image",
|
||||
"paused": False,
|
||||
"build_request": "pending"
|
||||
}.items() <= objs[0].items())
|
||||
|
||||
builder._janitor._emitBuildRequestStats()
|
||||
self.assertReportedStat('nodepool.image_build_requests', '1', 'g')
|
||||
@ -201,9 +203,11 @@ class TestWebApp(tests.DBTestCase):
|
||||
data = f.read()
|
||||
|
||||
objs = json.loads(data.decode("utf8"))
|
||||
self.assertDictContainsSubset({"image": "fake-image",
|
||||
"paused": False,
|
||||
"build_request": "building"}, objs[0])
|
||||
self.assertTrue({
|
||||
"image": "fake-image",
|
||||
"paused": False,
|
||||
"build_request": "building"
|
||||
}.items() <= objs[0].items())
|
||||
|
||||
def test_node_list_json(self):
|
||||
configfile = self.setup_config('node.yaml')
|
||||
@ -227,13 +231,13 @@ class TestWebApp(tests.DBTestCase):
|
||||
objs = json.loads(data.decode('utf8'))
|
||||
# We don't check the value of 'locked' because we may get a
|
||||
# cached value returned.
|
||||
self.assertDictContainsSubset({'id': '0000000000',
|
||||
'ipv6': '',
|
||||
'label': ['fake-label'],
|
||||
'provider': 'fake-provider',
|
||||
'public_ipv4': 'fake',
|
||||
'connection_port': 22,
|
||||
'state': 'ready'}, objs[0])
|
||||
self.assertTrue({'id': '0000000000',
|
||||
'ipv6': '',
|
||||
'label': ['fake-label'],
|
||||
'provider': 'fake-provider',
|
||||
'public_ipv4': 'fake',
|
||||
'connection_port': 22,
|
||||
'state': 'ready'}.items() <= objs[0].items())
|
||||
self.assertTrue('locked' in objs[0])
|
||||
# specify valid node_id
|
||||
req = request.Request(
|
||||
@ -247,13 +251,13 @@ class TestWebApp(tests.DBTestCase):
|
||||
objs = json.loads(data.decode('utf8'))
|
||||
# We don't check the value of 'locked' because we may get a
|
||||
# cached value returned.
|
||||
self.assertDictContainsSubset({'id': '0000000000',
|
||||
'ipv6': '',
|
||||
'label': ['fake-label'],
|
||||
'provider': 'fake-provider',
|
||||
'public_ipv4': 'fake',
|
||||
'connection_port': 22,
|
||||
'state': 'ready'}, objs[0])
|
||||
self.assertTrue({'id': '0000000000',
|
||||
'ipv6': '',
|
||||
'label': ['fake-label'],
|
||||
'provider': 'fake-provider',
|
||||
'public_ipv4': 'fake',
|
||||
'connection_port': 22,
|
||||
'state': 'ready'}.items() <= objs[0].items())
|
||||
self.assertTrue('locked' in objs[0])
|
||||
# node_id not found
|
||||
req = request.Request(
|
||||
@ -299,10 +303,9 @@ class TestWebApp(tests.DBTestCase):
|
||||
data = f.read()
|
||||
objs = json.loads(data.decode('utf8'))
|
||||
objs = [o for o in objs if 'min-ready' not in o['requestor']]
|
||||
self.assertDictContainsSubset({'node_types': ['fake-label'],
|
||||
'requestor': 'test_request_list',
|
||||
'event_id': req.event_id, },
|
||||
objs[0])
|
||||
self.assertTrue({'node_types': ['fake-label'],
|
||||
'requestor': 'test_request_list',
|
||||
'event_id': req.event_id}.items() <= objs[0].items())
|
||||
|
||||
def test_label_list_json(self):
|
||||
configfile = self.setup_config('node.yaml')
|
||||
|
Loading…
x
Reference in New Issue
Block a user