예제 #1
0
def test_package_updates(session):
    # Add more more dummy data
    pkg = db.Package(name="test_proj", latest_version="0.1.4")
    session.add(pkg)
    session.commit()

    session.add(db.Version(package_id=pkg.package_id, version="0.1.3"))
    session.add(db.Version(package_id=pkg.package_id, version="0.1.4"))
    session.commit()

    data = {1: '0.0.2', 2: '0.1.3'}

    result = db.package_updates(session, data)
    assert len(result) == 2
    assert type(result[0]) == db.Version
    assert result[0].package.name == "dummy"
    assert result[0].version == "0.0.3"
    assert result[1].package.name == "test_proj"
    assert result[1].version == "0.1.4"

    # if we currently have the latest version, return nothing. Do not return
    # packages that we don't have installed.
    data = {1: '0.0.3'}
    result = db.package_updates(session, data)
    assert len(result) == 0
예제 #2
0
def test_search_packages(session):
    # Test with no args
    result = db.search_packages(session)
    assert len(result) == 3
    assert type(result[0]) == db.Version
    assert result[0].package.latest_version == "0.0.3"

    # add a little more dummy data
    pkg = db.Package(name="test_proj", latest_version="0.1.3")
    session.add(pkg)
    session.commit()

    session.add(db.Version(package_id=pkg.package_id, version="0.1.3"))
    session.commit()

    # Test with a search query. Note that the wildcards are added by
    # the function, and so they're not needed.
    result = db.search_packages(session, search_query='test')
    assert len(result) == 1
    assert result[0].package.name == "test_proj"

    # Test with a filter.
    result = db.search_packages(session,
                                filter_='IsLatestVersion',
                                search_query='%dummy%')
    assert len(result) == 1
    assert result[0].version == "0.0.3"

    # Test with a different order_by
    result = db.search_packages(session, order_by=sa.desc(db.Version.version))
    assert len(result) == 4
    assert result[0].version == '0.1.3'
    assert result[-1].version == '0.0.1'
예제 #3
0
def version_row():
    row = db.Version(
        version_id=1,
        package_id=1,
        version="0.0.1",
        copyright_="No copyright",
        created=dt.datetime(1970, 1, 1, 0, 0, 0, 0),
        dependencies='[{"id": 1, "version": "0.2.3"}]',
        description="Some description",
        icon_url="no url",
        is_prerelease=False,
        package_hash="abc123",
        package_hash_algorithm="Michael Jackson",
        package_size=1024,
        project_url="https://github.com/dougthor42/pynuget/",
        release_notes="No release notes. Sorry!",
        require_license_acceptance=False,
        tags="no tags",
        title="DummyPackage",
        version_download_count=9,
        license_url="https://github.com/dougthor42/pynuget/blob/master/LICENSE",
    )

    pkg = db.Package(package_id=1,
                     title="DummyPackage",
                     download_count=12,
                     latest_version="0.0.1")

    row.package = pkg

    return row
예제 #4
0
def test_delete_version(session):
    # Add additional dummy data.
    pkg = db.Package(name="Foo", latest_version="0.9.6")
    session.add(pkg)
    session.commit()

    session.add(db.Version(package_id=pkg.package_id, version="0.9.6"))
    session.add(db.Version(package_id=pkg.package_id, version="0.9.7"))
    session.commit()

    # The package we're interested in.
    pkg_id = 'dummy'

    # get our initial counts
    version_count = (session.query(sa.func.count(db.Version.version_id)).join(
        db.Package).filter(db.Package.name == pkg_id))
    package_count = session.query(sa.func.count(db.Package.package_id))
    initial_version_count = version_count.scalar()
    initial_package_count = package_count.scalar()

    db.delete_version(session, pkg_id, '0.0.2')

    # The number of versions for our package should have decreased by 1.
    assert initial_version_count - 1 == version_count.scalar()

    # We should still have 2 packages
    assert initial_package_count == 2
    assert initial_package_count == package_count.scalar()

    # The deleted version should not show up at all. (Note this particular
    # test only works because our dummy data only has 1 instance of "0.0.2")
    assert '0.0.2' not in session.query(db.Version.version).all()

    # Deleting the highest version should change the `latest_version` value
    qry = session.query(db.Package).filter(db.Package.name == 'dummy')
    db.delete_version(session, pkg_id, '0.0.3')
    assert qry.one().latest_version == '0.0.1'

    # Deleting the last version of a package should remove the row from the
    # Packages table.
    db.delete_version(session, pkg_id, '0.0.1')
    assert version_count.scalar() == 0
    assert package_count.scalar() == 1
예제 #5
0
def session():
    """
    Create a database session.
    """
    engine = sa.create_engine('sqlite:///:memory:')

    db.Base.metadata.create_all(engine)

    session = sa.orm.Session(bind=engine)

    # Add some dummy data
    pkg = db.Package(name="dummy", latest_version="0.0.3")
    session.add(pkg)
    session.commit()

    session.add(db.Version(package_id=pkg.package_id, version="0.0.1"))
    session.add(db.Version(package_id=pkg.package_id, version="0.0.2"))
    session.add(db.Version(package_id=pkg.package_id, version="0.0.3"))
    session.commit()

    return session
예제 #6
0
def test_count_packages(session):
    session.add(db.Package(name="pkg_2", latest_version="0.0.1"))
    session.commit()
    assert db.count_packages(session) == 2