~ubuntu-branches/ubuntu/raring/glance/raring-proposed

« back to all changes in this revision

Viewing changes to glance/tests/unit/v1/test_api.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Chuck Short
  • Date: 2013-03-20 07:42:22 UTC
  • mfrom: (1.1.50)
  • Revision ID: package-import@ubuntu.com-20130320074222-d8oochgvhjooh1a5
Tags: 1:2013.1~rc1-0ubuntu1
[ James Page ]
* d/watch: Update uversionmangle to deal with upstream versioning
  changes, remove tarballs.openstack.org.

[ Chuck Short ]
* New upstrem release
* debian/control: Clean up build-dependencies:
  - Drop python-argparse referenced in pydist-overrides
  - Drop python-swift no longer needed.
  - Drop python-dateutils no longer needed.
  - Drop python-glacneclient no longer needed.
  - Added python-anyjson to build-depends.
  - Use python-keystoneclient instead of python-keystone.
  - Added python-lxml to build-depends.
  - Added python-swiftclientto build-depends.
  - Added python-passlib to build-depends.
* debian/rules: Set the PYTHONPATH for the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#    License for the specific language governing permissions and limitations
17
17
#    under the License.
18
18
 
 
19
import copy
19
20
import datetime
20
21
import hashlib
21
22
import httplib
124
125
             'min_disk': 0,
125
126
             'min_ram': 0,
126
127
             'size': 13,
127
 
             'location': "file:///%s/%s" % (self.test_dir, UUID1),
 
128
             'locations': ["file:///%s/%s" % (self.test_dir, UUID1)],
128
129
             'properties': {'type': 'kernel'}},
129
130
            {'id': UUID2,
130
131
             'name': 'fake image #2',
140
141
             'min_disk': 5,
141
142
             'min_ram': 256,
142
143
             'size': 19,
143
 
             'location': "file:///%s/%s" % (self.test_dir, UUID2),
 
144
             'locations': ["file:///%s/%s" % (self.test_dir, UUID2)],
144
145
             'properties': {}}]
145
146
        self.context = glance.context.RequestContext(is_admin=True)
146
147
        db_api.configure_db()
1942
1943
             'deleted': False,
1943
1944
             'checksum': None,
1944
1945
             'size': 13,
1945
 
             'location': "file:///%s/%s" % (self.test_dir, UUID1),
 
1946
             'locations': ["file:///%s/%s" % (self.test_dir, UUID1)],
1946
1947
             'properties': {'type': 'kernel'}},
1947
1948
            {'id': UUID2,
1948
1949
             'name': 'fake image #2',
1956
1957
             'deleted': False,
1957
1958
             'checksum': None,
1958
1959
             'size': 19,
1959
 
             'location': "file:///%s/%s" % (self.test_dir, UUID2),
 
1960
             'locations': ["file:///%s/%s" % (self.test_dir, UUID2)],
1960
1961
             'properties': {}}]
1961
1962
        self.context = glance.context.RequestContext(is_admin=True)
1962
1963
        db_api.configure_db()
2322
2323
        res = req.get_response(self.api)
2323
2324
        self.assertEquals(res.status_int, 403)
2324
2325
 
2325
 
    def test_add_public_image_unauthorized(self):
2326
 
        rules = {"add_image": '@', "publicize_image": '!'}
 
2326
    def test_add_publicize_image_unauthorized(self):
 
2327
        rules = {"add_image": '@', "modify_image": '@',
 
2328
                 "publicize_image": '!'}
2327
2329
        self.set_policy_rules(rules)
2328
2330
        fixture_headers = {'x-image-meta-store': 'file',
2329
2331
                           'x-image-meta-is-public': 'true',
2341
2343
        res = req.get_response(self.api)
2342
2344
        self.assertEquals(res.status_int, 403)
2343
2345
 
 
2346
    def test_add_publicize_image_authorized(self):
 
2347
        rules = {"add_image": '@', "modify_image": '@',
 
2348
                 "publicize_image": '@'}
 
2349
        self.set_policy_rules(rules)
 
2350
        fixture_headers = {'x-image-meta-store': 'file',
 
2351
                           'x-image-meta-is-public': 'true',
 
2352
                           'x-image-meta-disk-format': 'vhd',
 
2353
                           'x-image-meta-container-format': 'ovf',
 
2354
                           'x-image-meta-name': 'fake image #3'}
 
2355
 
 
2356
        req = webob.Request.blank("/images")
 
2357
        req.method = 'POST'
 
2358
        for k, v in fixture_headers.iteritems():
 
2359
            req.headers[k] = v
 
2360
 
 
2361
        req.headers['Content-Type'] = 'application/octet-stream'
 
2362
        req.body = "chunk00000remainder"
 
2363
        res = req.get_response(self.api)
 
2364
        self.assertEquals(res.status_int, httplib.CREATED)
 
2365
 
2344
2366
    def _do_test_post_image_content_missing_format(self, missing):
2345
2367
        """Tests creation of an image with missing format"""
2346
2368
        fixture_headers = {'x-image-meta-store': 'file',
3441
3463
                                                  self.serializer.notifier)
3442
3464
 
3443
3465
        self.assertTrue(called['notified'])
 
3466
 
 
3467
    def test_redact_location(self):
 
3468
        """Ensure location redaction does not change original metadata"""
 
3469
        image_meta = {'size': 3, 'id': '123', 'location': 'http://localhost'}
 
3470
        redacted_image_meta = {'size': 3, 'id': '123'}
 
3471
        copy_image_meta = copy.deepcopy(image_meta)
 
3472
        tmp_image_meta = glance.api.v1.images.redact_loc(image_meta)
 
3473
 
 
3474
        self.assertEqual(image_meta, copy_image_meta)
 
3475
        self.assertEqual(tmp_image_meta, redacted_image_meta)
 
3476
 
 
3477
    def test_noop_redact_location(self):
 
3478
        """Check no-op location redaction does not change original metadata"""
 
3479
        image_meta = {'size': 3, 'id': '123'}
 
3480
        redacted_image_meta = {'size': 3, 'id': '123'}
 
3481
        copy_image_meta = copy.deepcopy(image_meta)
 
3482
        tmp_image_meta = glance.api.v1.images.redact_loc(image_meta)
 
3483
 
 
3484
        self.assertEqual(image_meta, copy_image_meta)
 
3485
        self.assertEqual(tmp_image_meta, redacted_image_meta)
 
3486
        self.assertEqual(image_meta, redacted_image_meta)