Example #1
0
def test_follow(users):
    u1 = User.find_by_email('*****@*****.**')
    u2 = User.find_by_email('*****@*****.**')
    assert u1.followed.all() == []
    assert u1.followers.all() == []

    u1.follow(u2)
    db.session.commit()
    assert u1.is_following(u2) is True
    assert u1.followed.count() == 1
    assert u1.followed.first().profile.username == 'commonuser'
    assert u2.followers.count() == 1
    assert u2.followers.first().profile.username == 'regularuser'

    u1.unfollow(u2)
    db.session.commit()
    assert u1.is_following(u2) is False
    assert u1.followed.count() == 0
    assert u2.followers.count() == 0
Example #2
0
def login_user():
    data = request.get_json()

    if data is None:
        return bad_request("No input data provided")

    try:
        # check for existing user
        user = User.find_by_email(data.get('email'))

        if user and user.check_password(data.get('password')):
            return jsonify({'token': user.encode_auth_token()})
        else:
            return error_response(401, 'Incorrect email or password.')
    except Exception:
        return server_error('Something went wrong, please try again.')
Example #3
0
def check_email():
    data = request.get_json()
    user = User.find_by_email(data.get('email'))
    return {'res': not isinstance(user, User)}
Example #4
0
def test_password_hashing(db):
    user = User.find_by_email('*****@*****.**')
    assert user.check_password('secret') is False
    assert user.check_password('password') is True
Example #5
0
def test_avatar(users):
    user = User.find_by_email('*****@*****.**')
    profile = Profile.query.filter_by(user_id=user.id).first()
    assert profile.avatar == ('https://www.gravatar.com/avatar/'
                        'e6b6b9ec69c4837878505768b621d383?s=128&d=mm&r=pg')