本文整理汇总了Python中pyramid.testing.DummyRequest.user方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.user方法的具体用法?Python DummyRequest.user怎么用?Python DummyRequest.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_image_url
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_get_image_url(self):
request = DummyRequest()
request.user = None
gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
self.assertEqual(gravatar.get_image_url(),
'http://localhost/default_gravatar.png')
request = DummyRequest()
request.user = {}
gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
self.assertEqual(gravatar.get_image_url(),
'http://localhost/default_gravatar.png')
request = DummyRequest()
request.user = {'email': ''}
gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
self.assertEqual(gravatar.get_image_url(),
'http://localhost/default_gravatar.png')
request = DummyRequest()
request.user = {'email': '[email protected]'}
gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
self.assertEqual(
gravatar.get_image_url(),
'https://www.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=32&d=http%3A%2F%2Flocalhost%2Fdefault_gravatar.png')
gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
self.assertEqual(
gravatar.get_image_url(100),
'https://www.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=100&d=http%3A%2F%2Flocalhost%2Fdefault_gravatar.png')
示例2: test_has_avatar
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_has_avatar(self):
request = DummyRequest()
request.user = None
gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
self.assertFalse(gravatar.has_avatar())
request = DummyRequest()
request.user = {'email': '[email protected]'}
gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
self.assertTrue(gravatar.has_avatar())
示例3: test_clean_session
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_clean_session(self):
request = DummyRequest()
request.session = {}
request.user = None
ga = GoogleAnalytics(request)
ga.clean_session()
self.assertEqual(request.session, {})
request = DummyRequest()
request.session = {USER_ATTR: True}
request.user = None
ga = GoogleAnalytics(request)
ga.clean_session()
self.assertEqual(request.session, {})
示例4: test__get_child_layers_info_without_scalehint
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
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)
示例5: test_forbidden_view_without_user_returns_redirect_to_login
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_forbidden_view_without_user_returns_redirect_to_login():
from paildocket.views.root import forbidden
request = DummyRequest()
request.user = False
request.context = DummyResource()
response = forbidden(request)
assert urlparse(response.location).path == '/login'
示例6: test_decimal_json
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_decimal_json(self):
from decimal import Decimal
from pyramid.testing import DummyRequest
from c2cgeoportal import DecimalJSON
renderer = DecimalJSON()(None)
request = DummyRequest()
request.user = None
system = {'request': request}
self.assertEquals(
renderer({'a': Decimal('3.3')}, system),
'{"a": 3.3}'
)
self.assertEquals(request.response.content_type, 'application/json')
request.params = {'callback': 'abc'}
self.assertEquals(
renderer({'a': Decimal('3.3')}, system),
'abc({"a": 3.3});'
)
self.assertEquals(request.response.content_type, 'text/javascript')
renderer = DecimalJSON(jsonp_param_name='cb')(None)
request.params = {'cb': 'def'}
self.assertEquals(
renderer({'a': Decimal('3.3')}, system),
'def({"a": 3.3});'
)
self.assertEquals(request.response.content_type, 'text/javascript')
示例7: test_get_user_attr
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_get_user_attr(self):
request = DummyRequest()
request.session = {}
request.user = None
ga = GoogleAnalytics(request)
self.assertEqual(ga.get_user_attr(True), {USER_ATTR: True})
self.assertEqual(ga.get_user_attr(False), {USER_ATTR: False})
示例8: test_shortener
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_shortener(self):
from pyramid.testing import DummyRequest
from pyramid.httpexceptions import HTTPNotFound, HTTPBadRequest
from c2cgeoportal.views.shortener import Shortener
def route_url(name, *elements, **kw):
return "https://example.com/short/" + kw["ref"]
request = DummyRequest()
request.user = None
request.host = "example.com:443"
request.server_name = "example.com"
request.route_url = route_url
request.registry.settings["shortener"] = {
"base_url": "https://example.com/s/"
}
shortener = Shortener(request)
request.params = {}
request.matchdict = {
"ref": "AAAAAA"
}
self.assertRaises(HTTPNotFound, shortener.get)
request.params = {}
request.matchdict = {}
self.assertRaises(HTTPBadRequest, shortener.create)
request.params = {
"url": "https://other-site.com/hi"
}
self.assertRaises(HTTPBadRequest, shortener.create)
示例9: test__get_child_layers_info_with_scalehint
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test__get_child_layers_info_with_scalehint(self):
import math
from pyramid.testing import DummyRequest
from c2cgeoportal.views.entry import Entry
request = DummyRequest()
request.user = None
entry = Entry(request)
class Layer:
pass
child_layer_1 = Layer()
child_layer_1.name = "layer_1"
child_layer_1.scaleHint = {"min": 1 * math.sqrt(2), "max": 2 * math.sqrt(2)}
child_layer_1.layers = []
child_layer_2 = Layer()
child_layer_2.name = "layer_2"
child_layer_2.scaleHint = {"min": 3 * math.sqrt(2), "max": 4 * math.sqrt(2)}
child_layer_2.layers = []
layer = Layer()
layer.layers = [child_layer_1, child_layer_2]
child_layers_info = entry._get_child_layers_info_1(layer)
expected = [
{"name": "layer_1", "minResolutionHint": 1.0, "maxResolutionHint": 2.0},
{"name": "layer_2", "minResolutionHint": 3.0, "maxResolutionHint": 4.0},
]
self.assertEqual(child_layers_info, expected)
示例10: test_shortener_create_1
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_shortener_create_1(self):
from pyramid.testing import DummyRequest
from pyramid.httpexceptions import HTTPFound
from c2cgeoportal.views.shortener import Shortener
def route_url(name, *elements, **kw):
return "https://example.com/short/" + kw["ref"]
request = DummyRequest()
request.user = None
request.host = "example.com:443"
request.server_name = "example.com"
request.route_url = route_url
request.registry.settings["shortener"] = {
"base_url": "https://example.com/s/"
}
shortener = Shortener(request)
request.params = {
"url": "https://example.com/hi"
}
result = shortener.create()
index = result["short_url"].rfind("/")
self.assertEqual(
result["short_url"][:index],
"https://example.com/s"
)
request.params = {}
request.matchdict = {
"ref": result["short_url"][index + 1:]
}
result = shortener.get()
self.assertEqual(type(result), HTTPFound)
self.assertEqual(result.location, "https://example.com/hi")
示例11: test_login
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_login(self):
from pyramid.testing import DummyRequest
from c2cgeoportal.views.entry import Entry
request = DummyRequest()
request.user = None
entry = Entry(request)
request.path = "/for_test"
expected = {
"lang": "fr",
"came_from": "/for_test",
}
self.assertEqual(entry.loginform403(), expected)
request.params = {
"came_from": "/for_a_second_test",
}
entry = Entry(request)
expected = {
"lang": "fr",
"came_from": "/for_a_second_test",
}
self.assertEqual(entry.loginform(), expected)
entry = Entry(request)
request.params = {}
expected = {
"lang": "fr",
"came_from": "/",
}
self.assertEqual(entry.loginform(), expected)
示例12: test_no_user
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_no_user(self):
request = DummyRequest()
request.user = None
from ..security import MyAuthenticationPolicy
policy = MyAuthenticationPolicy(None)
self.assertEqual(policy.authenticated_userid(request), None)
示例13: test_shortener_baseurl
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_shortener_baseurl(self):
from pyramid.testing import DummyRequest
from c2cgeoportal.views.shortener import Shortener
def route_url(name, *elements, **kw):
return "https://example.com/short/" + kw["ref"]
request = DummyRequest()
request.user = None
request.host = "example.com:443"
request.server_name = "example.com"
request.route_url = route_url
request.registry.settings["shortener"] = {
"base_url": "http://my_host/my_short/"
}
shortener = Shortener(request)
request.params = {
"url": "https://example.com/hi"
}
result = shortener.create()
index = result["short_url"].rfind("/")
self.assertEqual(
result["short_url"][:index],
"http://my_host/my_short"
)
示例14: test_get_image_url_with_size
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_get_image_url_with_size(self):
request = DummyRequest()
request.user = User(email='[email protected]')
gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
self.assertURLEqual(
gravatar.get_image_url(100),
'https://www.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=100&d=http%3A%2F%2Flocalhost%2Fdefault_gravatar.png')
示例15: test_authenticated_user
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import user [as 别名]
def test_authenticated_user(self):
from ..models import User
request = DummyRequest()
request.user = User()
request.user.id = 'foo'
from ..security import MyAuthenticationPolicy
policy = MyAuthenticationPolicy(None)
self.assertEqual(policy.authenticated_userid(request), 'foo')