def test_volume_get_metadata(self, cc): request = self.mock_rest_request(**{'GET': {}}) cc.volume_get.return_value = mock.Mock( **{'to_dict.return_value': {'id': 'one', 'metadata': {'foo': 'bar'}}}) response = cinder.VolumeMetadata().get(request, '1') self.assertStatusCode(response, 200) self.assertEqual(response.json, {'foo': 'bar'}) cc.volume_get.assert_called_once_with(request, '1')
def test_volume_get_metadata(self): request = self.mock_rest_request(**{'GET': {}}) vol = self.cinder_volumes.first() vol._apiresource.metadata = {'foo': 'bar'} self.mock_volume_get.return_value = vol response = cinder.VolumeMetadata().get(request, '1') self.assertStatusCode(response, 200) self.assertEqual(vol.to_dict()['metadata'], response.json) self.mock_volume_get.assert_called_once_with(request, '1')
def test_volume_update_metadata(self, cc): request = self.mock_rest_request( body='{"updated": {"a": "1", "b": "2"}, ' '"removed": ["c", "d"]}') response = cinder.VolumeMetadata().patch(request, '1') self.assertStatusCode(response, 204) self.assertEqual(b'', response.content) cc.volume_set_metadata.assert_called_once_with(request, '1', { 'a': '1', 'b': '2' }) cc.volume_delete_metadata.assert_called_once_with( request, '1', ['c', 'd'])