Пример #1
0
def test_uses_local_updates(events_provider, event_sync, db):
    """Test that non-conflicting local and remote updates to the same event
    both get stored."""
    events_provider.supply_event('subj', '', 0, 1, False, False)
    event_sync.provider_instance = events_provider
    event_sync.poll()
    results = db.session.query(Event).filter_by(source='local').all()
    # Fake a local event update.
    results[-1].subject = 'New Subject'
    db.session.commit()

    events_provider.__init__()
    events_provider.supply_event('subj', 'newbody', 0, 1, False, False)
    event_sync.provider_instance = events_provider
    event_sync.poll()

    remote_results = db.session.query(Event).filter_by(source='remote').all()
    subjects = [r.subject for r in remote_results]
    assert 'New Subject' in subjects
    bodies = [r.body for r in remote_results]
    assert 'newbody' in bodies

    local_results = db.session.query(Event).filter_by(source='local').all()
    subjects = [r.subject for r in local_results]
    assert 'New Subject' in subjects
    bodies = [r.body for r in local_results]
    assert 'newbody' in bodies
Пример #2
0
def test_api_get(events_provider, event_sync, db, api_client):
    events_provider.supply_event('subj', '', 0, 1, False, False)
    events_provider.supply_event('subj2', '', 0, 1, False, False)

    event_sync.provider_instance = events_provider
    event_sync.poll()
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    event_list = api_client.get_data('/events', ns_id)

    event_ids = [event['id'] for event in event_list]

    c1found = False
    c2found = False
    for c_id in event_ids:
        event = api_client.get_data('/events/' + c_id, ns_id)

        if event['subject'] == 'subj':
            c1found = True

        if event['subject'] == 'subj2':
            c2found = True

    assert c1found
    assert c2found
Пример #3
0
def test_uses_local_updates(events_provider, event_sync, db):
    """Test that non-conflicting local and remote updates to the same event
    both get stored."""
    events_provider.supply_event('subj', '', 0, 1, False, False)
    event_sync.provider_instance = events_provider
    event_sync.poll()
    results = db.session.query(Event).filter_by(source='local').all()
    # Fake a local event update.
    results[-1].subject = 'New Subject'
    db.session.commit()

    events_provider.__init__()
    events_provider.supply_event('subj', 'newbody', 0, 1, False, False)
    event_sync.provider_instance = events_provider
    event_sync.poll()

    remote_results = db.session.query(Event).filter_by(source='remote').all()
    subjects = [r.subject for r in remote_results]
    assert 'New Subject' in subjects
    bodies = [r.body for r in remote_results]
    assert 'newbody' in bodies

    local_results = db.session.query(Event).filter_by(source='local').all()
    subjects = [r.subject for r in local_results]
    assert 'New Subject' in subjects
    bodies = [r.body for r in local_results]
    assert 'newbody' in bodies
Пример #4
0
def test_api_get(events_provider, event_sync, db, api_client):
    events_provider.supply_event('subj', '', 0, 1, False, False)
    events_provider.supply_event('subj2', '', 0, 1, False, False)

    event_sync.provider_instance = events_provider
    event_sync.poll()
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    event_list = api_client.get_data('/events', ns_id)

    event_ids = [event['id'] for event in event_list]

    c1found = False
    c2found = False
    for c_id in event_ids:
        event = api_client.get_data('/events/' + c_id, ns_id)

        if event['subject'] == 'subj':
            c1found = True

        if event['subject'] == 'subj2':
            c2found = True

    assert c1found
    assert c2found
Пример #5
0
def test_deletes(events_provider, event_sync, db):
    num_original_events = db.session.query(Event).count()
    events_provider.supply_event('subj', '', 0, 1, False, False)
    event_sync.provider_instance = events_provider
    event_sync.poll()
    num_current_events = db.session.query(Event).count()
    assert num_current_events - num_original_events == 2

    events_provider.__init__()
    events_provider.supply_event('subj', '', 0, 1, False, False, deleted=True)
    event_sync.poll()

    num_current_events = db.session.query(Event).count()
    assert num_current_events == num_original_events
Пример #6
0
def test_deletes(events_provider, event_sync, db):
    num_original_events = db.session.query(Event).count()
    events_provider.supply_event('subj', '', 0, 1, False, False)
    event_sync.provider_instance = events_provider
    event_sync.poll()
    num_current_events = db.session.query(Event).count()
    assert num_current_events - num_original_events == 2

    events_provider.__init__()
    events_provider.supply_event('subj', '', 0, 1, False, False, deleted=True)
    event_sync.poll()

    num_current_events = db.session.query(Event).count()
    assert num_current_events == num_original_events
Пример #7
0
def test_add_events(events_provider, event_sync, db):
    """Test that added events get stored."""
    num_original_local_events = db.session.query(Event). \
        filter_by(account_id=ACCOUNT_ID).filter_by(source='local').count()
    num_original_remote_events = db.session.query(Event). \
        filter_by(account_id=ACCOUNT_ID).filter_by(source='remote').count()
    events_provider.supply_event('subj', '', 0, 1, False, False)
    events_provider.supply_event('subj2', '', 0, 1, False, False)

    event_sync.provider_instance = events_provider
    event_sync.poll()
    num_current_local_events = db.session.query(Event). \
        filter_by(account_id=ACCOUNT_ID).filter_by(source='local').count()
    num_current_remote_events = db.session.query(Event). \
        filter_by(account_id=ACCOUNT_ID).filter_by(source='remote').count()
    assert num_current_local_events - num_original_local_events == 2
    assert num_current_remote_events - num_original_remote_events == 2
