def test_project_docs(db_session):
    projects = [ProjectFactory.create() for _ in range(2)]
    releases = {
        p: sorted(
            [ReleaseFactory.create(project=p) for _ in range(3)],
            key=lambda r: packaging.version.parse(r.version),
            reverse=True,
        )
        for p in projects
    }

    assert list(_project_docs(db_session)) == [
        {
            "_id": p.normalized_name,
            "_type": "project",
            "_source": {
                "created": p.created,
                "name": p.name,
                "normalized_name": p.normalized_name,
                "version": [r.version for r in prs],
                "uploader_name": prs[0].uploader.name,
                "uploader_username": prs[0].uploader.username,
            },
        }
        for p, prs in sorted(releases.items(), key=lambda x: x[0].name.lower())
    ]
Exemple #2
0
def test_project_docs(db_session):
    projects = [ProjectFactory.create() for _ in range(2)]
    releases = {
        p: sorted(
            [ReleaseFactory.create(project=p) for _ in range(3)],
            key=lambda r: packaging.version.parse(r.version),
            reverse=True,
        )
        for p in projects
    }

    assert list(_project_docs(db_session)) == [{
        "_id": p.normalized_name,
        "_type": "project",
        "_source": {
            "created":
            p.created,
            "name":
            p.name,
            "normalized_name":
            p.normalized_name,
            "version": [r.version for r in prs],
            "latest_version":
            first(
                prs,
                key=lambda r: not r.is_prerelease,
            ).version,
        },
    } for p, prs in sorted(releases.items(), key=lambda x: x[0].name.lower())]