Skip to content

Commit

Permalink
Improvements, fix tests
Browse files Browse the repository at this point in the history
Co-authored-by: jonathan-d-zhang <[email protected]>
Signed-off-by: Bruno Rodrigues dos Santos <[email protected]>
  • Loading branch information
2 people authored and BruDriguezz committed Aug 24, 2024
1 parent 87c48f3 commit deba694
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/mainframe/endpoints/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,12 @@ def lookup_package_info(
query = query.where(Scan.finished_at >= dt.datetime.fromtimestamp(since, tz=dt.timezone.utc))

with session, session.begin():
log.info("Package info queried")
params = Params(page=page, size=size)
return paginate(
session, query, params=params, transformer=lambda items: [Package.from_db(item) for item in items]
)



def _deduplicate_packages(packages: list[PackageSpecifier], session: Session) -> set[tuple[str, str]]:
name_ver = {(p.name, p.version) for p in packages}
scalars = session.scalars(select(Scan).where(tuple_(Scan.name, Scan.version).in_(name_ver)))
Expand Down
8 changes: 4 additions & 4 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ def test_package_lookup(
test_data: list[Scan],
db_session: Session,
):
expected_scans = [
expected_scans = {
(scan.name, scan.version)
for scan in test_data
if (since is None or (scan.finished_at is not None and since <= int(scan.finished_at.timestamp())))
and (name is None or scan.name == name)
and (version is None or scan.version == version)
]
}

actual_scans = lookup_package_info(db_session, since, name, version, page, size)
assert set(expected_scans) == {(scan.name, scan.version) for scan in actual_scans.items}
assert expected_scans == {(scan.name, scan.version) for scan in actual_scans.items}


@pytest.mark.parametrize(
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_package_lookup_files(db_session: Session):
with db_session.begin():
db_session.add(scan)

package = lookup_package_info(db_session, name="abc", version="1.0.0")[0]
package = lookup_package_info(db_session, name="abc", version="1.0.0").items[0]

assert package.distributions == distros

Expand Down

0 comments on commit deba694

Please sign in to comment.