コード例 #1
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
def test_get_project_versions(dbapp):
    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="2.0",
        _pypi_ordering=2,
    ))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="1.0",
        _pypi_ordering=1,
    ))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="3.0",
        _pypi_ordering=3,
    ))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="4.0",
        _pypi_ordering=4,
    ))

    assert dbapp.db.packaging.get_project_versions("test-project") == \
        ["4.0", "3.0", "2.0", "1.0"]
コード例 #2
0
def test_get_projects_for_user(dbapp):
    dbapp.engine.execute(users.insert().values(
        password="******",
        username="******",
        name="Test User",
        last_login=datetime.datetime.utcnow(),
        is_active=True,
        is_superuser=False,
        is_staff=False,
    ))
    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="1.0",
        summary="test summmary",
        _pypi_ordering=1,
    ))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="2.0",
        summary="test summmary 2.0",
        _pypi_ordering=2,
    ))
    dbapp.engine.execute(roles.insert().values(
        package_name="test-project",
        user_name="test-user",
        role_name="Owner",
    ))

    assert dbapp.models.packaging.get_projects_for_user("test-user") == [
        {
            "name": "test-project",
            "summary": "test summmary 2.0"
        },
    ]
コード例 #3
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
def test_get_projects_for_user(dbapp):
    dbapp.engine.execute(users.insert().values(
        password="******",
        username="******",
        name="Test User",
        last_login=datetime.datetime.utcnow(),
        is_active=True,
        is_superuser=False,
        is_staff=False,
    ))
    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="1.0",
        summary="test summmary",
        _pypi_ordering=1,
    ))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="2.0",
        summary="test summmary 2.0",
        _pypi_ordering=2,
    ))
    dbapp.engine.execute(roles.insert().values(
        package_name="test-project",
        user_name="test-user",
        role_name="Owner",
    ))

    assert dbapp.db.packaging.get_projects_for_user("test-user") == [
        {"name": "test-project", "summary": "test summmary 2.0"},
    ]
コード例 #4
0
def test_get_project_versions(dbapp):
    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="2.0",
        _pypi_ordering=2,
    ))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="1.0",
        _pypi_ordering=1,
    ))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="3.0",
        _pypi_ordering=3,
    ))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="4.0",
        _pypi_ordering=4,
    ))

    assert dbapp.models.packaging.get_project_versions("test-project") == \
        ["4.0", "3.0", "2.0", "1.0"]
コード例 #5
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
def test_get_full_latest_releases(dbapp):
    created = datetime.datetime.utcnow()

    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        created=created,
        name="test-project",
        version="1.0",
        author="John Doe",
        author_email="*****@*****.**",
        maintainer="Jane Doe",
        maintainer_email="*****@*****.**",
        home_page="https://example.com/",
        license="Apache License v2.0",
        summary="A Test Project",
        description="A Longer Test Project",
        keywords="foo,bar,wat",
        platform="All",
        download_url="https://example.com/downloads/test-project-1.0.tar.gz",
        _pypi_ordering=1,
    ))
    dbapp.engine.execute(releases.insert().values(
        created=created,
        name="test-project",
        version="2.0",
        author="John Doe",
        author_email="*****@*****.**",
        maintainer="Jane Doe",
        maintainer_email="*****@*****.**",
        home_page="https://example.com/",
        license="Apache License v2.0",
        summary="A Test Project",
        description="A Longer Test Project",
        keywords="foo,bar,wat",
        platform="All",
        download_url="https://example.com/downloads/test-project-1.0.tar.gz",
        _pypi_ordering=2,
    ))

    assert dbapp.db.packaging.get_full_latest_releases() == [
        {
            "created": created,
            "name": "test-project",
            "version": "2.0",
            "author": "John Doe",
            "author_email": "*****@*****.**",
            "maintainer": "Jane Doe",
            "maintainer_email": "*****@*****.**",
            "home_page": "https://example.com/",
            "license": "Apache License v2.0",
            "summary": "A Test Project",
            "description": "A Longer Test Project",
            "keywords": "foo,bar,wat",
            "platform": "All",
            "download_url": (
                "https://example.com/downloads/test-project-1.0.tar.gz"
            ),
        }
    ]
コード例 #6
0
def test_get_releases_since(dbapp):
    dbapp.engine.execute(packages.insert().values(name="foo1"))
    dbapp.engine.execute(packages.insert().values(name="foo2"))
    dbapp.engine.execute(packages.insert().values(name="foo3"))

    now = datetime.datetime.utcnow()

    dbapp.engine.execute(releases.insert().values(
        name="foo2",
        version="1.0",
        created=now - datetime.timedelta(seconds=10),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo3",
        version="2.0",
        created=now - datetime.timedelta(seconds=9),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo1",
        version="1.0",
        created=now - datetime.timedelta(seconds=4),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo3",
        version="1.0",
        created=now - datetime.timedelta(seconds=3),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo1",
        version="2.0",
        created=now,
    ))

    since = now - datetime.timedelta(seconds=5)
    assert dbapp.models.packaging.get_releases_since(since) == [
        {
            "name": "foo1",
            "version": "2.0",
            "summary": None,
            "created": now,
        },
        {
            "name": "foo3",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=3),
        },
        {
            "name": "foo1",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=4),
        },
    ]
