Example #1
0
def test_sync_empty(alter_xmlrpc):
    alter_xmlrpc(set())
    redis.delete(POLL_SIMPLE_THROTTLE)
    Package.query.delete()
    database.session.commit()

    assert '302 FOUND' == current_app.test_client().get('/pypi/sync').status
    assert [] == database.session.query(Package.name, Package.summary,
                                        Package.latest_version).all()
Example #2
0
def test_sync_unhandled_exception():
    old_throttle = pypi.THROTTLE
    pypi.THROTTLE = 'nan'
    redis.delete(POLL_SIMPLE_THROTTLE)

    with pytest.raises(ValueError):
        current_app.test_client().get('/pypi/sync').status()

    pypi.THROTTLE = old_throttle
Example #3
0
def test_rate_limit():
    assert redis.exists(POLL_SIMPLE_THROTTLE)
    assert update_package_list() is None

    redis.delete(POLL_SIMPLE_THROTTLE)
    assert not redis.exists(POLL_SIMPLE_THROTTLE)
    assert list() == update_package_list()

    assert redis.exists(POLL_SIMPLE_THROTTLE)
    assert update_package_list() is None
Example #4
0
def test_sync_few(alter_xmlrpc):
    alter_xmlrpc([
        dict(name='packageB', summary='Test package.', version='3.0.0'),
    ])
    redis.delete(POLL_SIMPLE_THROTTLE)

    assert '302 FOUND' == current_app.test_client().get('/pypi/sync').status

    expected = [
        ('packageB', 'Test package.', '3.0.0'),
    ]
    actual = database.session.query(Package.name, Package.summary,
                                    Package.latest_version).all()
    assert expected == actual
Example #5
0
def test_sorting(alter_xmlrpc, latest):
    value = [
        dict(name='packageA',
             summary='Test package.',
             version=('2.0.0-beta' if latest else '0.0.9')),
        dict(name='packageA', summary='Test package.', version='1.10.0'),
        dict(name='packageB', summary='Test package.', version='3.0.0'),
    ]
    alter_xmlrpc(value)
    redis.delete(POLL_SIMPLE_THROTTLE)
    assert sorted(['packageA', 'packageB']) == sorted(update_package_list())

    expected = [
        ('packageA', 'Test package.', '2.0.0-beta' if latest else '1.10.0'),
        ('packageB', 'Test package.', '3.0.0'),
    ]
    actual = database.session.query(Package.name, Package.summary,
                                    Package.latest_version).all()
    assert expected == actual
Example #6
0
def test_sync_timeout():
    old_delay = pypi.update_package_list.delay
    pypi.update_package_list.delay = FakeDelay
    redis.delete(POLL_SIMPLE_THROTTLE)

    assert '302 FOUND' == current_app.test_client().get('/pypi/sync').status

    expected = [
        ('packageB', 'Test package.', '3.0.0'),
        ('packageB1', 'Test package.', '3.0.0'),
        ('packageB2', 'Test package.', '3.0.0'),
        ('packageB3', 'Test package.', '3.0.0'),
        ('packageB4', 'Test package.', '3.0.0'),
        ('packageB5', 'Test package.', '3.0.0'),
    ]
    actual = database.session.query(Package.name, Package.summary,
                                    Package.latest_version).all()
    assert sorted(expected) == sorted(actual)

    pypi.update_package_list.delay = old_delay
Example #7
0
def test_sync_parallel(alter_xmlrpc):
    alter_xmlrpc([
        dict(name='packageD', summary='Test package.', version='3.0.0'),
    ])
    redis.delete(POLL_SIMPLE_THROTTLE)

    redis_key = CELERY_LOCK.format(
        task_name='restify.tasks.pypi.update_package_list')
    lock = redis.lock(redis_key, timeout=1)
    assert lock.acquire(blocking=False)

    assert '302 FOUND' == current_app.test_client().get('/pypi/sync').status

    expected = [
        ('packageB', 'Test package.', '3.0.0'),
    ]
    actual = database.session.query(Package.name, Package.summary,
                                    Package.latest_version).all()
    assert expected == actual

    try:
        lock.release()
    except LockError:
        pass
Example #8
0
def test_no_results(alter_xmlrpc):
    alter_xmlrpc(set())
    redis.delete(POLL_SIMPLE_THROTTLE)
    assert list() == update_package_list()