当前位置: 首页>>代码示例>>Python>>正文


Python Request.matchdict方法代码示例

本文整理汇总了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)
开发者ID:basco-johnkevin,项目名称:tradeorsale,代码行数:29,代码来源:test_views.py

示例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)
开发者ID:basco-johnkevin,项目名称:tradeorsale,代码行数:12,代码来源:test_views.py

示例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)
开发者ID:basco-johnkevin,项目名称:tradeorsale,代码行数:17,代码来源:test_views.py

示例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)
开发者ID:basco-johnkevin,项目名称:tradeorsale,代码行数:41,代码来源:test_views.py

示例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))
开发者ID:basco-johnkevin,项目名称:tradeorsale,代码行数:39,代码来源:test_views.py


注:本文中的pyramid.request.Request.matchdict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。