コード例 #7
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
def test_get_releases_since(dbapp):
    dbapp.engine.execute(packages.insert().values(name="foo1"))
    dbapp.engine.execute(packages.insert().values(name="foo2"))
    dbapp.engine.execute(packages.insert().values(name="foo3"))

    now = datetime.datetime.utcnow()

    dbapp.engine.execute(releases.insert().values(
        name="foo2", version="1.0",
        created=now - datetime.timedelta(seconds=10),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo3", version="2.0",
        created=now - datetime.timedelta(seconds=9),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo1", version="1.0",
        created=now - datetime.timedelta(seconds=4),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo3", version="1.0",
        created=now - datetime.timedelta(seconds=3),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo1", version="2.0", created=now,
    ))

    since = now - datetime.timedelta(seconds=5)
    assert dbapp.db.packaging.get_releases_since(since) == [
        {
            "name": "foo1",
            "version": "2.0",
            "summary": None,
            "created": now,
        },
        {
            "name": "foo3",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=3),
        },
        {
            "name": "foo1",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=4),
        },
    ]
コード例 #8
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
 def add_project(name, classifiers):
     dbapp.engine.execute(packages.insert().values(name=name))
     dbapp.engine.execute(releases.insert().values(name=name, version="1"))
     for trove_id in classifiers:
         dbapp.engine.execute(release_classifiers.insert().values(
             name=name,
             version="1",
             trove_id=trove_id,
         ))
コード例 #9
0
def test_get_release_urls(name, attrs, dbapp):
    # prepare database
    dbapp.engine.execute(packages.insert().values(name=name))
    for data in attrs:
        dbapp.engine.execute(releases.insert().values(name=name, **data))

    assert dbapp.models.packaging.get_release_urls(name) == {
        a["version"]: (a.get("home_page"), a.get("download_url")) for a in attrs
    }
コード例 #10
0
 def add_project(name, classifiers):
     dbapp.engine.execute(packages.insert().values(name=name))
     dbapp.engine.execute(releases.insert().values(name=name, version="1"))
     for trove_id in classifiers:
         dbapp.engine.execute(release_classifiers.insert().values(
             name=name,
             version="1",
             trove_id=trove_id,
         ))
コード例 #11
0
def test_get_downloads(pgp, dbapp, monkeypatch):
    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="1.0",
    ))
    dbapp.engine.execute(release_files.insert().values(
        name="test-project",
        version="1.0",
        filename="test-project-1.0.tar.gz",
        python_version="source",
        packagetype="sdist",
        md5_digest="0cc175b9c0f1b6a831c399e269772661",
        downloads=10,
        upload_time=datetime.datetime(year=2013, month=1, day=30),
    ))

    def os_exists():
        yield  # start
        yield True  # whether download file exists
        yield pgp  # whether .asc pgp file exists

    f = os_exists().send
    f(None)  # start it off
    os_exists = pretend.call_recorder(f)

    monkeypatch.setattr(os.path, "exists", os_exists)
    monkeypatch.setattr(os.path, "getsize", lambda x: 10)

    dbapp.config.paths.packages = "fake"

    downloads = dbapp.models.packaging.get_downloads("test-project", "1.0")

    pgp_url = "/packages/source/t/test-project/test-project-1.0.tar.gz.asc"

    assert downloads == [
        {
            "name": "test-project",
            "version": "1.0",
            "filename": "test-project-1.0.tar.gz",
            "filepath": "fake/source/t/test-project/test-project-1.0.tar.gz",
            "comment_text": None,
            "downloads": 10,
            "upload_time": datetime.datetime(year=2013, month=1, day=30),
            "python_version": "source",
            "md5_digest": "0cc175b9c0f1b6a831c399e269772661",
            "url": "/packages/source/t/test-project/test-project-1.0.tar.gz",
            "packagetype": "sdist",
            "size": 10,
            "pgp_url": pgp_url if pgp else None,
        },
    ]
    assert os_exists.calls == [
        pretend.call(downloads[0]["filepath"]),
        pretend.call(downloads[0]["filepath"] + ".asc")
    ]
