本文整理汇总了Python中pyramid.testing.DummyRequest类的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest类的具体用法?Python DummyRequest怎么用?Python DummyRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DummyRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_PUT_using_header
def test_PUT_using_header(self):
app = self._make_app()
request = DummyRequest(method='POST')
request.headers['X-HTTP-Method-Override'] = 'PUT'
self._assert_before(request)
app.registry.notify(NewRequest(request))
self._assert_after(request, 'PUT')
示例2: test_forbidden
def test_forbidden(self):
from ptahcrowd.forbidden import Forbidden
class Context(object):
""" """
request = DummyRequest()
request.url = 'http://example.com'
request.application_url = 'http://example.com'
request.root = Context()
excview = Forbidden(HTTPForbidden(), request)
excview.update()
res = request.response
self.assertIs(excview.__parent__, request.root)
self.assertEqual(res.status, '302 Found')
self.assertEqual(
text_(res.headers['location']),
'http://example.com/login.html?came_from=http%3A%2F%2Fexample.com')
excview = Forbidden(HTTPForbidden(), request)
res = excview()
self.assertEqual(res.status, '302 Found')
示例3: test__get_child_layers_info_without_scalehint
def test__get_child_layers_info_without_scalehint(self):
from pyramid.testing import DummyRequest
from c2cgeoportal.views.entry import Entry
request = DummyRequest()
request.user = None
entry = Entry(request)
class Layer(object):
pass
child_layer_1 = Layer()
child_layer_1.name = 'layer_1'
child_layer_1.scaleHint = None
child_layer_1.layers = []
child_layer_2 = Layer()
child_layer_2.name = 'layer_2'
child_layer_2.scaleHint = None
child_layer_2.layers = []
layer = Layer()
layer.layers = [child_layer_1, child_layer_2]
child_layers_info = entry._get_child_layers_info(layer)
expected = [{
'name': 'layer_1'
}, {
'name': 'layer_2',
}]
self.assertEqual(child_layers_info, expected)
示例4: test_profile_csv
def test_profile_csv(self):
from pyramid.testing import DummyRequest
from c2cgeoportal.views.profile import Profile
request = DummyRequest()
request.registry.settings = {
"raster": {
"dem": {"file": "c2cgeoportal/tests/data/dem.shp", "round": 1},
"dem2": {"file": "c2cgeoportal/tests/data/dem.shp", "round": 1}
}
}
profile = Profile(request)
request.params["nbPoints"] = "3"
request.params["geom"] = '{"type":"LineString",' \
'"coordinates":[[548009.5,215990],[547990,216009.5]]}'
response = profile.csv()
self.assertEqual(response.body, """distance,dem2,dem,x,y
0.0,1166,1166,548009,215990
9.2,1181,1181,548003,215996
18.4,1181,1181,547996,216003""")
request.params["layers"] = "dem"
response = profile.csv()
self.assertEqual(response.body, """distance,dem,x,y
0.0,1166,548009,215990
9.2,1181,548003,215996
18.4,1181,547996,216003""")
示例5: dummy_request
def dummy_request(self):
request = DummyRequest()
request.context = DummyResource()
request.userdb = self.userdb
request.db = self.db
request.registry.settings = self.settings
return request
示例6: _makeRequest
def _makeRequest(self, db, fs):
from pyramid.testing import DummyRequest
request = DummyRequest()
request.db = db
request.fs = fs
return request
示例7: test_websocket_good_origin
def test_websocket_good_origin(config):
config.registry.settings.update({'origins': 'http://good'})
config.include('h.streamer')
req = DummyRequest(headers={'Origin': 'http://good'})
req.get_response = MagicMock()
res = websocket(req)
assert res.code != 403
示例8: test_remember_me_with_bad_endpoint
def test_remember_me_with_bad_endpoint(self):
"""Test the post-login hook with a bad openid endpoint"""
req = DummyRequest(params={
'openid.op_endpoint': 'bad_endpoint',
})
req.db = self.db
def flash(msg):
pass
req.session.flash = flash
info = {
'identity_url': 'http://lmacken.id.fedoraproject.org',
'groups': [u'releng'],
}
req.registry.settings = self.app_settings
try:
resp = remember_me(None, req, info)
assert False, 'remember_me should have thrown an exception'
except Exception:
# A ComponentLookupError is thrown because we're doing this outside
# of the webapp
pass
# The user should not exist
self.assertIsNone(User.get(u'lmacken', self.db))
示例9: test_get_current_page
def test_get_current_page(self):
request = DummyRequest()
page = get_current_page(request)
self.assertEqual(page, 1)
request.GET['page'] = 5
page = get_current_page(request)
self.assertEqual(page, 5)
示例10: test_call
def test_call(self):
config = testing.setUp()
config.add_route('some_route', '/')
pagination_request_writer = PaginationRequestWriterMock()
param_property_naming = PropertyNamingMock(
'page-number',
'page-size',
'sort-property',
'sort-direction')
url_creator_factory = UrlCreatorFactoryMock('http://example.com')
request = DummyRequest()
request.registry.pagination = {
'some_route': {
'pagination_request_writer': pagination_request_writer,
'param_property_naming': param_property_naming,
'url_creator_factory': url_creator_factory,
}
}
request.pagination = Pagination(
Paging(
100,
PagingRequest(3, 12)),
Sorting('some_property', 'desc'))
request.matched_route = RouteMock('some_route')
event = BeforeRenderEventMock()
event['request'] = request
subscriber = PaginationBeforeRenderSubscriber()
subscriber(event)
self.assertEqual(pagination_request_writer.call_count, 1)
pagination = event.rendering_val['pagination']
self.assertEqual('http://example.com', str(pagination.url))
示例11: test_build_url_forward_headers
def test_build_url_forward_headers(self):
request = DummyRequest()
request.environ = {
"SERVER_NAME": "example.com"
}
request.registry.settings = {
"checker": {
"forward_headers": ["Cookie"]
}
}
request.headers["Cookie"] = "test"
self.assertEqual(
build_url(
"Test",
"https://camptocamp.com/toto?titi#tutu",
request
),
(
"https://camptocamp.com/toto?titi#tutu",
{
"Cache-Control": "no-cache",
"Cookie": "test",
}
)
)
示例12: test_call_exception
def test_call_exception(self):
class ExceptionPaginationReader(object):
# pylint: disable=too-few-public-methods
def __init__(self, exception):
self._exception = exception
def __call__(self, request, content_size_provider):
raise self._exception
content_size_provider_mock = ContentSizeProviderMock(100)
request = DummyRequest()
request.registry.pagination = {
'some_route': {
'content_size_provider': content_size_provider_mock,
'pagination_reader': ExceptionPaginationReader(
PageNotFoundException()),
}
}
request.matched_route = RouteMock('some_route')
event = ContextFoundEventMock(request)
subscriber = PaginationContextFoundSubscriber()
with self.assertRaises(ParameterValidationException):
subscriber(event)
示例13: _undo_delete_column
def _undo_delete_column(self, base, old_name, path, results):
for doc in results:
if doc.get(old_name, None):
id_doc=doc['_metadata']['id_doc']
url='/%s/doc/%d/%s' % (
base.metadata.name,
id_doc, "/".join(path)
)
params={
'value': doc[old_name],
'alter_files': False
}
request=DummyRequest(path=url, params=params)
request.method='PUT'
request.matchdict={
'base': base.metadata.name,
'id': str(id_doc),
'path': "/".join(path)
}
doc_view=DocumentCustomView(
DocumentContextFactory(request),
request
)
response=doc_view.put_path()
示例14: test_websocket_view_same_origin
def test_websocket_view_same_origin(config):
# example.com is the dummy request default host URL
config.registry.settings.update({'origins': []})
req = DummyRequest(headers={'Origin': 'http://example.com'})
req.get_response = lambda _: mock.sentinel.good_response
res = views.websocket_view(req)
assert res == mock.sentinel.good_response
示例15: test_leaders_weekly
def test_leaders_weekly(self):
session = self.db_master_session
for i in range(3):
user = User(nickname=unicode(i))
session.add(user)
session.flush()
score1 = Score(userid=user.id, value=i)
score1.name = 'new_cell'
session.add(score1)
score2 = Score(userid=user.id, value=i)
score2.name = 'new_wifi'
session.add(score2)
session.commit()
request = DummyRequest()
request.db_slave_session = self.db_master_session
inst = self._make_view(request)
result = inst.leaders_weekly_view()
for score_name in ('new_cell', 'new_wifi'):
self.assertEqual(
result['scores'][score_name]['leaders1'],
[{'nickname': u'2', 'num': 2, 'pos': 1},
{'nickname': u'1', 'num': 1, 'pos': 2}])
self.assertEqual(
result['scores'][score_name]['leaders2'],
[{'nickname': u'0', 'num': 0, 'pos': 3}])