def test_external_sync_disabling(db, mock_queue_client):
    purge_other_accounts()
    account = add_generic_imap_account(db.session, email_address='*****@*****.**')
    other_account = add_generic_imap_account(
        db.session, email_address='*****@*****.**')
    qp = QueuePopulator(zone='testzone')
    qp.queue_client = mock_queue_client
    s = patched_sync_service(db, mock_queue_client)

    qp.enqueue_new_accounts()
    s.poll()
    s.poll()
    assert len(s.syncing_accounts) == 2

    account.mark_deleted()
    db.session.commit()
    assert account.sync_should_run is False
    assert account._sync_status['sync_disabled_reason'] == 'account deleted'

    account.mark_invalid()
    db.session.commit()
    assert account.sync_should_run is False
    assert account.sync_state == 'invalid'
    assert account._sync_status['sync_disabled_reason'] == \
        'invalid credentials'

    qp.unassign_disabled_accounts()
    s.poll()
    assert s.syncing_accounts == {other_account.id}
Beispiel #2
0
def test_external_sync_disabling(monkeypatch, db, mock_queue_client):
    monkeypatch.setattr('psutil.cpu_percent',
                        lambda *args, **kwargs: [10.0, 25.0])

    purge_other_accounts()
    account = add_generic_imap_account(db.session,
                                       email_address='*****@*****.**')
    other_account = add_generic_imap_account(db.session,
                                             email_address='*****@*****.**')
    qp = QueuePopulator(zone='testzone')
    qp.queue_client = mock_queue_client
    s = patched_sync_service(db, mock_queue_client)

    qp.enqueue_new_accounts()
    s.poll()
    s.poll()
    assert len(s.syncing_accounts) == 2

    account.mark_deleted()
    db.session.commit()
    assert account.sync_should_run is False
    assert account._sync_status['sync_disabled_reason'] == 'account deleted'

    account.mark_invalid()
    db.session.commit()
    assert account.sync_should_run is False
    assert account.sync_state == 'invalid'
    assert account._sync_status['sync_disabled_reason'] == \
        'invalid credentials'

    qp.unassign_disabled_accounts()
    s.poll()
    assert s.syncing_accounts == {other_account.id}
def test_external_sync_disabling(db, mock_queue_client):
    purge_other_accounts()
    account = add_fake_account(db.session, email_address='*****@*****.**')
    other_account = add_fake_account(db.session,
                                     email_address='*****@*****.**')
    qp = QueuePopulator(zone='testzone')
    qp.queue_client = mock_queue_client
    s = patched_sync_service(mock_queue_client)

    qp.enqueue_new_accounts()
    s.poll()
    s.poll()
    assert len(s.syncing_accounts) == 2

    account.mark_deleted()
    db.session.commit()
    assert account.sync_should_run is False
    assert account._sync_status['sync_disabled_reason'] == 'account deleted'

    account.mark_invalid()
    db.session.commit()
    assert account.sync_should_run is False
    assert account.sync_state == 'invalid'
    assert account._sync_status['sync_disabled_reason'] == \
        'invalid credentials'

    qp.unassign_disabled_accounts()
    s.poll()
    assert s.syncing_accounts == {other_account.id}