コード例 #12
0
def test_get_release_urls(name, attrs, dbapp):
    # prepare database
    dbapp.engine.execute(packages.insert().values(name=name))
    for data in attrs:
        dbapp.engine.execute(releases.insert().values(name=name, **data))

    assert dbapp.models.packaging.get_release_urls(name) == {
        a["version"]: (a.get("home_page"), a.get("download_url"))
        for a in attrs
    }
コード例 #13
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
def test_get_downloads(pgp, dbapp, monkeypatch):
    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="1.0",
    ))
    dbapp.engine.execute(release_files.insert().values(
        name="test-project",
        version="1.0",
        filename="test-project-1.0.tar.gz",
        python_version="source",
        packagetype="sdist",
        md5_digest="0cc175b9c0f1b6a831c399e269772661",
        downloads=10,
        upload_time=datetime.datetime(year=2013, month=1, day=30),
    ))

    def os_exists():
        yield       # start
        yield True  # whether download file exists
        yield pgp   # whether .asc pgp file exists
    f = os_exists().send
    f(None)     # start it off
    os_exists = pretend.call_recorder(f)

    monkeypatch.setattr(os.path, "exists", os_exists)
    monkeypatch.setattr(os.path, "getsize", lambda x: 10)

    dbapp.config.paths.packages = "fake"

    downloads = dbapp.db.packaging.get_downloads("test-project", "1.0")

    pgp_url = "/packages/source/t/test-project/test-project-1.0.tar.gz.asc"

    assert downloads == [
        {
            "name": "test-project",
            "version": "1.0",
            "filename": "test-project-1.0.tar.gz",
            "filepath": "fake/source/t/test-project/test-project-1.0.tar.gz",
            "comment_text": None,
            "downloads": 10,
            "upload_time": datetime.datetime(year=2013, month=1, day=30),
            "python_version": "source",
            "md5_digest": "0cc175b9c0f1b6a831c399e269772661",
            "url": "/packages/source/t/test-project/test-project-1.0.tar.gz",
            "packagetype": "sdist",
            "size": 10,
            "pgp_url": pgp_url if pgp else None,
        },
    ]
    assert os_exists.calls == [
        pretend.call(downloads[0]["filepath"]),
        pretend.call(downloads[0]["filepath"] + ".asc")
    ]
コード例 #14
0
 def release(name, version, delta):
     dbapp.engine.execute(releases.insert().values(name=name,
                                                   version=version,
                                                   created=now - delta))
     dbapp.engine.execute(journals.insert().values(id=create.id,
                                                   name=name,
                                                   version=version,
                                                   submitted_date=now -
                                                   delta,
                                                   action="new release"))
     create.id += 1
コード例 #15
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
 def release(name, version, delta):
     dbapp.engine.execute(releases.insert().values(
         name=name,
         version=version,
         created=now - delta,
     ))
     dbapp.engine.execute(journals.insert().values(
         id=create.id,
         name=name,
         version=version,
         submitted_date=now - delta,
         action="new release",
     ))
     create.id += 1
コード例 #16
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
def test_get_recent_projects(dbapp):
    def create_package(name, version, ordering, created):
        dbapp.engine.execute(packages.insert().values(
            name=name, created=created))
        dbapp.engine.execute(releases.insert().values(
            name=name, version=version, _pypi_ordering=ordering,
            created=created))

    now = datetime.datetime.utcnow()
    create_package("foo1", "2.0", 2, now)
    create_package("foo2", "1.0", 1, now - datetime.timedelta(seconds=45))
    create_package("foo3", "1.0", 1, now - datetime.timedelta(seconds=15))
    create_package("foo4", "1.0", 1, now - datetime.timedelta(seconds=40))
    create_package("foo5", "1.0", 1, now - datetime.timedelta(seconds=25))
    create_package("foo6", "1.0", 1, now - datetime.timedelta(seconds=30))
    create_package("foo7", "1.0", 1, now - datetime.timedelta(seconds=35))

    dbapp.engine.execute(releases.insert().values(
        name="foo1", version="1.0", _pypi_ordering=1,
        created=now - datetime.timedelta(seconds=5),
    ))

    assert dbapp.db.packaging.get_recent_projects(num=4) == [
        {
            "name": "foo1",
            "version": "2.0",
            "summary": None,
            "created": now,
        },
        {
            "name": "foo3",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=15),
        },
        {
            "name": "foo5",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=25),
        },
        {
            "name": "foo6",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=30),
        },
    ]
コード例 #17
0
def test_get_download_count(dbapp):
    dbapp.engine.execute(packages.insert().values(name="foo"))
    dbapp.engine.execute(releases.insert().values(name="foo", version="1.0"))
    dbapp.engine.execute(release_files.insert().values(
        name="foo",
        version="1.0",
        filename="foo-1.0.tar.gz",
        downloads=15,
    ))
    dbapp.engine.execute(release_files.insert().values(
        name="foo",
        version="1.0",
        filename="foo-1.0.tar.bz2",
        downloads=12,
    ))

    assert dbapp.models.packaging.get_download_count() == 27
