def test_view_builder_show_extra_specs_policy(self): with mock.patch('cinder.context.RequestContext.authorize', side_effect=[True, False]): view_builder = views_types.ViewBuilder() now = timeutils.utcnow().isoformat() raw_volume_type = dict( name='new_type', description='new_type_desc', qos_specs_id='new_id', is_public=True, deleted=False, created_at=now, updated_at=now, extra_specs={}, deleted_at=None, id=42, ) request = fakes.HTTPRequest.blank("/v3") output = view_builder.show(request, raw_volume_type) self.assertIn('volume_type', output) expected_volume_type = dict( name='new_type', description='new_type_desc', extra_specs={}, is_public=True, id=42, ) self.assertDictEqual(expected_volume_type, output['volume_type']) with mock.patch('cinder.context.RequestContext.authorize', side_effect=[False, False]): view_builder = views_types.ViewBuilder() now = timeutils.utcnow().isoformat() raw_volume_type = dict( name='new_type', description='new_type_desc', qos_specs_id='new_id', is_public=True, deleted=False, created_at=now, updated_at=now, extra_specs={}, deleted_at=None, id=42, ) request = fakes.HTTPRequest.blank("/v3") output = view_builder.show(request, raw_volume_type) self.assertIn('volume_type', output) expected_volume_type = dict( name='new_type', description='new_type_desc', is_public=True, id=42, ) self.assertDictEqual(expected_volume_type, output['volume_type'])
def test_view_builder_list(self): view_builder = views_types.ViewBuilder() self.mock_authorize.return_value = False now = timeutils.utcnow().isoformat() raw_volume_types = [] for i in range(0, 10): raw_volume_types.append( dict( name='new_type', description='new_type_desc', qos_specs_id='new_id', is_public=True, deleted=False, created_at=now, updated_at=now, extra_specs={}, deleted_at=None, id=42 + i ) ) request = fakes.HTTPRequest.blank("/v3") output = view_builder.index(request, raw_volume_types) self.assertIn('volume_types', output) for i in range(0, 10): expected_volume_type = dict( name='new_type', description='new_type_desc', is_public=True, id=42 + i ) self.assertDictEqual(expected_volume_type, output['volume_types'][i])
def test_view_builder_show_admin(self): view_builder = views_types.ViewBuilder() self.mock_authorize.return_value = True now = timeutils.utcnow().isoformat() raw_volume_type = dict( name='new_type', description='new_type_desc', qos_specs_id='new_id', is_public=True, deleted=False, created_at=now, updated_at=now, extra_specs={}, deleted_at=None, id=42, ) request = fakes.HTTPRequest.blank("/v3", use_admin_context=True) output = view_builder.show(request, raw_volume_type) self.assertIn('volume_type', output) expected_volume_type = dict( name='new_type', description='new_type_desc', qos_specs_id='new_id', is_public=True, extra_specs={}, id=42, ) self.assertDictEqual(expected_volume_type, output['volume_type'])
def test_view_builder_show(self, extra_spec_policy, read_sensitive_policy, qos_policy): # This function returns the authorization result supplied by the # DDT data for the associated policy. def authorize(policy, fatal): policy_data = { type_policy.EXTRA_SPEC_POLICY: extra_spec_policy, extra_specs_policy.READ_SENSITIVE_POLICY: (read_sensitive_policy), type_policy.QOS_POLICY: qos_policy, } return policy_data[policy] view_builder = views_types.ViewBuilder() now = timeutils.utcnow().isoformat() raw_volume_type = dict( name='new_type', description='new_type_desc', qos_specs_id='new_id', is_public=True, deleted=False, created_at=now, updated_at=now, extra_specs={ 'multiattach': True, 'sensitive': 'secret' }, deleted_at=None, id=42, ) request = fakes.HTTPRequest.blank("/v3") with mock.patch('cinder.context.RequestContext.authorize', side_effect=authorize): output = view_builder.show(request, raw_volume_type) self.assertIn('volume_type', output) expected_volume_type = dict( name='new_type', description='new_type_desc', is_public=True, id=42, ) if extra_spec_policy: expected_volume_type['extra_specs'] = {'multiattach': True} if read_sensitive_policy: expected_volume_type['extra_specs']['sensitive'] = 'secret' if qos_policy: expected_volume_type['qos_specs_id'] = 'new_id' self.assertDictEqual(expected_volume_type, output['volume_type'])