How to use the pyramid.compat.text_type function in pyramid

To help you get started, we’ve selected a few pyramid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fizyk / pyramid_fullauth / tests / views / test_login_social.py View on Github external
def test_logged_social_connect_used_account(social_config, facebook_user, db_session):
    """Try to connect facebook account to logged in user used by other user."""
    # this user will be logged and trying to connect facebook's user account.
    fresh_user = User(
        email=text_type('new@user.pl'),
        password=text_type('somepassword'),
        address_ip=text_type('127.0.0.1')
    )
    db_session.add(fresh_user)
    transaction.commit()
    user = db_session.merge(facebook_user)
    fresh_user = db_session.merge(fresh_user)

    # mock request
    profile = {
        'accounts':
        [{'domain': text_type('facebook.com'), 'userid': user.provider_id('facebook')}],
        'displayName':
        text_type('teddy'),
        'preferredUsername':
        text_type('teddy'),
        'emails':
        [{'value': text_type('aasd@basd.pl')}],
github fizyk / pyramid_fullauth / tests / cases / test_unit / test_validators.py View on Github external
import pytest
from pyramid.compat import text_type
from pyramid_fullauth.models import User
from pyramid_fullauth.exceptions import EmptyError, EmailValidationError


class TestUserValidates(object):

    user_data = {'password': text_type('password1'),
                 'email': text_type('test@example.com'),
                 'address_ip': text_type('32.32.32.32')}

    def create_user(self, session, **user_data):
        '''method to create basic user'''
        user = User()

        for key in self.user_data:
            if not key in user_data:
                user_data[key] = self.user_data[key]

        for key in user_data:
            setattr(user, key, user_data[key])

        session.add(user)
        session.commit()

    @pytest.mark.parametrize('email', [
github fizyk / pyramid_fullauth / tests / cases / test_models.py View on Github external
def test_delete_admin(self):
        '''Admin user soft delete'''

        user = self.session.query(User).filter(User.email == text_type('test@example.com')).one()
        self.create_user(email=text_type('test2@example.com'), is_admin=True)

        user.is_admin = True
        self.session.commit()

        user.delete()

        self.assertNotEqual(user.deleted_at, None)
github fizyk / pyramid_fullauth / tests / views / test_login_social.py View on Github external
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('we@po.pl'),
        'preferredUsername': text_type('teddy'),
        'emails': [{'value': text_type('aasd@bwwqwe.pl')}],
        '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')
github fizyk / pyramid_fullauth / tests / views / test_login_social.py View on Github external
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('aasd@bwwqwe.pl')}],
        '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!
github fizyk / pyramid_fullauth / tests / unit / test_social_view.py View on Github external
            'verifiedEmail': text_type('verified@email.co.uk'),
            'preferredUsername': text_type('teddy'),
            'emails': [{'value': text_type('aasd@bwwqwe.pl')}],
            'name': text_type('ted')
        },
        'verified@email.co.uk'
    ), (
        {
            'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
            'displayName': text_type('teddy'),
            'preferredUsername': text_type('teddy'),
            'emails': [{'value': text_type('aasd@bwwqwe.pl')}],
            'name': text_type('ted')
        },
        'aasd@bwwqwe.pl'
    ), (
        {
github fizyk / pyramid_fullauth / tests / views / test_events.py View on Github external
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('we@po.pl'),
        'preferredUsername': text_type('teddy'),
        'emails': [{'value': text_type('aasd@bwwqwe.pl')}],
        '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
github fizyk / pyramid_fullauth / tests / views / test_register.py View on Github external
        text_type('email') * 100 + text_type('@wap.pl'), DEFAULT_USER['password'], DEFAULT_USER['password'],
        'Incorrect e-mail format'
    ),
    # too short password
    (DEFAULT_USER['email'], '12', '12', 'Password is too short'),
    # empty password
    (DEFAULT_USER['email'], '', '', 'Please enter your password'),
))
def test_register_error(db_session, default_app, email, password, confirm_password, error):
    """Error in registration process."""
    assert db_session.query(User).count() == 0

    res = default_app.get('/register')
    if email is not None:
        res.form['email'] = email
    res.form['password'] = password
    res.form['confirm_password'] = confirm_password
github fizyk / pyramid_fullauth / tests / unit / test_social_view.py View on Github external
            'emails': [{'value': text_type('aasd@bwwqwe.pl')}],
            'name': text_type('ted')
        },
        'aasd@bwwqwe.pl'
    ), (
        {
            'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
            'displayName': text_type('teddy'),
            'preferredUsername': text_type('teddy'),
            'emails': [{}],
            'name': text_type('ted')
        },
        '2343@facebook.com'
    ), (
        {
            'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
            'displayName': text_type('teddy'),
github fizyk / pyramid_fullauth / pyramid_fullauth / views / basic / register.py View on Github external
def _fillin_user(self, response, user):
        """
        Fill new user object in, with sent data.

        :param dict response: response to return from register view
        :param pyramid_fullauth.models.User user: new user object

        :returns: response
        :rtype: dict
        """
        email = self.request.POST.get('email', text_type(''))
        password = self.request.POST.get('password', text_type(''))
        # here if e-mail is already in database

        email_error = self._set_email(email, user)
        if email_error:
            response['errors']['email'] = email_error

        password_error = self._set_password(password, user)
        if password_error:
            response['errors']['password'] = password_error

        try:
            self.request.registry.notify(BeforeRegister(self.request, user, response['errors']))

            if not response['errors']:
                pyramid_basemodel.Session.add(user)
                pyramid_basemodel.Session.flush()