示例#1
0
def test_uses_local_updates(contacts_provider, db):
    """Test that non-conflicting local and remote updates to the same contact
    both get stored."""
    contacts_provider.supply_contact("Old Name", "*****@*****.**")
    poll(ACCOUNT_ID, contacts_provider)
    results = db.session.query(Contact).filter_by(source="local").all()
    # Fake a local contact update.
    results[-1].name = "New Name"
    db.session.commit()

    contacts_provider.__init__()
    contacts_provider.supply_contact("Old Name", "*****@*****.**")
    poll(ACCOUNT_ID, contacts_provider)

    remote_results = db.session.query(Contact).filter_by(source="remote").all()
    names = [r.name for r in remote_results]
    assert "New Name" in names
    email_addresses = [r.email_address for r in remote_results]
    assert "*****@*****.**" in email_addresses

    local_results = db.session.query(Contact).filter_by(source="local").all()
    names = [r.name for r in local_results]
    assert "New Name" in names
    email_addresses = [r.email_address for r in local_results]
    assert "*****@*****.**" in email_addresses
示例#2
0
def test_deletes(contacts_provider, db):
    num_original_contacts = db.session.query(Contact).count()
    contacts_provider.supply_contact("Name", "*****@*****.**")
    poll(ACCOUNT_ID, contacts_provider)
    num_current_contacts = db.session.query(Contact).count()
    assert num_current_contacts - num_original_contacts == 2

    contacts_provider.__init__()
    contacts_provider.supply_contact(None, None, deleted=True)
    poll(ACCOUNT_ID, contacts_provider)
    num_current_contacts = db.session.query(Contact).count()
    assert num_current_contacts == num_original_contacts
示例#3
0
def test_multiple_remotes(contacts_provider, alternate_contacts_provider, db):
    contacts_provider.supply_contact("Name", "*****@*****.**")
    alternate_contacts_provider.supply_contact("Alternate Name", "*****@*****.**")

    poll(ACCOUNT_ID, contacts_provider)
    poll(ACCOUNT_ID, alternate_contacts_provider)
    result = db.session.query(Contact).filter_by(source="local", provider_name="test_provider").one()
    alternate_result = db.session.query(Contact).filter_by(source="local", provider_name="alternate_provider").one()
    # Check that both contacts were persisted, even though they have the same
    # uid.
    assert result.name == "Name"
    assert alternate_result.name == "Alternate Name"
示例#4
0
def test_update_contact(contacts_provider, db):
    """Test that subsequent contact updates get stored."""
    contacts_provider.supply_contact("Old Name", "*****@*****.**")
    poll(ACCOUNT_ID, contacts_provider)
    results = db.session.query(Contact).filter_by(source="remote").all()
    db.new_session()
    email_addresses = [r.email_address for r in results]
    assert "*****@*****.**" in email_addresses

    contacts_provider.__init__()
    contacts_provider.supply_contact("New Name", "*****@*****.**")
    poll(ACCOUNT_ID, contacts_provider)
    results = db.session.query(Contact).filter_by(source="remote").all()
    names = [r.name for r in results]
    assert "New Name" in names
    email_addresses = [r.email_address for r in results]
    assert "*****@*****.**" in email_addresses
示例#5
0
def test_add_contacts(contacts_provider, db):
    """Test that added contacts get stored."""
    num_original_local_contacts = (
        db.session.query(Contact).filter_by(account_id=ACCOUNT_ID).filter_by(source="local").count()
    )
    num_original_remote_contacts = (
        db.session.query(Contact).filter_by(account_id=ACCOUNT_ID).filter_by(source="remote").count()
    )
    contacts_provider.supply_contact("Contact One", "*****@*****.**")
    contacts_provider.supply_contact("Contact Two", "*****@*****.**")

    poll(ACCOUNT_ID, contacts_provider)
    num_current_local_contacts = (
        db.session.query(Contact).filter_by(account_id=ACCOUNT_ID).filter_by(source="local").count()
    )
    num_current_remote_contacts = (
        db.session.query(Contact).filter_by(account_id=ACCOUNT_ID).filter_by(source="remote").count()
    )
    assert num_current_local_contacts - num_original_local_contacts == 2
    assert num_current_remote_contacts - num_original_remote_contacts == 2