Beispiel #1
0
 def test_create_with_id(self):
     request = test_utils.FakeRequest()
     image_id = utils.generate_uuid()
     request.body = json.dumps({'id': image_id})
     output = self.deserializer.create(request)
     expected = {'image': {'id': image_id, 'properties': {}}}
     self.assertEqual(expected, output)
Beispiel #2
0
 def test_update_readonly_attributes_ignored(self):
     for key in ['created_at', 'updated_at']:
         request = test_utils.FakeRequest()
         request.body = json.dumps({key: ISOTIME})
         output = self.deserializer.update(request)
         expected = {'image': {'properties': {}}}
         self.assertEqual(expected, output)
Beispiel #3
0
 def test_list_tags(self):
     request = test_utils.FakeRequest()
     tags = self.controller.index(request, test_utils.UUID1)
     expected = [
         {'value': 'ping', 'image_id': test_utils.UUID1},
         {'value': 'pong', 'image_id': test_utils.UUID1},
     ]
     self.assertEqual(expected, tags)
Beispiel #4
0
 def test_create_bad_data(self):
     fixture = {
         'tenant_id': test_utils.TENANT1,
         'can_share': False,
         'color': 'purple',
     }
     request = test_utils.FakeRequest()
     request.body = json.dumps(fixture)
     self.assertRaises(exception.InvalidObject,
             self.deserializer.create, request)
 def test_upload(self):
     request = test_utils.FakeRequest()
     request.headers['Content-Type'] = 'application/octet-stream'
     request.body = 'YYY'
     request.headers['Content-Length'] = 3
     output = self.deserializer.upload(request)
     data = output.pop('data')
     self.assertEqual(data.getvalue(), 'YYY')
     expected = {'size': 3}
     self.assertEqual(expected, output)
 def test_upload_chunked(self):
     request = test_utils.FakeRequest()
     request.headers['Content-Type'] = 'application/octet-stream'
     # If we use body_file, webob assumes we want to do a chunked upload,
     # ignoring the Content-Length header
     request.body_file = StringIO.StringIO('YYY')
     output = self.deserializer.upload(request)
     data = output.pop('data')
     self.assertEqual(data.getvalue(), 'YYY')
     expected = {'size': None}
     self.assertEqual(expected, output)
Beispiel #7
0
 def test_show(self):
     req = test_utils.FakeRequest()
     image_id = test_utils.UUID1
     tenant_id = test_utils.TENANT1
     output = self.controller.show(req, image_id, tenant_id)
     expected = {
         'image_id': image_id,
         'member': tenant_id,
         'can_share': True,
         'deleted': False,
     }
     self.assertEqual(expected, output)
Beispiel #8
0
 def test_update(self):
     request = test_utils.FakeRequest()
     request.body = json.dumps({'name': 'image-1', 'visibility': 'public'})
     output = self.deserializer.update(request)
     expected = {
         'image': {
             'name': 'image-1',
             'is_public': True,
             'properties': {},
         },
     }
     self.assertEqual(expected, output)
 def test_upload_chunked_with_content_length(self):
     request = test_utils.FakeRequest()
     request.headers['Content-Type'] = 'application/octet-stream'
     request.body_file = StringIO.StringIO('YYY')
     # The deserializer shouldn't care if the Content-Length is
     # set when the user is attempting to send chunked data.
     request.headers['Content-Length'] = 3
     output = self.deserializer.upload(request)
     data = output.pop('data')
     self.assertEqual(data.getvalue(), 'YYY')
     expected = {'size': 3}
     self.assertEqual(expected, output)
Beispiel #10
0
 def test_update(self):
     request = test_utils.FakeRequest()
     request.body = json.dumps({'name': 'image-1', 'pants': 'off'})
     output = self.deserializer.update(request)
     expected = {
         'image': {
             'name': 'image-1',
             'properties': {
                 'pants': 'off'
             },
         },
     }
     self.assertEqual(expected, output)
 def test_upload_with_incorrect_content_length(self):
     request = test_utils.FakeRequest()
     request.headers['Content-Type'] = 'application/octet-stream'
     # The deserializer shouldn't care if the Content-Length and
     # actual request body length differ. That job is left up
     # to the controller
     request.body = 'YYY'
     request.headers['Content-Length'] = 4
     output = self.deserializer.upload(request)
     data = output.pop('data')
     self.assertEqual(data.getvalue(), 'YYY')
     expected = {'size': 4}
     self.assertEqual(expected, output)
Beispiel #12
0
 def test_update(self):
     request = test_utils.FakeRequest()
     image = {'name': 'image-2'}
     output = self.controller.update(request, test_utils.UUID1, image)
     for key in ['id', 'created_at', 'updated_at']:
         output.pop(key)
     expected = {
         'name': 'image-2',
         'owner': test_utils.TENANT1,
         'location': test_utils.UUID1,
         'status': 'queued',
         'is_public': False,
         'properties': {},
     }
     self.assertEqual(expected, output)
Beispiel #13
0
 def test_create(self):
     member = utils.generate_uuid()
     fixture = {
         'member': member,
         'can_share': True,
     }
     expected = {
         'image_id': test_utils.UUID1,
         'member': member,
         'can_share': True,
         'deleted': False,
     }
     req = test_utils.FakeRequest()
     output = self.controller.create(req, test_utils.UUID1, fixture)
     self.assertEqual(expected, output)