コード例 #18
0
ファイル: test_models.py プロジェクト: mattrobenolt/warehouse
def test_get_download_count(dbapp):
    dbapp.engine.execute(packages.insert().values(name="foo"))
    dbapp.engine.execute(releases.insert().values(name="foo", version="1.0"))
    dbapp.engine.execute(release_files.insert().values(
        name="foo",
        version="1.0",
        filename="foo-1.0.tar.gz",
        downloads=15,
    ))
    dbapp.engine.execute(release_files.insert().values(
        name="foo",
        version="1.0",
        filename="foo-1.0.tar.bz2",
        downloads=12,
    ))

    assert dbapp.models.packaging.get_download_count() == 27
コード例 #19
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
def test_get_downloads_missing(dbapp, monkeypatch):
    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="1.0",
    ))
    dbapp.engine.execute(release_files.insert().values(
        name="test-project",
        version="1.0",
        filename="test-project-1.0.tar.gz",
        python_version="source",
        packagetype="sdist",
        md5_digest="0cc175b9c0f1b6a831c399e269772661",
        downloads=10,
        upload_time=datetime.datetime(year=2013, month=1, day=30),
    ))

    # file does not exist
    os_exists = pretend.call_recorder(lambda p: False)

    # we match the specific arguments below - no need forcing them here as well
    log_error = pretend.call_recorder(lambda *a: None)

    monkeypatch.setattr(os.path, "exists", os_exists)
    # log from warehouse.packaging.db
    monkeypatch.setattr(log, "error", log_error)

    dbapp.config.paths.packages = "fake"

    downloads = dbapp.db.packaging.get_downloads("test-project", "1.0")

    assert downloads == []
    filepath = "fake/source/t/test-project/test-project-1.0.tar.gz"
    assert os_exists.calls == [pretend.call(filepath)]

    # actual error message may vary, so just assert that the logging was called
    assert log_error.calls == [
        pretend.call(
            "%s missing for package %s %s",
            filepath,
            "test-project",
            "1.0",
        ),
    ]
コード例 #20
0
def test_get_downloads_missing(dbapp, monkeypatch):
    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="1.0",
    ))
    dbapp.engine.execute(release_files.insert().values(
        name="test-project",
        version="1.0",
        filename="test-project-1.0.tar.gz",
        python_version="source",
        packagetype="sdist",
        md5_digest="0cc175b9c0f1b6a831c399e269772661",
        downloads=10,
        upload_time=datetime.datetime(year=2013, month=1, day=30),
    ))

    # file does not exist
    os_exists = pretend.call_recorder(lambda p: False)

    # we match the specific arguments below - no need forcing them here as well
    log_error = pretend.call_recorder(lambda *a: None)

    monkeypatch.setattr(os.path, "exists", os_exists)
    # log from warehouse.packaging.models
    monkeypatch.setattr(log, "error", log_error)

    dbapp.config.paths.packages = "fake"

    downloads = dbapp.models.packaging.get_downloads("test-project", "1.0")

    assert downloads == []
    filepath = "fake/source/t/test-project/test-project-1.0.tar.gz"
    assert os_exists.calls == [pretend.call(filepath)]

    # actual error message may vary, so just assert that the logging was called
    assert log_error.calls == [
        pretend.call(
            "%s missing for package %s %s",
            filepath,
            "test-project",
            "1.0",
        ),
    ]
コード例 #21
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
def test_get_classifiers(dbapp):
    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="1.0",
    ))
    dbapp.engine.execute(classifiers.insert().values(
        id=1,
        classifier="Test :: Classifier",
    ))
    dbapp.engine.execute(release_classifiers.insert().values(
        name="test-project",
        version="1.0",
        trove_id=1,
    ))

    test_classifiers = dbapp.db.packaging.get_classifiers(
        "test-project",
        "1.0",
    )

    assert test_classifiers == ["Test :: Classifier"]
コード例 #22
0
def test_get_classifiers(dbapp):
    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        name="test-project",
        version="1.0",
    ))
    dbapp.engine.execute(classifiers.insert().values(
        id=1,
        classifier="Test :: Classifier",
    ))
    dbapp.engine.execute(release_classifiers.insert().values(
        name="test-project",
        version="1.0",
        trove_id=1,
    ))

    test_classifiers = dbapp.models.packaging.get_classifiers(
        "test-project",
        "1.0",
    )

    assert test_classifiers == ["Test :: Classifier"]