Пример #8
0
def test_add_events(events_provider, event_sync, db):
    """Test that added events get stored."""
    num_original_local_events = db.session.query(Event). \
        filter_by(account_id=ACCOUNT_ID).filter_by(source='local').count()
    num_original_remote_events = db.session.query(Event). \
        filter_by(account_id=ACCOUNT_ID).filter_by(source='remote').count()
    events_provider.supply_event('subj', '', 0, 1, False, False)
    events_provider.supply_event('subj2', '', 0, 1, False, False)

    event_sync.provider_instance = events_provider
    event_sync.poll()
    num_current_local_events = db.session.query(Event). \
        filter_by(account_id=ACCOUNT_ID).filter_by(source='local').count()
    num_current_remote_events = db.session.query(Event). \
        filter_by(account_id=ACCOUNT_ID).filter_by(source='remote').count()
    assert num_current_local_events - num_original_local_events == 2
    assert num_current_remote_events - num_original_remote_events == 2
Пример #9
0
def test_api_list(events_provider, event_sync, db, api_client):
    events_provider.supply_event('subj', 'body1', 0, 1, False, False)
    events_provider.supply_event('subj2', 'body2', 0, 1, False, False)

    event_sync.provider_instance = events_provider
    event_sync.poll()
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    event_list = api_client.get_data('/events', ns_id)
    event_subjects = [event['subject'] for event in event_list]
    assert 'subj' in event_subjects
    assert 'subj2' in event_subjects

    event_bodies = [event['body'] for event in event_list]
    assert 'body1' in event_bodies
    assert 'body2' in event_bodies
Пример #10
0
def test_api_list(events_provider, event_sync, db, api_client):
    events_provider.supply_event('subj', 'body1', 0, 1, False, False)
    events_provider.supply_event('subj2', 'body2', 0, 1, False, False)

    event_sync.provider_instance = events_provider
    event_sync.poll()
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    event_list = api_client.get_data('/events', ns_id)
    event_subjects = [event['subject'] for event in event_list]
    assert 'subj' in event_subjects
    assert 'subj2' in event_subjects

    event_bodies = [event['body'] for event in event_list]
    assert 'body1' in event_bodies
    assert 'body2' in event_bodies
Пример #11
0
def test_multiple_remotes(events_provider, alternate_events_provider,
                          event_sync, db):
    events_provider.supply_event('subj', '', 0, 1, False, False)
    alternate_events_provider.supply_event('subj2', 'body', 0, 1, False, False)

    event_sync.provider_instance = events_provider
    event_sync.poll()

    event_sync.provider_instance = alternate_events_provider
    event_sync.poll()

    result = db.session.query(Event). \
        filter_by(source='local', provider_name='test_provider').one()
    alternate_result = db.session.query(Event). \
        filter_by(source='local', provider_name='alternate_provider').one()
    # Check that both events were persisted, even though they have the same
    # uid.
    assert result.subject == 'subj'
    assert alternate_result.subject == 'subj2'
Пример #12
0
def test_multiple_remotes(events_provider, alternate_events_provider,
                          event_sync, db):
    events_provider.supply_event('subj', '', 0, 1, False, False)
    alternate_events_provider.supply_event('subj2', 'body', 0, 1, False, False)

    event_sync.provider_instance = events_provider
    event_sync.poll()

    event_sync.provider_instance = alternate_events_provider
    event_sync.poll()

    result = db.session.query(Event). \
        filter_by(source='local', provider_name='test_provider').one()
    alternate_result = db.session.query(Event). \
        filter_by(source='local', provider_name='alternate_provider').one()
    # Check that both events were persisted, even though they have the same
    # uid.
    assert result.subject == 'subj'
    assert alternate_result.subject == 'subj2'
Пример #13
0
def test_update_event(events_provider, event_sync, db):
    """Test that subsequent event updates get stored."""
    events_provider.supply_event('subj', '', 0, 1, False, False)
    event_sync.provider_instance = events_provider
    event_sync.poll()
    results = db.session.query(Event).filter_by(source='remote').all()
    db.new_session()
    subjects = [r.subject for r in results]
    assert 'subj' in subjects

    events_provider.__init__()
    events_provider.supply_event('newsubj', 'newbody', 0, 1, False, False)
    event_sync.poll()
    db.new_session()

    results = db.session.query(Event).filter_by(source='remote').all()
    subjs = [r.subject for r in results]
    assert 'newsubj' in subjs
    bodies = [r.body for r in results]
    assert 'newbody' in bodies
Пример #14
0
def test_update_event(events_provider, event_sync, db):
    """Test that subsequent event updates get stored."""
    events_provider.supply_event('subj', '', 0, 1, False, False)
    event_sync.provider_instance = events_provider
    event_sync.poll()
    results = db.session.query(Event).filter_by(source='remote').all()
    db.new_session()
    subjects = [r.subject for r in results]
    assert 'subj' in subjects

    events_provider.__init__()
    events_provider.supply_event('newsubj', 'newbody', 0, 1, False, False)
    event_sync.poll()
    db.new_session()

    results = db.session.query(Event).filter_by(source='remote').all()
    subjs = [r.subject for r in results]
    assert 'newsubj' in subjs
    bodies = [r.body for r in results]
    assert 'newbody' in bodies