# Path: pypi_portal/extensions.py
# LOG = getLogger(__name__)
# def _on_connect(dbapi_connection, **_):
# 
# Path: pypi_portal/models/pypi.py
# class Package(Base):
#     """Holds all of the packages on PyPI."""
#     name = Column(String(255), unique=True, nullable=False)
#     summary = Column(Text, nullable=False)
#     latest_version = Column(String(128), nullable=False)
# 
# Path: pypi_portal/models/redis.py
# POLL_SIMPLE_THROTTLE = 'pypi_portal:poll_simple_throttle'  # Lock.
# 
# Path: pypi_portal/tasks/pypi.py
# LOG = getLogger(__name__)
# THROTTLE = 1 * 60 * 60
# def update_package_list():


from flask import current_app
from flask.ext.celery import CELERY_LOCK
from redis.exceptions import LockError
from pypi_portal.extensions import db, redis
from pypi_portal.models.pypi import Package
from pypi_portal.models.redis import POLL_SIMPLE_THROTTLE
from pypi_portal.tasks import pypi
import pytest



class FakeDelay(object):
    @staticmethod
    def ready():
        return False


def test_index():
    assert '200 OK' == current_app.test_client().get('/pypi/').status


def test_sync_empty(alter_xmlrpc):
    alter_xmlrpc(set())
    redis.delete(POLL_SIMPLE_THROTTLE)
    Package.query.delete()
    db.session.commit()

    assert '302 FOUND' == current_app.test_client().get('/pypi/sync').status
    assert [] == db.session.query(Package.name, Package.summary, Package.latest_version).all()


def test_sync_few(alter_xmlrpc):
    alter_xmlrpc([dict(name='packageB', summary='Test package.', version='3.0.0'), ])

# Path: pypi_portal/extensions.py
# LOG = getLogger(__name__)
# def _on_connect(dbapi_connection, **_):
# 
# Path: pypi_portal/models/pypi.py
# class Package(Base):
#     """Holds all of the packages on PyPI."""
#     name = Column(String(255), unique=True, nullable=False)
#     summary = Column(Text, nullable=False)
#     latest_version = Column(String(128), nullable=False)
# 
# Path: pypi_portal/models/redis.py
# POLL_SIMPLE_THROTTLE = 'pypi_portal:poll_simple_throttle'  # Lock.
# 
# Path: pypi_portal/tasks/pypi.py
# LOG = getLogger(__name__)
# THROTTLE = 1 * 60 * 60
# def update_package_list():


# Path: tests/views/test_pypi_packages.py
from flask import current_app
from flask.ext.celery import CELERY_LOCK
from redis.exceptions import LockError
from pypi_portal.extensions import db, redis
from pypi_portal.models.pypi import Package
from pypi_portal.models.redis import POLL_SIMPLE_THROTTLE
from pypi_portal.tasks import pypi
import pytest




class FakeDelay(object):
    @staticmethod
    def ready():
        return False


def test_index():
    assert '200 OK' == current_app.test_client().get('/pypi/').status


def test_sync_empty(alter_xmlrpc):
    alter_xmlrpc(set())
    redis.delete(POLL_SIMPLE_THROTTLE)
    Package.query.delete()
    db.session.commit()

    assert '302 FOUND' == current_app.test_client().get('/pypi/sync').status
    assert [] == db.session.query(Package.name, Package.summary, Package.latest_version).all()


def test_sync_few(alter_xmlrpc):
    alter_xmlrpc([dict(name='packageB', summary='Test package.', version='3.0.0'), ])

    redis.delete(POLL_SIMPLE_THROTTLE)