~ubuntu-branches/ubuntu/raring/cinder/raring-updates

« back to all changes in this revision

Viewing changes to cinder/tests/api/contrib/test_extended_snapshot_attributes.py

Tags: upstream-2013.1~g2
ImportĀ upstreamĀ versionĀ 2013.1~g2

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from cinder import flags
22
22
from cinder.openstack.common import jsonutils
23
23
from cinder import test
24
 
from cinder.tests.api.openstack import fakes
 
24
from cinder.tests.api import fakes
25
25
from cinder import volume
26
26
 
27
27
 
33
33
 
34
34
 
35
35
def _get_default_snapshot_param():
36
 
    return {
37
 
        'id': UUID1,
38
 
        'volume_id': 12,
39
 
        'status': 'available',
40
 
        'volume_size': 100,
41
 
        'created_at': None,
42
 
        'display_name': 'Default name',
43
 
        'display_description': 'Default description',
44
 
        'project_id': 'fake',
45
 
        'progress': '0%'
46
 
        }
 
36
    return {'id': UUID1,
 
37
            'volume_id': 12,
 
38
            'status': 'available',
 
39
            'volume_size': 100,
 
40
            'created_at': None,
 
41
            'display_name': 'Default name',
 
42
            'display_description': 'Default description',
 
43
            'project_id': 'fake',
 
44
            'progress': '0%'}
47
45
 
48
46
 
49
47
def fake_snapshot_get(self, context, snapshot_id):
80
78
 
81
79
    def assertSnapshotAttributes(self, snapshot, project_id, progress):
82
80
        self.assertEqual(snapshot.get('%sproject_id' % self.prefix),
83
 
                                      project_id)
 
81
                         project_id)
84
82
        self.assertEqual(snapshot.get('%sprogress' % self.prefix), progress)
85
83
 
86
84
    def test_show(self):
87
 
        url = '/v1/fake/snapshots/%s' % UUID2
 
85
        url = '/v2/fake/snapshots/%s' % UUID2
88
86
        res = self._make_request(url)
89
87
 
90
88
        self.assertEqual(res.status_int, 200)
91
89
        self.assertSnapshotAttributes(self._get_snapshot(res.body),
92
 
                                project_id='fake',
93
 
                                progress='0%')
 
90
                                      project_id='fake',
 
91
                                      progress='0%')
94
92
 
95
93
    def test_detail(self):
96
 
        url = '/v1/fake/snapshots/detail'
 
94
        url = '/v2/fake/snapshots/detail'
97
95
        res = self._make_request(url)
98
96
 
99
97
        self.assertEqual(res.status_int, 200)
100
98
        for i, snapshot in enumerate(self._get_snapshots(res.body)):
101
99
            self.assertSnapshotAttributes(snapshot,
102
 
                                    project_id='fake',
103
 
                                    progress='0%')
 
100
                                          project_id='fake',
 
101
                                          progress='0%')
104
102
 
105
103
    def test_no_instance_passthrough_404(self):
106
104
 
107
105
        def fake_snapshot_get(*args, **kwargs):
108
 
            raise exception.InstanceNotFound()
 
106
            raise exception.InstanceNotFound(instance_id='fake')
109
107
 
110
108
        self.stubs.Set(volume.api.API, 'get_snapshot', fake_snapshot_get)
111
 
        url = '/v1/fake/snapshots/70f6db34-de8d-4fbd-aafb-4065bdfa6115'
 
109
        url = '/v2/fake/snapshots/70f6db34-de8d-4fbd-aafb-4065bdfa6115'
112
110
        res = self._make_request(url)
113
111
 
114
112
        self.assertEqual(res.status_int, 404)