Skip to content

Commit 1339b2f

Browse files
committed
Fix test_flavors to run with correct microversion
test_flavors has microversion tests FlavorsTestV2_55 and FlavorsTestV2_61 which are suppose to run all the base class test with respective microversion. But few tests in base class does not set the microversion in request so they are always being run with 2.1 version even running under FlavorsTestV2_61. Fixing those tests by using the self._build_request() which set the microversion on request. Change-Id: Ic9d708e2c5559fa1adccc0e6bdb22f1143ca1fc0
1 parent a5cf4ae commit 1339b2f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

nova/tests/unit/api/openstack/compute/test_flavors.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def test_get_flavor_with_default_limit(self):
326326
self.stub_out('nova.api.openstack.common.get_limit_and_marker',
327327
fake_get_limit_and_marker)
328328
self.flags(max_limit=1, group='api')
329-
req = fakes.HTTPRequest.blank('/v2/fake/flavors?limit=2')
329+
req = self._build_request('/flavors?limit=2')
330330
response = self.controller.index(req)
331331
response_list = response["flavors"]
332332
response_links = response["flavors_links"]
@@ -347,6 +347,9 @@ def test_get_flavor_with_default_limit(self):
347347
]
348348
}
349349
]
350+
if self.expect_description:
351+
expected_flavors[0]['description'] = (
352+
fakes.FLAVORS['1'].description)
350353

351354
self.assertEqual(response_list, expected_flavors)
352355
self.assertEqual(response_links[0]['rel'], 'next')
@@ -526,7 +529,7 @@ def _test_list_flavors_with_invalid_filter(
526529
controller_list = self.controller.index
527530
if 'detail' in url:
528531
controller_list = self.controller.detail
529-
req = self.fake_request.blank(self._prefix + url)
532+
req = self._build_request(url)
530533
self.assertRaises(expected_exception,
531534
controller_list, req)
532535

@@ -574,6 +577,12 @@ def _test_list_flavors_duplicate_query_parameters_validation(
574577
}]
575578
if expected:
576579
expected_resp[0].update(expected)
580+
if self.expect_description:
581+
expected_resp[0]['description'] = (
582+
fakes.FLAVORS['2'].description)
583+
if 'detail' in url and self.expect_extra_specs:
584+
expected_resp[0]['extra_specs'] = (
585+
fakes.FLAVORS['2'].extra_specs)
577586
params = {
578587
'limit': 1,
579588
'marker': 1,
@@ -585,8 +594,8 @@ def _test_list_flavors_duplicate_query_parameters_validation(
585594
}
586595

587596
for param, value in params.items():
588-
req = self.fake_request.blank(
589-
self._prefix + url + '?marker=1&%s=%s&%s=%s' %
597+
req = self._build_request(
598+
url + '?marker=1&%s=%s&%s=%s' %
590599
(param, value, param, value))
591600
result = controller_list(req)
592601
self.assertEqual(expected_resp, result['flavors'])
@@ -632,7 +641,13 @@ def _test_list_flavors_with_allowed_filter(
632641
}]
633642
if expected:
634643
expected_resp[0].update(expected)
635-
req = self.fake_request.blank(self._prefix + url + '&limit=1&marker=1')
644+
if self.expect_description:
645+
expected_resp[0]['description'] = (
646+
fakes.FLAVORS['2'].description)
647+
if 'detail' in url and self.expect_extra_specs:
648+
expected_resp[0]['extra_specs'] = (
649+
fakes.FLAVORS['2'].extra_specs)
650+
req = self._build_request(url + '&limit=1&marker=1')
636651
result = controller_list(req)
637652
self.assertEqual(expected_resp, result['flavors'])
638653

0 commit comments

Comments
 (0)