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
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
def test_deletes(contacts_provider, db): contacts_provider.supply_contact('Name', '*****@*****.**') poll(ACCOUNT_ID, contacts_provider) results = db.session.query(Contact).all() assert len(results) == 2 db.new_session() contacts_provider.__init__() contacts_provider.supply_contact(None, None, deleted=True) poll(ACCOUNT_ID, contacts_provider) results = db.session.query(Contact).all() assert len(results) == 0
def test_add_contacts(contacts_provider, db): """Test that added contacts get stored.""" contacts_provider.supply_contact('Contact One', '*****@*****.**') contacts_provider.supply_contact('Contact Two', '*****@*****.**') poll(ACCOUNT_ID, contacts_provider) local_contacts = db.session.query(Contact). \ filter_by(account_id=ACCOUNT_ID).filter_by(source='local').count() remote_contacts = db.session.query(Contact). \ filter_by(account_id=ACCOUNT_ID).filter_by(source='remote').count() assert local_contacts == 2 assert remote_contacts == 2
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'
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
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