コード例 #23
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
def test_get_release(dbapp):
    created = datetime.datetime.utcnow()

    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        created=created,
        name="test-project",
        version="1.0",
        author="John Doe",
        author_email="*****@*****.**",
        maintainer="Jane Doe",
        maintainer_email="*****@*****.**",
        home_page="https://example.com/",
        license="Apache License v2.0",
        summary="A Test Project",
        description="A Longer Test Project",
        keywords="foo,bar,wat",
        platform="All",
        download_url="https://example.com/downloads/test-project-1.0.tar.gz",
        _pypi_ordering=1,
    ))
    dbapp.engine.execute(releases.insert().values(
        created=created,
        name="test-project",
        version="2.0",
        author="John Doe",
        author_email="*****@*****.**",
        maintainer="Jane Doe",
        maintainer_email="*****@*****.**",
        home_page="https://example.com/",
        license="Apache License v2.0",
        summary="A Test Project",
        description="A Longer Test Project",
        keywords="foo,bar,wat",
        platform="All",
        download_url="https://example.com/downloads/test-project-1.0.tar.gz",
        _pypi_ordering=2,
    ))
    dbapp.engine.execute(release_dependencies.insert().values(
        name="test-project",
        version="1.0",
        kind=4,
        specifier="requests (>=2.0)",
    ))
    dbapp.engine.execute(release_dependencies.insert().values(
        name="test-project",
        version="2.0",
        kind=4,
        specifier="requests (>=2.0)",
    ))
    dbapp.engine.execute(release_dependencies.insert().values(
        name="test-project",
        version="1.0",
        kind=5,
        specifier="test-project-old",
    ))
    dbapp.engine.execute(release_dependencies.insert().values(
        name="test-project",
        version="2.0",
        kind=5,
        specifier="test-project-old",
    ))
    dbapp.engine.execute(release_dependencies.insert().values(
        name="test-project",
        version="1.0",
        kind=8,
        specifier="Repository,git://git.example.com/",
    ))
    dbapp.engine.execute(release_dependencies.insert().values(
        name="test-project",
        version="2.0",
        kind=8,
        specifier="Repository,git://git.example.com/",
    ))

    test_release = dbapp.db.packaging.get_release("test-project", "1.0")

    assert test_release == {
        "name": "test-project",
        "version": "1.0",
        "author": "John Doe",
        "author_email": "*****@*****.**",
        "maintainer": "Jane Doe",
        "maintainer_email": "*****@*****.**",
        "home_page": "https://example.com/",
        "license": "Apache License v2.0",
        "summary": "A Test Project",
        "description": "A Longer Test Project",
        "keywords": "foo,bar,wat",
        "platform": "All",
        "download_url": ("https://example.com/downloads/"
                         "test-project-1.0.tar.gz"),
        "requires_dist": ["requests (>=2.0)"],
        "provides_dist": ["test-project-old"],
        "project_url": {"Repository": "git://git.example.com/"},
        "created": created,
    }
コード例 #24
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
def test_get_recently_updated(dbapp):
    dbapp.engine.execute(packages.insert().values(name="foo1"))
    dbapp.engine.execute(packages.insert().values(name="foo2"))
    dbapp.engine.execute(packages.insert().values(name="foo3"))
    dbapp.engine.execute(packages.insert().values(name="foo4"))
    dbapp.engine.execute(packages.insert().values(name="foo5"))
    dbapp.engine.execute(packages.insert().values(name="foo6"))
    dbapp.engine.execute(packages.insert().values(name="foo7"))
    dbapp.engine.execute(packages.insert().values(name="foo8"))
    dbapp.engine.execute(packages.insert().values(name="foo9"))
    dbapp.engine.execute(packages.insert().values(name="foo10"))
    dbapp.engine.execute(packages.insert().values(name="foo11"))
    dbapp.engine.execute(packages.insert().values(name="foo12"))

    now = datetime.datetime.utcnow()

    dbapp.engine.execute(releases.insert().values(
        name="foo1", version="2.0", created=now,
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo1", version="1.0",
        created=now - datetime.timedelta(seconds=5),
    ))

    dbapp.engine.execute(releases.insert().values(
        name="foo2", version="1.0",
        created=now - datetime.timedelta(seconds=10),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo3", version="1.0",
        created=now - datetime.timedelta(seconds=15),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo4", version="1.0",
        created=now - datetime.timedelta(seconds=20),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo5", version="1.0",
        created=now - datetime.timedelta(seconds=25),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo6", version="1.0",
        created=now - datetime.timedelta(seconds=30),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo7", version="1.0",
        created=now - datetime.timedelta(seconds=35),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo8", version="1.0",
        created=now - datetime.timedelta(seconds=40),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo9", version="1.0",
        created=now - datetime.timedelta(seconds=45),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo10", version="1.0",
        created=now - datetime.timedelta(seconds=50),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo11", version="1.0",
        created=now - datetime.timedelta(seconds=55),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo12", version="1.0",
        created=now - datetime.timedelta(seconds=60),
    ))

    assert dbapp.db.packaging.get_recently_updated() == [
        {
            "name": "foo1",
            "version": "2.0",
            "summary": None,
            "created": now,
        },
        {
            "name": "foo2",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=10),
        },
        {
            "name": "foo3",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=15),
        },
        {
            "name": "foo4",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=20),
        },
        {
            "name": "foo5",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=25),
        },
        {
            "name": "foo6",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=30),
        },
        {
            "name": "foo7",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=35),
        },
        {
            "name": "foo8",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=40),
        },
        {
            "name": "foo9",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=45),
        },
        {
            "name": "foo10",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=50),
        },
    ]
