コード例 #1
0
def test_template_filter(app):
    with app.app_context():
        user = User(email='*****@*****.**', password='******')
        db.session.add(user)
        db.session.commit()
        user.profile = UserProfile(username='******', full_name='name')
        db.session.commit()

        assert userprofile(user.profile.user_id) == user.profile
コード例 #2
0
def test_template_filter(app):
    """Test template filter."""
    with app.app_context():
        user = User(email='*****@*****.**', password='******')
        db.session.add(user)
        db.session.commit()
        user.profile = UserProfile(username='******', full_name='name')
        db.session.commit()

        assert userprofile(user.profile.user_id) == user.profile
コード例 #3
0
def test_profile_updating(base_app):
    base_app.config.update(USERPROFILES_EXTEND_SECURITY_FORMS=True)
    InvenioUserProfiles(base_app)
    app = base_app

    with app.app_context():
        user = User(email='lollorosso', password='******')
        db.session.add(user)
        db.session.commit()

        assert user.profile is None

        profile = UserProfile(username='******', full_name='Test T. User')
        user.profile = profile
        user.profile.username = '******'
        assert user.profile.username == 'Different_Name'
        assert profile.username == 'Different_Name'
コード例 #4
0
    def sync_user_and_profile(cls, data):
        """Create or update the rero user with the patron data.

        :param data - dict representing the patron data
        """
        created = False
        # start a session to be able to rollback if the data are not valid
        user = cls._get_user_by_data(data)
        with db.session.begin_nested():
            # need to create the user
            if not user:
                birth_date = data.get('birth_date')
                # sanity check
                if not birth_date:
                    raise RecordValidationError('birth_date field is required')
                # the default password is the birth date
                user = User(email=data.get('email'),
                            password=hash_password(birth_date),
                            profile=dict(),
                            active=True)
                db.session.add(user)
                created = True
            else:
                if user.email != data.get('email'):
                    user.email = data.get('email')
            # update all common fields
            if user.profile is None:
                user.profile = UserProfile(user_id=user.id)
            profile = user.profile
            for field in cls.profile_fields:
                # date field need conversion
                if field == 'birth_date':
                    setattr(profile, field,
                            datetime.strptime(data.get(field), '%Y-%m-%d'))
                elif field == 'keep_history':
                    setattr(profile, field,
                            data.get('patron', {}).get(field, True))
                else:
                    setattr(profile, field, data.get(field, ''))
            db.session.merge(user)
            data['user_id'] = user.id
            if created:
                # the fresh created user
                return user
コード例 #5
0
def test_profile_updating(base_app):
    base_app.config.update(USERPROFILES_EXTEND_SECURITY_FORMS=True)
    InvenioUserProfiles(base_app)
    app = base_app

    with app.app_context():
        user = User(email='lollorosso', password='******')
        db.session.add(user)
        db.session.commit()

        assert user.profile is None

        profile = UserProfile(
            username='******',
            full_name='Test T. User'
        )
        user.profile = profile
        user.profile.username = '******'
        assert user.profile.username == 'Different_Name'
        assert profile.username == 'Different_Name'