Ejemplo n.º 1
0
def test_bulk_namespace_deletion(db):
    from inbox.models import Account
    from inbox.models.util import get_accounts_to_delete, delete_marked_accounts

    db.session.query(Account).delete(synchronize_session=False)
    db.session.commit()
    assert db.session.query(Account.id).count() == 0

    # Add 5 accounts
    account_1 = add_completely_fake_account(db)
    account_1_id = account_1.id

    account_2 = add_completely_fake_account(db, "*****@*****.**")
    account_2_id = account_2.id

    account_3 = add_completely_fake_account(db, "*****@*****.**")
    account_3_id = account_3.id

    account_4 = add_completely_fake_account(db, "*****@*****.**")
    account_4_id = account_4.id

    add_completely_fake_account(db, "*****@*****.**")

    # Ensure all of the accounts have been created successfully
    assert db.session.query(Account).count() == 5

    # delete_marked_accounts() with no accounts marked as deleted
    to_delete = get_accounts_to_delete(0)
    delete_marked_accounts(0, to_delete)
    assert len(db.session.query(Account.id).all()) == 5

    # delete_marked_accounts() with one account marked as deleted
    account_1.mark_deleted()
    db.session.commit()

    to_delete = get_accounts_to_delete(0)
    delete_marked_accounts(0, to_delete)

    alive_accounts = db.session.query(Account.id).all()
    assert len(alive_accounts) == 4
    assert account_1_id not in alive_accounts

    # delete_marked_accounts() with more than one account marked as deleted
    account_2.mark_deleted()
    account_3.mark_deleted()
    account_4.mark_deleted()
    db.session.commit()

    to_delete = get_accounts_to_delete(0)
    delete_marked_accounts(0, to_delete)

    alive_accounts = db.session.query(Account.id).all()
    assert len(alive_accounts) == 1
    assert account_4_id not in alive_accounts
    assert account_3_id not in alive_accounts
    assert account_2_id not in alive_accounts
Ejemplo n.º 2
0
def test_bulk_namespace_deletion(db):
    from inbox.models import Account
    from inbox.models.util import get_accounts_to_delete, delete_marked_accounts

    db.session.query(Account).delete(synchronize_session=False)
    db.session.commit()
    assert db.session.query(Account.id).count() == 0

    # Add 5 accounts
    account_1 = add_completely_fake_account(db)
    account_1_id = account_1.id

    account_2 = add_completely_fake_account(db, "*****@*****.**")
    account_2_id = account_2.id

    account_3 = add_completely_fake_account(db, "*****@*****.**")
    account_3_id = account_3.id

    account_4 = add_completely_fake_account(db, "*****@*****.**")
    account_4_id = account_4.id

    add_completely_fake_account(db, "*****@*****.**")

    # Ensure all of the accounts have been created successfully
    assert db.session.query(Account).count() == 5

    # delete_marked_accounts() with no accounts marked as deleted
    to_delete = get_accounts_to_delete(0)
    delete_marked_accounts(0, to_delete)
    assert len(db.session.query(Account.id).all()) == 5

    # delete_marked_accounts() with one account marked as deleted
    account_1.mark_deleted()
    db.session.commit()

    to_delete = get_accounts_to_delete(0)
    delete_marked_accounts(0, to_delete)

    alive_accounts = db.session.query(Account.id).all()
    assert len(alive_accounts) == 4
    assert account_1_id not in alive_accounts

    # delete_marked_accounts() with more than one account marked as deleted
    account_2.mark_deleted()
    account_3.mark_deleted()
    account_4.mark_deleted()
    db.session.commit()

    to_delete = get_accounts_to_delete(0)
    delete_marked_accounts(0, to_delete)

    alive_accounts = db.session.query(Account.id).all()
    assert len(alive_accounts) == 1
    assert account_4_id not in alive_accounts
    assert account_3_id not in alive_accounts
    assert account_2_id not in alive_accounts
Ejemplo n.º 3
0
def test_bulk_namespace_deletion(db):
    from inbox.models import Account
    from inbox.models.util import delete_marked_accounts

    old_account_count = len(db.session.query(Account.id).all())

    account_1 = add_completely_fake_account(db)
    account_1_id = account_1.id

    account_2 = add_completely_fake_account(db, "*****@*****.**")
    account_2_id = account_2.id

    account_3 = add_completely_fake_account(db, "*****@*****.**")
    account_3_id = account_3.id

    account_4 = add_completely_fake_account(db, "*****@*****.**")
    account_4_id = account_4.id

    add_completely_fake_account(db, "*****@*****.**")

    # Ensure all of the accounts have been created successfully
    assert len(db.session.query(Account.id).all()) - old_account_count == 5

    # run delete_marked_accounts with no accounts marked as deleted
    delete_marked_accounts(0)
    assert len(db.session.query(Account.id).all()) - old_account_count == 5

    account_1.mark_deleted()
    db.session.commit()
    delete_marked_accounts(0)

    alive_accounts = db.session.query(Account.id).all()
    assert len(alive_accounts) - old_account_count == 4
    assert account_1_id not in alive_accounts

    account_2.mark_deleted()
    account_3.mark_deleted()
    account_4.mark_deleted()
    db.session.commit()

    delete_marked_accounts(0)

    alive_accounts = db.session.query(Account.id).all()
    assert len(alive_accounts) - old_account_count == 1
    assert account_4_id not in alive_accounts
    assert account_3_id not in alive_accounts
    assert account_2_id not in alive_accounts
Ejemplo n.º 4
0
def test_bulk_namespace_deletion(db):
    from inbox.models import Account
    from inbox.models.util import delete_marked_accounts

    old_account_count = len(db.session.query(Account.id).all())

    account_1 = add_completely_fake_account(db)
    account_1_id = account_1.id

    account_2 = add_completely_fake_account(db, "*****@*****.**")
    account_2_id = account_2.id

    account_3 = add_completely_fake_account(db, "*****@*****.**")
    account_3_id = account_3.id

    account_4 = add_completely_fake_account(db, "*****@*****.**")
    account_4_id = account_4.id

    add_completely_fake_account(db, "*****@*****.**")

    # Ensure all of the accounts have been created successfully
    assert len(db.session.query(Account.id).all()) - old_account_count == 5

    # run delete_marked_accounts with no accounts marked as deleted
    delete_marked_accounts(0)
    assert len(db.session.query(Account.id).all()) - old_account_count == 5

    account_1.mark_deleted()
    db.session.commit()
    delete_marked_accounts(0)

    alive_accounts = db.session.query(Account.id).all()
    assert len(alive_accounts) - old_account_count == 4
    assert account_1_id not in alive_accounts

    account_2.mark_deleted()
    account_3.mark_deleted()
    account_4.mark_deleted()
    db.session.commit()

    delete_marked_accounts(0)

    alive_accounts = db.session.query(Account.id).all()
    assert len(alive_accounts) - old_account_count == 1
    assert account_4_id not in alive_accounts
    assert account_3_id not in alive_accounts
    assert account_2_id not in alive_accounts