コード例 #25
0
def test_get_recently_updated(dbapp):
    dbapp.engine.execute(packages.insert().values(name="foo1"))
    dbapp.engine.execute(packages.insert().values(name="foo2"))
    dbapp.engine.execute(packages.insert().values(name="foo3"))
    dbapp.engine.execute(packages.insert().values(name="foo4"))
    dbapp.engine.execute(packages.insert().values(name="foo5"))
    dbapp.engine.execute(packages.insert().values(name="foo6"))
    dbapp.engine.execute(packages.insert().values(name="foo7"))
    dbapp.engine.execute(packages.insert().values(name="foo8"))
    dbapp.engine.execute(packages.insert().values(name="foo9"))
    dbapp.engine.execute(packages.insert().values(name="foo10"))
    dbapp.engine.execute(packages.insert().values(name="foo11"))
    dbapp.engine.execute(packages.insert().values(name="foo12"))

    now = datetime.datetime.utcnow()

    dbapp.engine.execute(releases.insert().values(
        name="foo1",
        version="2.0",
        created=now,
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo1",
        version="1.0",
        created=now - datetime.timedelta(seconds=5),
    ))

    dbapp.engine.execute(releases.insert().values(
        name="foo2",
        version="1.0",
        created=now - datetime.timedelta(seconds=10),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo3",
        version="1.0",
        created=now - datetime.timedelta(seconds=15),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo4",
        version="1.0",
        created=now - datetime.timedelta(seconds=20),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo5",
        version="1.0",
        created=now - datetime.timedelta(seconds=25),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo6",
        version="1.0",
        created=now - datetime.timedelta(seconds=30),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo7",
        version="1.0",
        created=now - datetime.timedelta(seconds=35),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo8",
        version="1.0",
        created=now - datetime.timedelta(seconds=40),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo9",
        version="1.0",
        created=now - datetime.timedelta(seconds=45),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo10",
        version="1.0",
        created=now - datetime.timedelta(seconds=50),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo11",
        version="1.0",
        created=now - datetime.timedelta(seconds=55),
    ))
    dbapp.engine.execute(releases.insert().values(
        name="foo12",
        version="1.0",
        created=now - datetime.timedelta(seconds=60),
    ))

    assert dbapp.models.packaging.get_recently_updated() == [
        {
            "name": "foo1",
            "version": "2.0",
            "summary": None,
            "created": now,
        },
        {
            "name": "foo2",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=10),
        },
        {
            "name": "foo3",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=15),
        },
        {
            "name": "foo4",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=20),
        },
        {
            "name": "foo5",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=25),
        },
        {
            "name": "foo6",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=30),
        },
        {
            "name": "foo7",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=35),
        },
        {
            "name": "foo8",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=40),
        },
        {
            "name": "foo9",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=45),
        },
        {
            "name": "foo10",
            "version": "1.0",
            "summary": None,
            "created": now - datetime.timedelta(seconds=50),
        },
    ]
