예제 #1
0
 def get_all_data(self, principal_ids: list) -> list:
     """Get all user data from a list of principals."""
     users = UserProfile.query().filter(
         UserProfile.id == sa.any_(principal_ids)).all()
     result = []
     for user in users:
         data = map_from_object(user_schema, user, default='')
         result.append(data)
     return result
예제 #2
0
def email_in_use(request):
    """Validate if email is used by another user.

    :param request: pyramid request.
    """
    email = request.json.get('email')
    user_id = request.json.get('id')
    db_user = UserProfile.query().filter_by(email=email).one_or_none()
    if db_user and not str(db_user.id) == user_id:
        return False
    else:
        return True
예제 #3
0
def test_inactivate_user(profile_id, expected):
    """Test inactivate_user function."""
    from briefy.leica.models import UserProfile

    profile = UserProfile(
        id=profile_id,
        first_name='Foo',
        last_name='Bar',
        email='*****@*****.**',
    )

    func = user.inactivate_user
    assert func(profile) == expected
예제 #4
0
def test_activate_or_create_user(profile_id):
    """Test activate_or_create_user function."""
    from briefy.leica.models import UserProfile

    profile = UserProfile(
        id=profile_id,
        first_name='Foo',
        last_name='Bar',
        email='*****@*****.**',
    )
    groups = ['g:briefy', ]

    func = user.activate_or_create_user
    assert func(profile, groups)
예제 #5
0
    def get_data(self, user_id: AnyUUID) -> dict:
        """Get a map with user data."""
        try:
            user_id = EasyUUID(user_id)
        except ValueError:
            logger.warn(f'Invalid ACTOR UUID f{user_id}')
            data = user_schema.copy()
            data['id'] = str(user_id)
            data['fullname'] = ''
            return data

        if user_id == SystemUser.id:
            user = SystemUser
        else:
            user = UserProfile.get(user_id)

        return map_from_object(user_schema, user, default='') if user else {}
예제 #6
0
def test_create_user_success(profile_id):
    """Test create_user function with success."""
    from briefy.leica.models import UserProfile

    profile = UserProfile(
        id=profile_id,
        first_name='Foo',
        last_name='Bar',
        email='*****@*****.**',
    )
    initial_password = '******'
    groups = [
        'g:briefy',
    ]

    func = rolleiflex.create_user
    assert func(profile, initial_password, groups)
예제 #7
0
def test_create_user_failure(profile_id):
    """Test create_user function with a failure."""
    from briefy.leica.models import UserProfile
    from pyramid.httpexceptions import HTTPBadRequest

    profile = UserProfile(
        id=profile_id,
        first_name='Foo',
        last_name='Bar',
        email='*****@*****.**',
    )
    initial_password = '******'
    groups = [
        'g:briefy',
    ]

    func = rolleiflex.create_user
    with pytest.raises(HTTPBadRequest):
        func(profile, initial_password, groups)