本文整理汇总了Python中pyramid.request.Request.matchdict方法的典型用法代码示例。如果您正苦于以下问题:Python Request.matchdict方法的具体用法?Python Request.matchdict怎么用?Python Request.matchdict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.request.Request
的用法示例。
在下文中一共展示了Request.matchdict方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_items_delete
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import matchdict [as 别名]
def test_items_delete(self):
"""
Test deleting an item.
"""
# first create an item
self._create_item_status()
payload = {"name": "Macbook Air", "type": "TRADE", "quantity": "1",
"price": "", "description": "Lightweight lappy.",
"reason": "", "is_draft": "y", "uuid": str(uuid.uuid4())}
request = Request({}, method='POST', body=json.dumps(payload))
request.registry = self.config.registry
response = items(request)
self.assertEqual(response.status_code, 200)
self.assertEqual(DBSession.query(Item).count(), 1)
# try retrieving the newly added item
item = DBSession.query(Item).first()
# now send a delete request
request.method = 'DELETE'
request.matchdict = {'id': item.id}
request.body = None
items(request)
self.assertEqual(response.status_code, 200)
self.assertEqual(DBSession.query(Item).count(), 0)
示例2: test_item_image_delete_fail
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import matchdict [as 别名]
def test_item_image_delete_fail(self):
"""
Test deletion of non-existent image via DELETE request.
"""
# send DELETE request
request = Request({}, method='DELETE')
request.matchdict = {'id': 1}
request.registry = self.config.registry
self.assertRaises(HTTPBadRequest, item_images, None, request)
示例3: test_items_put_failed
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import matchdict [as 别名]
def test_items_put_failed(self):
"""
Test that updating non-existent item fails.
"""
payload = {"name": "Macbook Pro", "type": "SALE", "quantity": "5",
"price": "200.00", "description": "Lightweight lappy.",
"reason": "", "is_draft": "n", "id": 1}
request = Request({}, method='PUT', body=json.dumps(payload))
request.registry = self.config.registry
request.matchdict = {'id': 1}
request.method = 'PUT'
self.assertRaises(HTTPBadRequest, items, request)
self.assertEqual(DBSession.query(Item).count(), 0)
示例4: test_items_put
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import matchdict [as 别名]
def test_items_put(self):
"""
Test updating an item.
"""
self._create_item_status()
payload = {"name": "Macbook Air", "type": "TRADE", "quantity": "1",
"price": "", "description": "Lightweight lappy.",
"reason": "", "is_draft": "y", "uuid": str(uuid.uuid4())}
request = Request({}, method='POST', body=json.dumps(payload))
request.registry = self.config.registry
# make the request
items(request)
# try retrieving the newly added item
item = DBSession.query(Item).first()
self.failUnless(item)
payload = {"name": "Macbook Pro", "type": "SALE", "quantity": "5",
"price": "200.00", "description": "Lightweight lappy.",
"reason": "", "is_draft": "n", "id": item.id}
request.matchdict = {'id': item.id}
request.method = 'PUT'
request.body = json.dumps(payload)
# make the request again
response = items(request)
self.assertEqual(response.status_code, 200)
# reload item
item = DBSession.query(Item).filter_by(id=item.id).first()
self.assertEqual(item.name, payload['name'])
self.assertEqual(item.type, payload['type'])
self.assertEqual(item.quantity, int(payload['quantity']))
self.assertEqual(str(item.price), payload['price'])
self.assertEqual(item.status_id, self.draft_status.id)
示例5: test_item_image_delete
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import matchdict [as 别名]
def test_item_image_delete(self):
"""
Test that image is deleted when DELETE request is sent.
"""
self._create_item_status()
item = Item(name='iPhone', type='TRADE', quantity=1,
description='A smart phone', status=self.draft_status,
reason='just because')
DBSession.add(item)
DBSession.commit()
# write to disk the dummy image
mock_image = MockFileImage('original.jpg')
static_path = pkgr.resource_filename('tradeorsale', 'static')
item_images_path = os.path.join(static_path,
os.path.join('items/images', str(item.id)))
image_path = os.path.join(item_images_path, mock_image.filename)
with open(image_path, 'wb') as handle:
handle.write(mock_image.file.read())
self.failUnless(os.path.exists(image_path))
# save the image in db
item_image = ItemImage(item.id, mock_image.filename,
os.path.join('/%s' % item_images_path, mock_image.filename))
DBSession.add(item_image)
DBSession.commit()
# send DELETE request
request = Request({}, method='DELETE')
request.matchdict = {'id': item.id}
request.registry = self.config.registry
# check that record was deleted
response = item_images(None, request)
self.assertEqual(response.status_code, 200)
self.assertEqual(DBSession.query(ItemImage).count(), 0)
self.failUnless(not os.path.exists(image_path))