コード例 #26
0
def test_get_release(dbapp):
    created = datetime.datetime.utcnow()

    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        created=created,
        name="test-project",
        version="1.0",
        author="John Doe",
        author_email="*****@*****.**",
        maintainer="Jane Doe",
        maintainer_email="*****@*****.**",
        home_page="https://example.com/",
        license="Apache License v2.0",
        summary="A Test Project",
        description="A Longer Test Project",
        keywords="foo,bar,wat",
        platform="All",
        download_url="https://example.com/downloads/test-project-1.0.tar.gz",
        _pypi_ordering=1,
    ))
    dbapp.engine.execute(releases.insert().values(
        created=created,
        name="test-project",
        version="2.0",
        author="John Doe",
        author_email="*****@*****.**",
        maintainer="Jane Doe",
        maintainer_email="*****@*****.**",
        home_page="https://example.com/",
        license="Apache License v2.0",
        summary="A Test Project",
        description="A Longer Test Project",
        keywords="foo,bar,wat",
        platform="All",
        download_url="https://example.com/downloads/test-project-1.0.tar.gz",
        _pypi_ordering=2,
    ))
    dbapp.engine.execute(release_dependencies.insert().values(
        name="test-project",
        version="1.0",
        kind=4,
        specifier="requests (>=2.0)",
    ))
    dbapp.engine.execute(release_dependencies.insert().values(
        name="test-project",
        version="2.0",
        kind=4,
        specifier="requests (>=2.0)",
    ))
    dbapp.engine.execute(release_dependencies.insert().values(
        name="test-project",
        version="1.0",
        kind=5,
        specifier="test-project-old",
    ))
    dbapp.engine.execute(release_dependencies.insert().values(
        name="test-project",
        version="2.0",
        kind=5,
        specifier="test-project-old",
    ))
    dbapp.engine.execute(release_dependencies.insert().values(
        name="test-project",
        version="1.0",
        kind=8,
        specifier="Repository,git://git.example.com/",
    ))
    dbapp.engine.execute(release_dependencies.insert().values(
        name="test-project",
        version="2.0",
        kind=8,
        specifier="Repository,git://git.example.com/",
    ))

    test_release = dbapp.models.packaging.get_release("test-project", "1.0")

    assert test_release == {
        "name":
        "test-project",
        "version":
        "1.0",
        "author":
        "John Doe",
        "author_email":
        "*****@*****.**",
        "maintainer":
        "Jane Doe",
        "maintainer_email":
        "*****@*****.**",
        "home_page":
        "https://example.com/",
        "license":
        "Apache License v2.0",
        "summary":
        "A Test Project",
        "description":
        "A Longer Test Project",
        "keywords":
        "foo,bar,wat",
        "platform":
        "All",
        "download_url": ("https://example.com/downloads/"
                         "test-project-1.0.tar.gz"),
        "requires_dist": ["requests (>=2.0)"],
        "provides_dist": ["test-project-old"],
        "project_url": {
            "Repository": "git://git.example.com/"
        },
        "created":
        created,
    }
コード例 #27
0
def test_get_full_latest_releases(dbapp):
    created = datetime.datetime.utcnow()

    dbapp.engine.execute(packages.insert().values(name="test-project"))
    dbapp.engine.execute(releases.insert().values(
        created=created,
        name="test-project",
        version="1.0",
        author="John Doe",
        author_email="*****@*****.**",
        maintainer="Jane Doe",
        maintainer_email="*****@*****.**",
        home_page="https://example.com/",
        license="Apache License v2.0",
        summary="A Test Project",
        description="A Longer Test Project",
        keywords="foo,bar,wat",
        platform="All",
        download_url="https://example.com/downloads/test-project-1.0.tar.gz",
        _pypi_ordering=1,
    ))
    dbapp.engine.execute(releases.insert().values(
        created=created,
        name="test-project",
        version="2.0",
        author="John Doe",
        author_email="*****@*****.**",
        maintainer="Jane Doe",
        maintainer_email="*****@*****.**",
        home_page="https://example.com/",
        license="Apache License v2.0",
        summary="A Test Project",
        description="A Longer Test Project",
        keywords="foo,bar,wat",
        platform="All",
        download_url="https://example.com/downloads/test-project-1.0.tar.gz",
        _pypi_ordering=2,
    ))

    assert dbapp.models.packaging.get_full_latest_releases() == [{
        "created":
        created,
        "name":
        "test-project",
        "version":
        "2.0",
        "author":
        "John Doe",
        "author_email":
        "*****@*****.**",
        "maintainer":
        "Jane Doe",
        "maintainer_email":
        "*****@*****.**",
        "home_page":
        "https://example.com/",
        "license":
        "Apache License v2.0",
        "summary":
        "A Test Project",
        "description":
        "A Longer Test Project",
        "keywords":
        "foo,bar,wat",
        "platform":
        "All",
        "download_url":
        ("https://example.com/downloads/test-project-1.0.tar.gz"),
    }]
コード例 #28
0
ファイル: test_db.py プロジェクト: b-jazz/warehouse
 def create_package(name, version, ordering, created):
     dbapp.engine.execute(packages.insert().values(
         name=name, created=created))
     dbapp.engine.execute(releases.insert().values(
         name=name, version=version, _pypi_ordering=ordering,
         created=created))
