Example #1
0
def test_signup_creates_new_user_with_none_names(dummy_request, db_session):
    """Test that signup sets first and last name to None when not given."""
    data = {'email': FAKE.email(), 'password': FAKE.password()}
    dummy_request.POST = data
    res = signup_view(dummy_request)
    assert res['first_name'] is None
    assert res['last_name'] is None
Example #2
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
def test_incomplete_user_no_password_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(),
        email=FAKE.email(),
    )
    db_session.add(user)
    with pytest.raises(IntegrityError):
        db_session.flush()
Example #4
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
Example #5
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
Example #6
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
Example #7
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'])
Example #8
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'])
Example #9
0
def test_signup_post_data_without_names_sets_names_to_none(testapp):
    """Test that POST to signup route sets first and last names to None."""
    data = {'email': FAKE.email(), 'password': FAKE.password()}
    res = testapp.post('/signup', data)
    assert res.json['first_name'] is None
    assert res.json['last_name'] is None
def test_validate_user_raises_error_for_email_not_in_database(dummy_request):
    """Test that validate_user raises HTTPForbidden for bad email."""
    data = {'email': FAKE.email(), 'password': '******'}
    with pytest.raises(HTTPForbidden):
        validate_user(dummy_request.dbsession, data)
def test_validate_user_raises_error_for_incomplete_data(dummy_request):
    """Test that validate_user raises HTTPBadRequest for missing password."""
    data = {'email': FAKE.email()}
    with pytest.raises(HTTPBadRequest):
        validate_user(dummy_request.dbsession, data)