Beispiel #14
0
 def test_create(self):
     fixture = {
         'tenant_id': test_utils.TENANT1,
         'can_share': False,
     }
     expected = {
         'access_record': {
             'member': test_utils.TENANT1,
             'can_share': False,
         },
     }
     request = test_utils.FakeRequest()
     request.body = json.dumps(fixture)
     output = self.deserializer.create(request)
     self.assertEqual(expected, output)
Beispiel #15
0
 def test_create_public_image_as_admin(self):
     request = test_utils.FakeRequest()
     image = {'name': 'image-1', 'is_public': True}
     output = self.controller.create(request, image)
     for key in ['id', 'created_at', 'updated_at']:
         output.pop(key)
     expected = {
         'name': 'image-1',
         'owner': test_utils.TENANT1,
         'location': None,
         'status': 'queued',
         'is_public': True,
         'properties': {},
     }
     self.assertEqual(expected, output)
Beispiel #16
0
 def test_index(self):
     req = test_utils.FakeRequest()
     output = self.controller.index(req)
     expected = {
         'links': [
             {
                 'rel': 'schemas',
                 'href': '/v2/schemas'
             },
             {
                 'rel': 'images',
                 'href': '/v2/images'
             },
         ],
     }
     self.assertEqual(expected, output)
Beispiel #17
0
 def test_index(self):
     req = test_utils.FakeRequest()
     output = self.controller.index(req, test_utils.UUID1)
     expected = [
         {
             'image_id': test_utils.UUID1,
             'member': test_utils.TENANT1,
             'can_share': True,
             'deleted': False,
         },
         {
             'image_id': test_utils.UUID1,
             'member': test_utils.TENANT2,
             'can_share': False,
             'deleted': False,
         },
     ]
     self.assertEqual(expected, output)
Beispiel #18
0
 def test_update_bad_data(self):
     request = test_utils.FakeRequest()
     request.body = json.dumps({'name': 'image-1', 'pants': 'borked'})
     self.assertRaises(exception.InvalidObject, self.deserializer.update,
                       request)
Beispiel #19
0
 def test_index_nonexistant_image(self):
     req = test_utils.FakeRequest()
     image_id = utils.generate_uuid()
     self.assertRaises(exception.NotFound,
                       self.controller.index, req, image_id)
Beispiel #20
0
 def test_index_zero_records(self):
     req = test_utils.FakeRequest()
     output = self.controller.index(req, test_utils.UUID2)
     expected = []
     self.assertEqual(expected, output)
Beispiel #21
0
 def test_create_with_numeric_property(self):
     request = test_utils.FakeRequest()
     request.body = json.dumps({'abc': 123})
     self.assertRaises(exception.InvalidObject, self.deserializer.create,
                       request)
Beispiel #22
0
 def test_update_with_additional_properties_disallowed(self):
     self.conf.allow_additional_image_properties = False
     request = test_utils.FakeRequest()
     request.body = json.dumps({'foo': 'bar'})
     self.assertRaises(exception.InvalidObject, self.deserializer.update,
                       request)
Beispiel #23
0
 def test_create_with_owner_forbidden(self):
     request = test_utils.FakeRequest()
     image = {'name': 'image-1', 'owner': utils.generate_uuid()}
     self.assertRaises(webob.exc.HTTPForbidden, self.controller.create,
                       request, image)
Beispiel #24
0
 def test_show_non_existant(self):
     self.assertRaises(webob.exc.HTTPNotFound,
                       self.controller.show,
                       test_utils.FakeRequest(),
                       image_id=utils.generate_uuid())
Beispiel #25
0
 def test_show(self):
     request = test_utils.FakeRequest()
     output = self.controller.show(request, image_id=test_utils.UUID2)
     self.assertEqual(output['id'], test_utils.UUID2)
Beispiel #26
0
 def test_index_zero_images(self):
     self.db.reset()
     request = test_utils.FakeRequest()
     output = self.controller.index(request)
     self.assertEqual([], output)
Beispiel #27
0
 def test_create_with_list_property(self):
     request = test_utils.FakeRequest()
     request.body = json.dumps({'foo': ['bar']})
     self.assertRaises(exception.InvalidObject, self.deserializer.create,
                       request)
Beispiel #28
0
 def test_show_nonexistant_tenant(self):
     req = test_utils.FakeRequest()
     image_id = test_utils.UUID1
     tenant_id = utils.generate_uuid()
     self.assertRaises(webob.exc.HTTPNotFound,
                       self.controller.show, req, image_id, tenant_id)
Beispiel #29
0
 def test_index(self):
     request = test_utils.FakeRequest()
     output = self.controller.index(request)
     self.assertEqual(2, len(output))
     self.assertEqual(output[0]['id'], test_utils.UUID1)
     self.assertEqual(output[1]['id'], test_utils.UUID2)
Beispiel #30
0
 def test_update(self):
     request = test_utils.FakeRequest()
     request.body = json.dumps({'foo': 'bar'})
     output = self.deserializer.update(request)
     expected = {'image': {'properties': {'foo': 'bar'}}}
     self.assertEqual(expected, output)