feat(fastapi): add Provides field in package details

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-11 19:09:24 -08:00
parent 2016b80ea9
commit 50a9690c2d
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
3 changed files with 26 additions and 2 deletions

View file

@ -12,7 +12,7 @@ import aurweb.packages.util
from aurweb import db, defaults, l10n, logging, models, util
from aurweb.auth import auth_required
from aurweb.models.package_request import ACCEPTED_ID, PENDING_ID, REJECTED_ID
from aurweb.models.relation_type import CONFLICTS_ID
from aurweb.models.relation_type import CONFLICTS_ID, PROVIDES_ID
from aurweb.models.request_type import DELETION_ID, MERGE, MERGE_ID
from aurweb.packages.search import PackageSearch
from aurweb.packages.util import get_pkg_or_base, get_pkgbase_comment, query_notified, query_voted
@ -258,6 +258,10 @@ async def package(request: Request, name: str) -> Response:
)
context["conflicts"] = conflicts
provides = pkg.package_relations.filter(
models.PackageRelation.RelTypeID == PROVIDES_ID)
context["provides"] = provides
return render_template(request, "packages/show.html", context)

View file

@ -77,6 +77,14 @@
</td>
</tr>
{% endif %}
{% if show_package_details and provides and provides.count() %}
<tr id="provides">
<th>{{ "Provides" | tr }}:</th>
<td class="wrap">
{{ provides.all() | join(', ', attribute='RelName') }}
</td>
</tr>
{% endif %}
<tr>
<th>{{ "Submitter" | tr }}:</th>
<td>

View file

@ -217,8 +217,16 @@ def test_package_official_not_found(client: TestClient, package: Package):
def test_package(client: TestClient, package: Package):
""" Test a single / packages / {name} route. """
with client as request:
with db.begin():
db.create(PackageRelation, PackageID=package.ID,
RelTypeID=PROVIDES_ID,
RelName="test_provider1")
db.create(PackageRelation, PackageID=package.ID,
RelTypeID=PROVIDES_ID,
RelName="test_provider2")
with client as request:
resp = request.get(package_endpoint(package))
assert resp.status_code == int(HTTPStatus.OK)
@ -238,6 +246,10 @@ def test_package(client: TestClient, package: Package):
pkgbase = row.find("./td/a")
assert pkgbase.text.strip() == package.PackageBase.Name
provides = root.xpath('//tr[@id="provides"]/td')
expected = ["test_provider1", "test_provider2"]
assert provides[0].text.strip() == ", ".join(expected)
def test_package_comments(client: TestClient, user: User, package: Package):
now = (datetime.utcnow().timestamp())