예제 #1
0
def test_a_primary_email_cannot_be_deleted_using__the_sql(session):
    """A primary email cannot be deleted. This is enforced in the SQL."""
    # Given a user with a primary email set
    user = create_user(
        session,
        emails=['*****@*****.**', '*****@*****.**', '*****@*****.**'])
    user.emails[0].verify()
    user.primary_email = '*****@*****.**'
    user.save()

    # When attempting to delete this primary email
    # Then expect an IntegrityError
    with pytest.raises(IntegrityError):
        session.query(Email).filter_by(email='*****@*****.**').delete()
예제 #2
0
def test_a_user_can_be_deleted(session):
    """When a user is deleted, the user's emails are also deleted."""
    # Given a user with its corresponding id
    user = create_user(session, email='*****@*****.**')

    user.save()
    user_id = user.id

    assert session.query(User).filter_by(id=user_id).count() == 1

    # When the user is deleted
    user.delete()

    # Expect not to find the user.
    assert session.query(User).filter_by(id=user_id).count() == 0
예제 #3
0
def test_when_an_email_is_deleted_the_user_remains_untouched(session):
    """When a user is deleted, the user's emails are also deleted."""
    # Given a user with multiple email addresses
    user = create_user(
        session,
        emails=['*****@*****.**', '*****@*****.**', '*****@*****.**'])
    user.save()
    user_id = user.id

    # When one of those emails is deleted
    session.query(Email).filter_by(email='*****@*****.**').delete()
    assert session.query(Email).filter_by(
        email='*****@*****.**').count() == 0

    # Expect the user to still be there
    assert session.query(User).filter_by(id=user_id).count() == 1
예제 #4
0
def test_a_user_with_a_primary_email_can_be_deleted(session):
    """A user with a primary email can be deleted. This also deletes the
    primary email."""
    # Given a user with a primary email set
    user = create_user(
        session,
        emails=['*****@*****.**', '*****@*****.**', '*****@*****.**'])
    user.emails[0].verify()
    user.primary_email = '*****@*****.**'
    user.save()
    user_id = user.id

    # When deletin the user
    user.delete()

    # Then expect both the user and the email to be gone from the database
    assert session.query(Email).filter_by(
        email='*****@*****.**').count() == 0
    assert session.query(User).filter_by(id=user_id).count() == 0
예제 #5
0
def test_user_can_be_saved_to_database(session):
    """A user can be saved to the database."""
    # Given a user
    user = User(first_name='Jane',
                last_name='Doe',
                password='******',
                email='*****@*****.**')

    # When a user is saved to the database
    user.save()

    # Then a query should find it and it should be active
    user = session.query(User).filter_by(first_name='Jane').first()
    assert user.first_name == 'Jane'
    assert user.active
    assert user.is_active  # Proxied from active property
예제 #6
0
def test_when_a_user_is_deleted_their_emails_are_also_deleted(session):
    """When a user is deleted, the user's emails are also deleted."""
    # Given a user with multiple emails (none set as primary)
    user = create_user(
        session,
        emails=['*****@*****.**', '*****@*****.**', '*****@*****.**'])

    assert session.query(Email).filter_by(
        email='*****@*****.**').count() == 1
    assert session.query(Email).filter_by(
        email='*****@*****.**').count() == 1
    assert session.query(Email).filter_by(
        email='*****@*****.**').count() == 1

    # When the user is deleted
    user.delete()

    # Expect not to find the emails.
    assert session.query(Email).filter_by(
        email='*****@*****.**').count() == 0
    assert session.query(Email).filter_by(
        email='*****@*****.**').count() == 0
    assert session.query(Email).filter_by(
        email='*****@*****.**').count() == 0