本文整理汇总了Python中pyramid.compat.text_type函数的典型用法代码示例。如果您正苦于以下问题:Python text_type函数的具体用法?Python text_type怎么用?Python text_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了text_type函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_social_login_register
def test_social_login_register(social_config, db_session):
"""Register fresh user and logs him in."""
profile = {
'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
'displayName': text_type('teddy'),
'verifiedEmail': text_type('[email protected]'),
'preferredUsername': text_type('teddy'),
'emails': [{'value': text_type('[email protected]')}],
'name': text_type('ted')
}
credentials = {'oauthAccessToken': '7897048593434'}
provider_name = text_type('facebook')
provider_type = text_type('facebook')
request = testing.DummyRequest()
request.user = None
request.registry = social_config.registry
request.remote_addr = text_type('127.0.0.123')
request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
request.login_perform = MagicMock(name='login_perform')
request.login_perform.return_value = {'status': True}
view = SocialLoginViews(request)
out = view()
assert out == {'status': True}
transaction.commit()
# read first new account
user = db_session.query(User).one()
assert user.is_active
assert user.provider_id('facebook') == profile['accounts'][0]['userid']
开发者ID:fizyk,项目名称:pyramid_fullauth,代码行数:30,代码来源:test_login_social.py
示例2: test_login_different_social_account
def test_login_different_social_account(social_config, db_session, facebook_user): # pylint:disable=unused-argument
"""
Login with different social account than connected from same provider.
System should let user in, but not change connection.
"""
# profile mock response
profile = {
# facebook user id is different than user's
'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
'displayName': text_type('teddy'),
'verifiedEmail': facebook_user.email,
'preferredUsername': text_type('teddy'),
'emails': [{'value': text_type('[email protected]')}],
'name': text_type('ted')
}
request = testing.DummyRequest()
request.user = None
request.registry = social_config.registry
request.remote_addr = text_type('127.0.0.123')
request.context = AuthenticationComplete(
profile,
{'oauthAccessToken': '7897048593434'},
text_type('facebook'),
text_type('facebook'))
request.login_perform = MagicMock(name='login_perform')
request.login_perform.return_value = {'status': True}
view = SocialLoginViews(request)
out = view()
# user should be authenticated recognized by email!
assert out['status'] is True
assert facebook_user.provider_id(text_type('facebook')) is not profile['accounts'][0]['userid']
开发者ID:fizyk,项目名称:pyramid_fullauth,代码行数:33,代码来源:test_login_social.py
示例3: test_change_email
def test_change_email(db_with_user):
'''User::change_email'''
user = db_with_user.query(User).filter(User.email == text_type('[email protected]')).one()
user.set_new_email(text_type('[email protected]'))
user.change_email()
assert not user.email_change_key
开发者ID:develucas,项目名称:pyramid_fullauth,代码行数:7,代码来源:test_user_email.py
示例4: test_password_empty
def test_password_empty(db_with_user):
"""User::empty password change"""
user = db_with_user.query(User).filter(User.username == text_type("u1")).one()
with pytest.raises(EmptyError):
user.password = text_type("")
开发者ID:veronicazgirvaci,项目名称:pyramid_fullauth,代码行数:7,代码来源:test_user_password.py
示例5: test_aftersociallogin
def test_aftersociallogin(aftersociallogin_config, db_session): # pylint:disable=redefined-outer-name
"""Register fresh user and logs him in and check response if redirect from AfterSocialLogIn."""
profile = {
'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
'displayName': text_type('teddy'),
'verifiedEmail': text_type('[email protected]'),
'preferredUsername': text_type('teddy'),
'emails': [{'value': text_type('[email protected]')}],
'name': text_type('ted')
}
credentials = {'oauthAccessToken': '7897048593434'}
provider_name = text_type('facebook')
provider_type = text_type('facebook')
request = testing.DummyRequest()
request.user = None
request.registry = aftersociallogin_config.registry
request.remote_addr = text_type('127.0.0.123')
request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
def login_perform(*_, **kwargs):
return HTTPFound(location=kwargs['location'])
request.login_perform = login_perform
view = SocialLoginViews(request)
out = view()
assert out.location == EVENT_PATH.format(AfterSocialLogIn)
transaction.commit()
# read first new account
user = db_session.query(User).one()
assert user.is_active
assert user.provider_id('facebook') == profile['accounts'][0]['userid']
开发者ID:fizyk,项目名称:pyramid_fullauth,代码行数:31,代码来源:test_events.py
示例6: test_logged_social_connect_account
def test_logged_social_connect_account(social_config, active_user, db_session):
"""Connect facebook account to logged in user."""
user = db_session.merge(active_user)
profile = {
'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
'displayName': text_type('teddy'),
'preferredUsername': text_type('teddy'),
'emails': [{'value': text_type('[email protected]')}],
'name': text_type('ted')
}
credentials = {'oauthAccessToken': '7897048593434'}
provider_name = text_type('facebook')
provider_type = text_type('facebook')
request = testing.DummyRequest()
request.user = user
request.registry = social_config.registry
request.remote_addr = text_type('127.0.0.123')
request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
request._ = mock_translate
request.login_perform = MagicMock(name='login_perform')
request.login_perform.return_value = {'status': True}
view = SocialLoginViews(request)
out = view()
assert out['status'] is True
transaction.commit()
user = db_session.merge(user)
assert user.provider_id(text_type('facebook')) == profile['accounts'][0]['userid']
开发者ID:fizyk,项目名称:pyramid_fullauth,代码行数:30,代码来源:test_login_social.py
示例7: test_social_login_register
def test_social_login_register(social_config, db_session):
"""Register fresh user and logs him in."""
profile = {
"accounts": [{"domain": text_type("facebook.com"), "userid": text_type("2343")}],
"displayName": text_type("teddy"),
"verifiedEmail": text_type("[email protected]"),
"preferredUsername": text_type("teddy"),
"emails": [{"value": text_type("[email protected]")}],
"name": text_type("ted"),
}
credentials = {"oauthAccessToken": "7897048593434"}
provider_name = text_type("facebook")
provider_type = text_type("facebook")
request = testing.DummyRequest()
request.user = None
request.registry = social_config.registry
request.remote_addr = text_type("127.0.0.123")
request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
request.login_perform = MagicMock(name="login_perform")
request.login_perform.return_value = {"status": True}
view = SocialLoginViews(request)
out = view()
assert out == {"status": True}
transaction.commit()
# read first new account
user = db_session.query(User).one()
assert user.is_active
assert user.provider_id("facebook") == profile["accounts"][0]["userid"]
开发者ID:quantifiedcodebot,项目名称:pyramid_fullauth,代码行数:30,代码来源:test_login_social.py
示例8: db_locales
def db_locales(db_session): # pylint:disable=redefined-outer-name
"""Add Languages to db_session."""
for locale in ['pl', 'cz', 'fr']:
locale_object = Language(name=text_type(locale),
native_name=text_type(locale),
language_code=text_type(locale))
db_session.add(locale_object)
transaction.commit()
开发者ID:fizyk,项目名称:pyramid_localize,代码行数:8,代码来源:conftest.py
示例9: test_login_different_social_account
def test_login_different_social_account(social_config, db_session, facebook_user):
"""
Login with different social account than connected from same provider.
System should let user in, but not change connection.
"""
# profile mock response
profile = {
# facebook user id is different than user's
"accounts": [{"domain": text_type("facebook.com"), "userid": text_type("2343")}],
"displayName": text_type("teddy"),
"verifiedEmail": facebook_user.email,
"preferredUsername": text_type("teddy"),
"emails": [{"value": text_type("[email protected]")}],
"name": text_type("ted"),
}
request = testing.DummyRequest()
request.user = None
request.registry = social_config.registry
request.remote_addr = text_type("127.0.0.123")
request.context = AuthenticationComplete(
profile, {"oauthAccessToken": "7897048593434"}, text_type("facebook"), text_type("facebook")
)
request.login_perform = MagicMock(name="login_perform")
request.login_perform.return_value = {"status": True}
view = SocialLoginViews(request)
out = view()
# user should be authenticated recognized by email!
assert out["status"] is True
assert facebook_user.provider_id("facebook") is not profile["accounts"][0]["userid"]
开发者ID:quantifiedcodebot,项目名称:pyramid_fullauth,代码行数:31,代码来源:test_login_social.py
示例10: test_logged_social_connect_second_account
def test_logged_social_connect_second_account(social_config, facebook_user, db_session):
"""Connect second facebook account to logged in user."""
user = db_session.merge(facebook_user)
# mock request
profile = {
"accounts": [{"domain": text_type("facebook.com"), "userid": text_type("2343")}],
"displayName": text_type("teddy"),
"preferredUsername": text_type("teddy"),
"emails": [{"value": text_type("[email protected]")}],
"name": text_type("ted"),
}
credentials = {"oauthAccessToken": "7897048593434"}
provider_name = text_type("facebook")
provider_type = text_type("facebook")
request = testing.DummyRequest()
request.user = user
request.registry = social_config.registry
request.remote_addr = text_type("127.0.0.123")
request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
request._ = mock_translate
request.login_perform = MagicMock(name="login_perform")
request.login_perform.return_value = {"status": True}
view = SocialLoginViews(request)
out = view()
# status should be false
assert out["status"] is False
assert out["msg"] == "Your account is already connected to other ${provider} account."
assert user.provider_id("facebook") is not profile["accounts"][0]["userid"]
开发者ID:quantifiedcodebot,项目名称:pyramid_fullauth,代码行数:30,代码来源:test_login_social.py
示例11: test_logged_social_connect_account
def test_logged_social_connect_account(social_config, active_user, db_session):
"""Connect facebook account to logged in user."""
user = db_session.merge(active_user)
profile = {
"accounts": [{"domain": text_type("facebook.com"), "userid": text_type("2343")}],
"displayName": text_type("teddy"),
"preferredUsername": text_type("teddy"),
"emails": [{"value": text_type("[email protected]")}],
"name": text_type("ted"),
}
credentials = {"oauthAccessToken": "7897048593434"}
provider_name = text_type("facebook")
provider_type = text_type("facebook")
request = testing.DummyRequest()
request.user = user
request.registry = social_config.registry
request.remote_addr = text_type("127.0.0.123")
request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
request._ = mock_translate
request.login_perform = MagicMock(name="login_perform")
request.login_perform.return_value = {"status": True}
view = SocialLoginViews(request)
out = view()
assert out["status"] is True
transaction.commit()
user = db_session.merge(user)
assert user.provider_id("facebook") == profile["accounts"][0]["userid"]
开发者ID:quantifiedcodebot,项目名称:pyramid_fullauth,代码行数:30,代码来源:test_login_social.py
示例12: test_email_from_context
def test_email_from_context(profile, email):
"""Test email_from_context email getting method."""
from velruse import AuthenticationComplete
context = AuthenticationComplete(
profile,
{'oauthAccessToken': '7897048593434'},
text_type('facebook'),
text_type('facebook')
)
view = SocialLoginViews(mock.MagicMock())
assert view._email_from_context(context) == email
开发者ID:franbull,项目名称:pyramid_fullauth,代码行数:11,代码来源:test_social_view.py
示例13: setUp
def setUp(self):
'''
setUp test method @see unittest.TestCase.setUp
'''
Base.metadata.create_all(engine)
for locale in ['pl', 'cz', 'fr']:
locale_object = Language(name=text_type(locale),
native_name=text_type(locale),
language_code=text_type(locale))
Session.add(locale_object)
开发者ID:develucas,项目名称:pyramid_localize,代码行数:11,代码来源:test_request.py
示例14: password_validator
def password_validator(self, _, password):
"""
Validate password.
Password validator keeps new password hashed.
Rises Value error on empty password
:param str key: field key
:param str password: new password
:returns: hashed and salted password
:rtype: str
:raises: pyramid_fullauth.exceptions.EmptyError
.. note::
If you're using this Mixin on your own User object,
don't forget to add a listener as well, like that:
.. code-block:: python
from sqlalchemy.event import listen
listen(User.password, 'set', User.password_listener, retval=True)
.. note::
For more information on Attribute Events in sqlalchemy see:
:meth:`sqlalchemy.orm.events.AttributeEvents.set`
"""
if not password:
raise EmptyError('password-empty')
# reading default hash_algorithm
# pylint:disable=protected-access
hash_algorithm = self.__class__._hash_algorithm.property.columns[0].default.arg
# pylint:enable=protected-access
# getting currently used hash method
hash_method = getattr(hashlib, hash_algorithm)
# generating salt
salt = hash_method()
salt.update(os.urandom(60))
salt_value = salt.hexdigest()
# storing used hash algorithm
self._hash_algorithm = hash_algorithm
self._salt = text_type(salt_value)
return text_type(self.__class__.hash_password(password, salt_value, hash_method))
开发者ID:fizyk,项目名称:pyramid_fullauth,代码行数:52,代码来源:password.py
示例15: test_email_valid_formats
def test_email_valid_formats(self, db, email):
''' Check all valid formats of Email (RFC 5321) can be set by user
'''
self.create_user(db, username=text_type('u1'))
user = db.query(User).filter(User.username == text_type('u1')).one()
user.email = email
db.commit()
user = db.query(User).filter(
User.username == text_type('u1')).one()
assert user.email == email
开发者ID:develucas,项目名称:pyramid_fullauth,代码行数:13,代码来源:test_validators.py
示例16: test_email_invalid_formats
def test_email_invalid_formats(self, db, email):
'''
Check all invalid formats of Email (RFC 5321) can not be set by user
'''
self.create_user(db, username=text_type('u1'))
user = db.query(User).filter(User.username == text_type('u1')).one()
assert user.email == text_type('[email protected]')
with pytest.raises(EmailValidationError):
user.email = email
db.commit()
开发者ID:develucas,项目名称:pyramid_fullauth,代码行数:13,代码来源:test_validators.py
示例17: test_login_social_connect
def test_login_social_connect(social_config, active_user, db_session):
"""Connect and logs user in."""
user = db_session.merge(active_user)
profile = {
'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
'displayName': text_type('teddy'),
'preferredUsername': text_type('teddy'),
'emails': [{'value': user.email}],
'name': text_type('ted')
}
credentials = {'oauthAccessToken': '7897048593434'}
provider_name = text_type('facebook')
provider_type = text_type('facebook')
user = None
request = testing.DummyRequest()
request.user = user
request.registry = social_config.registry
request.remote_addr = text_type('127.0.0.123')
request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
request.login_perform = MagicMock(name='login_perform')
request.login_perform.return_value = {'status': True}
view = SocialLoginViews(request)
out = view()
assert out == {'status': True}
开发者ID:fizyk,项目名称:pyramid_fullauth,代码行数:26,代码来源:test_login_social.py
示例18: test_password_change
def test_password_change(db_session, user, password):
"""User password change."""
new_password = text_type(password)
user = db_session.merge(user)
old_password = user.password
old_salt = user._salt
user.password = new_password
transaction.commit()
user = db_session.query(User).filter(User.username == text_type('u1')).one()
assert not user.password == old_password
assert not user._salt == old_salt
assert user.check_password(new_password)
开发者ID:fizyk,项目名称:pyramid_fullauth,代码行数:14,代码来源:test_user_password.py
示例19: test_login_social_connect
def test_login_social_connect(social_config, active_user, db_session):
"""Connect and logs user in."""
user = db_session.merge(active_user)
profile = {
"accounts": [{"domain": text_type("facebook.com"), "userid": text_type("2343")}],
"displayName": text_type("teddy"),
"preferredUsername": text_type("teddy"),
"emails": [{"value": user.email}],
"name": text_type("ted"),
}
credentials = {"oauthAccessToken": "7897048593434"}
provider_name = text_type("facebook")
provider_type = text_type("facebook")
user = None
request = testing.DummyRequest()
request.user = user
request.registry = social_config.registry
request.remote_addr = text_type("127.0.0.123")
request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
request.login_perform = MagicMock(name="login_perform")
request.login_perform.return_value = {"status": True}
view = SocialLoginViews(request)
out = view()
assert out == {"status": True}
开发者ID:quantifiedcodebot,项目名称:pyramid_fullauth,代码行数:26,代码来源:test_login_social.py
示例20: password_validator
def password_validator(self, key, password):
'''
Password validator keeps new password hashed.
Rises Value error on empty password
:param User user: object instance that triggered event
:param str password: new password
:param str oldvalue: old password value
:param initiatior: the attribute implementation object which initiated this event.
:returns: hashed and salted password
:rtype: str
:raises: pyramid_fullauth.exceptions.EmptyError
.. note::
If you using this Mixin on your own User object, don't forget to add a listener as well, like that:
.. code-block:: python
from sqlalchemy.event import listen
listen(User.password, 'set', User.password_listener, retval=True)
.. note::
For more information on Attribute Events in sqlalchemy see:
:meth:`sqlalchemy.orm.events.AttributeEvents.set`
'''
if not password:
raise EmptyError('password-empty')
# reading default hash_algorithm
hash_algorithm = self.__class__._hash_algorithm.property.columns[0].default.arg
# getting currently used hash method
hash_method = getattr(hashlib, hash_algorithm)
# generating salt
salt = hash_method()
salt.update(os.urandom(60))
salt_value = salt.hexdigest()
# storing used hash algorithm
self._hash_algorithm = hash_algorithm
self._salt = text_type(salt_value)
return text_type(self.__class__.hash_password(password, salt_value, hash_method))
开发者ID:veronicazgirvaci,项目名称:pyramid_fullauth,代码行数:49,代码来源:password.py
注:本文中的pyramid.compat.text_type函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论