コード例 #29
0
ファイル: db.py プロジェクト: AaronLaw/warehouse
    def upsert_release(self, project_name, version, username, user_ip,
                       classifiers=None, release_dependencies=None,
                       description=None, **additional_db_values):
        """
        Takes in the following:

        * project_name: the name of the package to insert
        * version: the version of the package to insert
        * username: username of the user upserting the package
        * user_ip: ip address of the user upserting the package
        * classifiers: a list of the classifiers to classify the release with
        * release_dependencies: a dictionary of
            'ReleaseDependencyKind.value: [specifier]' pairs.
        * description: a restructured text description of the release/project
        * additional_db_values: any other column in the release table,
            as specified by get_settable_release_columns

        and inserts the release (if one doesn't exist), or updates otherwise
        """
        is_update = self.get_release(project_name, version) is not None
        modified_elements = list(additional_db_values.keys())

        db.validate_argument_column_mapping(
            additional_db_values,
            releases,
            blacklist=['name', 'version', 'description', 'description_html',
                       '_pypi_ordering', '_pypi_hidden']
        )

        if not is_update:
            additional_db_values['name'] = project_name
            additional_db_values['version'] = version

        if description:
            modified_elements += ['description', 'description_html']
            additional_db_values['description'] = description
            additional_db_values['description_html'] = \
                readme.rst.render(description)[0]

        if len(additional_db_values) > 0:
            if is_update:
                self.engine.execute(
                    releases
                    .update()
                    .where(releases.columns.name == project_name)
                    .where(releases.columns.version == version)
                    .values(**additional_db_values)
                )
            else:
                self.engine.execute(
                    releases.insert().values(**additional_db_values)
                )

        # external tables

        # this is legacy behavior. According to PEP-438, we should
        # no longer support parsing urls from descriptions
        hosting_mode = self.get_hosting_mode(project_name)
        if hosting_mode in ('pypi-scrape-crawl', 'pypi-scrape') \
           and 'description_html' in additional_db_values:

            self.update_release_external_urls(
                project_name, version,
                utils.find_links_from_html(
                    additional_db_values['description_html']
                )
            )

        if classifiers:
            modified_elements.append('classifiers')
            self.update_release_classifiers(project_name, version,
                                            classifiers)

        if release_dependencies:
            self.update_release_dependencies(project_name, version,
                                             release_dependencies)

        if is_update:
            journal_message = 'update {0}'.format(','.join(modified_elements))
        else:
            journal_message = "new release"

        self._insert_journal_entry(project_name, version, journal_message,
                                   username, user_ip)

        # insert specific actions

        if not is_update:
            self._update_release_ordering(project_name)
コード例 #30
0
ファイル: db.py プロジェクト: DalavanCloud/warehouse
    def upsert_release(self,
                       project_name,
                       version,
                       username,
                       user_ip,
                       classifiers=None,
                       release_dependencies=None,
                       description=None,
                       **additional_db_values):
        """
        Takes in the following:

        * project_name: the name of the package to insert
        * version: the version of the package to insert
        * username: username of the user upserting the package
        * user_ip: ip address of the user upserting the package
        * classifiers: a list of the classifiers to classify the release with
        * release_dependencies: a dictionary of
            'ReleaseDependencyKind.value: [specifier]' pairs.
        * description: a restructured text description of the release/project
        * additional_db_values: any other column in the release table,
            as specified by get_settable_release_columns

        and inserts the release (if one doesn't exist), or updates otherwise
        """
        is_update = self.get_release(project_name, version) is not None
        modified_elements = list(additional_db_values.keys())

        db.validate_argument_column_mapping(additional_db_values,
                                            releases,
                                            blacklist=[
                                                'name', 'version',
                                                'description',
                                                'description_html',
                                                '_pypi_ordering',
                                                '_pypi_hidden'
                                            ])

        if not is_update:
            additional_db_values['name'] = project_name
            additional_db_values['version'] = version

        if description:
            modified_elements += ['description', 'description_html']
            additional_db_values['description'] = description
            additional_db_values['description_html'] = \
                readme.rst.render(description)[0]

        if len(additional_db_values) > 0:
            if is_update:
                self.engine.execute(releases.update().where(
                    releases.columns.name == project_name).where(
                        releases.columns.version == version).values(
                            **additional_db_values))
            else:
                self.engine.execute(
                    releases.insert().values(**additional_db_values))

        # external tables

        # this is legacy behavior. According to PEP-438, we should
        # no longer support parsing urls from descriptions
        hosting_mode = self.get_hosting_mode(project_name)
        if hosting_mode in ('pypi-scrape-crawl', 'pypi-scrape') \
           and 'description_html' in additional_db_values:

            self.update_release_external_urls(
                project_name, version,
                utils.find_links_from_html(
                    additional_db_values['description_html']))

        if classifiers:
            modified_elements.append('classifiers')
            self.update_release_classifiers(project_name, version, classifiers)

        if release_dependencies:
            self.update_release_dependencies(project_name, version,
                                             release_dependencies)

        if is_update:
            journal_message = 'update {0}'.format(','.join(modified_elements))
        else:
            journal_message = "new release"

        self._insert_journal_entry(project_name, version, journal_message,
                                   username, user_ip)

        # insert specific actions

        if not is_update:
            self._update_release_ordering(project_name)