def test_incomplete_user_no_email_not_added_to_database(db_session):
    """Test that a User cannot be added without required fields."""
    user = User(first_name=FAKE.first_name(),
                last_name=FAKE.last_name(),
                password='******')
    db_session.add(user)
    with pytest.raises(IntegrityError):
        db_session.flush()
Esempio n. 2
0
def test_signup_post_incomplete_data_gets_400_status_code(testapp):
    """Test that POST to signup route gets 400 status code for bad data."""
    data = {
        'first_name': FAKE.first_name(),
        'last_name': FAKE.last_name(),
        'password': FAKE.password()
    }
    res = testapp.post('/signup', data, status=400)
    assert res.status_code == 400
Esempio n. 3
0
def test_signup_post_complete_data_gets_201_status_code(testapp):
    """Test that POST to signup route gets 201 status code."""
    data = {
        'first_name': FAKE.first_name(),
        'last_name': FAKE.last_name(),
        'email': FAKE.email(),
        'password': FAKE.password()
    }
    res = testapp.post('/signup', data)
    assert res.status_code == 201
Esempio n. 4
0
def test_signup_raises_error_for_incomplete_post_data(dummy_request):
    """Test that signup raises HTTPBadRequest for missing email."""
    data = {
        'first_name': FAKE.first_name(),
        'last_name': FAKE.last_name(),
        'password': FAKE.password()
    }
    dummy_request.POST = data
    with pytest.raises(HTTPBadRequest):
        signup_view(dummy_request)
def test_user_duplicate_email_not_added_to_database(db_session, one_user):
    """Test that a User can be added to the database."""
    db_session.add(one_user)
    db_session.flush()
    dup_user = User(first_name=FAKE.first_name(),
                    last_name=FAKE.last_name(),
                    email=one_user.email,
                    password='******')
    db_session.add(dup_user)
    with pytest.raises(IntegrityError):
        db_session.flush()
Esempio n. 6
0
def test_signup_adds_new_user_to_the_database(dummy_request, db_session):
    """Test that signup adds a new User to the database."""
    data = {
        'first_name': FAKE.first_name(),
        'last_name': FAKE.last_name(),
        'email': FAKE.email(),
        'password': FAKE.password()
    }
    dummy_request.POST = data
    signup_view(dummy_request)
    assert len(db_session.query(User).all()) == 1
Esempio n. 7
0
def test_signup_post_complete_data_returns_json_with_new_user_info(testapp):
    """Test that POST to signup route gets JSON with details for new User."""
    data = {
        'first_name': FAKE.first_name(),
        'last_name': FAKE.last_name(),
        'email': FAKE.email(),
        'password': FAKE.password()
    }
    res = testapp.post('/signup', data)
    for prop in ['first_name', 'last_name', 'email']:
        assert res.json[prop] == data[prop]
    assert res.json['id'] is not None
Esempio n. 8
0
def test_signup_post_complete_data_adds_user_to_database(
        testapp, testapp_session):
    """Test that POST to signup route creates a new User."""
    assert len(testapp_session.query(User).all()) == 0
    data = {
        'first_name': FAKE.first_name(),
        'last_name': FAKE.last_name(),
        'email': FAKE.email(),
        'password': FAKE.password()
    }
    testapp.post('/signup', data)
    assert len(testapp_session.query(User).all()) == 1
Esempio n. 9
0
def test_signup_returns_dict_with_new_user_data(dummy_request):
    """Test that signup returns dict with the new User's data."""
    data = {
        'first_name': FAKE.first_name(),
        'last_name': FAKE.last_name(),
        'email': FAKE.email(),
        'password': FAKE.password()
    }
    dummy_request.POST = data
    res = signup_view(dummy_request)
    assert isinstance(res, dict)
    assert all(prop in res
               for prop in ['id', 'first_name', 'last_name', 'email'])
Esempio n. 10
0
def test_signup_raises_error_for_duplicate_email(dummy_request, db_session,
                                                 one_user):
    """Test that signup raises HTTPBadRequest for duplicate email."""
    db_session.add(one_user)
    data = {
        'first_name': FAKE.first_name(),
        'last_name': FAKE.last_name(),
        'email': one_user.email,
        'password': FAKE.password()
    }
    dummy_request.POST = data
    with pytest.raises(HTTPBadRequest):
        signup_view(dummy_request)
Esempio n. 11
0
def test_signup_creates_new_user_using_post_data(dummy_request, db_session):
    """Test that signup uses POST data to create the new User."""
    data = {
        'first_name': FAKE.first_name(),
        'last_name': FAKE.last_name(),
        'email': FAKE.email(),
        'password': FAKE.password()
    }
    dummy_request.POST = data
    res = signup_view(dummy_request)
    new_user = db_session.query(User).get(res['id'])
    for prop in ['first_name', 'last_name', 'email']:
        assert getattr(new_user, prop) == data[prop]
    assert new_user.verify(data['password'])