Skip to content

Commit

Permalink
Fix test_flavors to run with correct microversion
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gmannos committed Jun 28, 2019
1 parent a5cf4ae commit 1339b2f
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions nova/tests/unit/api/openstack/compute/test_flavors.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def test_get_flavor_with_default_limit(self):
self.stub_out('nova.api.openstack.common.get_limit_and_marker',
fake_get_limit_and_marker)
self.flags(max_limit=1, group='api')
req = fakes.HTTPRequest.blank('/v2/fake/flavors?limit=2')
req = self._build_request('/flavors?limit=2')
response = self.controller.index(req)
response_list = response["flavors"]
response_links = response["flavors_links"]
Expand All @@ -347,6 +347,9 @@ def test_get_flavor_with_default_limit(self):
]
}
]
if self.expect_description:
expected_flavors[0]['description'] = (
fakes.FLAVORS['1'].description)

self.assertEqual(response_list, expected_flavors)
self.assertEqual(response_links[0]['rel'], 'next')
Expand Down Expand Up @@ -526,7 +529,7 @@ def _test_list_flavors_with_invalid_filter(
controller_list = self.controller.index
if 'detail' in url:
controller_list = self.controller.detail
req = self.fake_request.blank(self._prefix + url)
req = self._build_request(url)
self.assertRaises(expected_exception,
controller_list, req)

Expand Down Expand Up @@ -574,6 +577,12 @@ def _test_list_flavors_duplicate_query_parameters_validation(
}]
if expected:
expected_resp[0].update(expected)
if self.expect_description:
expected_resp[0]['description'] = (
fakes.FLAVORS['2'].description)
if 'detail' in url and self.expect_extra_specs:
expected_resp[0]['extra_specs'] = (
fakes.FLAVORS['2'].extra_specs)
params = {
'limit': 1,
'marker': 1,
Expand All @@ -585,8 +594,8 @@ def _test_list_flavors_duplicate_query_parameters_validation(
}

for param, value in params.items():
req = self.fake_request.blank(
self._prefix + url + '?marker=1&%s=%s&%s=%s' %
req = self._build_request(
url + '?marker=1&%s=%s&%s=%s' %
(param, value, param, value))
result = controller_list(req)
self.assertEqual(expected_resp, result['flavors'])
Expand Down Expand Up @@ -632,7 +641,13 @@ def _test_list_flavors_with_allowed_filter(
}]
if expected:
expected_resp[0].update(expected)
req = self.fake_request.blank(self._prefix + url + '&limit=1&marker=1')
if self.expect_description:
expected_resp[0]['description'] = (
fakes.FLAVORS['2'].description)
if 'detail' in url and self.expect_extra_specs:
expected_resp[0]['extra_specs'] = (
fakes.FLAVORS['2'].extra_specs)
req = self._build_request(url + '&limit=1&marker=1')
result = controller_list(req)
self.assertEqual(expected_resp, result['flavors'])

Expand Down

0 comments on commit 1339b2f

Please sign in to comment.