本文整理汇总了Python中pyramid.request.Request.body_file方法的典型用法代码示例。如果您正苦于以下问题:Python Request.body_file方法的具体用法?Python Request.body_file怎么用?Python Request.body_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.request.Request
的用法示例。
在下文中一共展示了Request.body_file方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_update
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import body_file [as 别名]
def test_create_update(self):
from papyrus.protocol import Protocol
from pyramid.request import Request
from geojson import Feature, FeatureCollection
from shapely.geometry import Point
from StringIO import StringIO
MappedClass = self._get_mapped_class()
# a mock session specific to this test
class MockSession(object):
def query(self, mapped_class):
return {'a': mapped_class(Feature(id='a')),
'b': mapped_class(Feature(id='b'))}
def flush(self):
pass
proto = Protocol(MockSession, MappedClass, 'geom')
# we need an actual Request object here, for body_file to do its job
request = Request({})
request.body_file = StringIO('{"type": "FeatureCollection", "features": [{"type": "Feature", "id": "a", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}, {"type": "Feature", "id": "b", "properties": {"text": "bar"}, "geometry": {"type": "Point", "coordinates": [46, 6]}}]}')
features = proto.create(request)
self.assertTrue(isinstance(features, FeatureCollection))
self.assertEqual(len(features.features), 2)
self.assertEqual(features.features[0].id, 'a')
self.assertEqual(features.features[0].text, 'foo')
self.assertTrue(features.features[0].geom.shape.equals(Point(45, 5)))
self.assertEqual(features.features[1].id, 'b')
self.assertEqual(features.features[1].text, 'bar')
self.assertTrue(features.features[1].geom.shape.equals(Point(46, 6)))
示例2: test_create
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import body_file [as 别名]
def test_create(self):
from papyrus.protocol import Protocol
from pyramid.request import Request
from pyramid.response import Response
from StringIO import StringIO
engine = self._get_engine()
Session = self._get_session(engine)
MappedClass = self._get_mapped_class()
class MockSession(object):
def add(self, o):
Session.add(o)
def flush(self):
pass
# a before_update callback
def before_create(request, feature, obj):
if not hasattr(request, '_log'):
request._log = []
request._log.append(dict(feature=feature, obj=obj))
proto = Protocol(MockSession, MappedClass, "geom",
before_create=before_create)
# we need an actual Request object here, for body_file to do its job
request = Request({})
request.body_file = StringIO('{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}, {"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}')
proto.create(request)
self.assertEqual(len(request.response_callbacks), 1)
self.assertEqual(len(Session.new), 2)
for obj in Session.new:
self.assertEqual(obj.text, 'foo')
self.assertEqual(obj.geom.shape.x, 45)
self.assertEqual(obj.geom.shape.y, 5)
Session.rollback()
# test before_create
self.assertTrue(hasattr(request, '_log'))
self.assertEqual(len(request._log), 2)
self.assertEqual(request._log[0]['feature'].properties['text'], 'foo')
self.assertEqual(request._log[0]['obj'], None)
self.assertEqual(request._log[1]['feature'].properties['text'], 'foo')
self.assertEqual(request._log[1]['obj'], None)
# test response status
response = Response(status_int=400)
request._process_response_callbacks(response)
self.assertEqual(response.status_int, 201)
示例3: test_create_badrequest
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import body_file [as 别名]
def test_create_badrequest(self):
from papyrus.protocol import Protocol
from pyramid.request import Request
from StringIO import StringIO
engine = self._get_engine()
Session = self._get_session(engine)
MappedClass = self._get_mapped_class()
proto = Protocol(Session, MappedClass, "geom")
# we need an actual Request object here, for body_file to do its job
request = Request({})
request.body_file = StringIO('{"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}')
response = proto.create(request)
self.assertEqual(response.status_int, 400)
示例4: test_update_forbidden
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import body_file [as 别名]
def test_update_forbidden(self):
from papyrus.protocol import Protocol
from pyramid.request import Request
from StringIO import StringIO
engine = self._get_engine()
Session = self._get_session(engine)
MappedClass = self._get_mapped_class()
proto = Protocol(Session, MappedClass, "geom", readonly=True)
# we need an actual Request object here, for body_file to do its job
request = Request({})
request.body_file = StringIO('{"type": "Feature", "id": 1, "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}')
response = proto.update(request, 1)
self.assertTrue(response.headers.get('Allow') == "GET, HEAD")
self.assertEqual(response.status_int, 405)
示例5: test_update_badrequest
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import body_file [as 别名]
def test_update_badrequest(self):
from papyrus.protocol import Protocol
from pyramid.request import Request
from StringIO import StringIO
# a mock session specific to this test
class MockSession(object):
def query(self, mapped_class):
return {'a': {}}
proto = Protocol(MockSession, self._get_mapped_class(), "geom")
# we need an actual Request object here, for body_file to do its job
request = Request({})
request.body_file = StringIO('{"type": "Point", "coordinates": [45, 5]}')
response = proto.update(request, 'a')
self.assertEqual(response.status_int, 400)
示例6: test_create_empty
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import body_file [as 别名]
def test_create_empty(self):
from papyrus.protocol import Protocol
from pyramid.request import Request
from pyramid.response import Response
from StringIO import StringIO
engine = self._get_engine()
Session = self._get_session(engine)
MappedClass = self._get_mapped_class()
proto = Protocol(Session, MappedClass, "geom")
# we need an actual Request object here, for body_file to do its job
request = Request({})
request.body_file = StringIO('{"type": "FeatureCollection", "features": []}')
resp = proto.create(request)
self.assertEqual(resp, None)
示例7: test_update
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import body_file [as 别名]
def test_update(self):
from papyrus.protocol import Protocol
from geojson import Feature
from pyramid.request import Request
from pyramid.response import Response
from geoalchemy import WKBSpatialElement
from StringIO import StringIO
MappedClass = self._get_mapped_class()
# a mock session specific to this test
class MockSession(object):
def query(self, mapped_class):
return {'a': MappedClass(Feature(id='a'))}
def flush(self):
pass
# a before_update callback
def before_update(request, feature, obj):
request._log = dict(feature=feature, obj=obj)
proto = Protocol(MockSession, MappedClass, "geom",
before_update=before_update)
# we need an actual Request object here, for body_file to do its job
request = Request({})
request.body_file = StringIO('{"type": "Feature", "id": "a", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}')
obj = proto.update(request, "a")
self.assertEqual(len(request.response_callbacks), 1)
self.assertTrue(isinstance(obj, MappedClass))
self.assertTrue(isinstance(obj.geom, WKBSpatialElement))
self.assertEqual(obj.text, "foo")
# test before_update
self.assertTrue(hasattr(request, '_log'))
self.assertEqual(request._log["feature"].id, 'a')
self.assertEqual(request._log["feature"].properties['text'], 'foo')
self.assertTrue(isinstance(request._log["obj"], MappedClass))
# test response status
response = Response(status_int=400)
request._process_response_callbacks(response)
self.assertEqual(response.status_int, 201)
示例8: test_update_notfound
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import body_file [as 别名]
def test_update_notfound(self):
from papyrus.protocol import Protocol
from pyramid.request import Request
from StringIO import StringIO
engine = self._get_engine()
Session = self._get_session(engine)
MappedClass = self._get_mapped_class()
# a mock session specific to this test
class MockSession(object):
def query(self, mapped_class):
return {}
proto = Protocol(MockSession, MappedClass, "geom")
# we need an actual Request object here, for body_file to do its job
request = Request({})
request.body_file = StringIO('{"type": "Feature", "id": 1, "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}')
response = proto.update(request, 1)
self.assertEqual(response.status_int, 404)