feat(fastapi): add Replaces field to package details

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-11 19:14:08 -08:00
parent 50a9690c2d
commit a33e9bd571
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
3 changed files with 25 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, PROVIDES_ID
from aurweb.models.relation_type import CONFLICTS_ID, PROVIDES_ID, REPLACES_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
@ -262,6 +262,10 @@ async def package(request: Request, name: str) -> Response:
models.PackageRelation.RelTypeID == PROVIDES_ID)
context["provides"] = provides
replaces = pkg.package_relations.filter(
models.PackageRelation.RelTypeID == REPLACES_ID)
context["replaces"] = replaces
return render_template(request, "packages/show.html", context)

View file

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

View file

@ -24,7 +24,7 @@ from aurweb.models.package_notification import PackageNotification
from aurweb.models.package_relation import PackageRelation
from aurweb.models.package_request import ACCEPTED_ID, REJECTED_ID, PackageRequest
from aurweb.models.package_vote import PackageVote
from aurweb.models.relation_type import PROVIDES_ID, RelationType
from aurweb.models.relation_type import PROVIDES_ID, REPLACES_ID, RelationType
from aurweb.models.request_type import DELETION_ID, MERGE_ID, RequestType
from aurweb.models.user import User
from aurweb.testing import setup_test_db
@ -226,6 +226,13 @@ def test_package(client: TestClient, package: Package):
RelTypeID=PROVIDES_ID,
RelName="test_provider2")
db.create(PackageRelation, PackageID=package.ID,
RelTypeID=REPLACES_ID,
RelName="test_replacer1")
db.create(PackageRelation, PackageID=package.ID,
RelTypeID=REPLACES_ID,
RelName="test_replacer2")
with client as request:
resp = request.get(package_endpoint(package))
assert resp.status_code == int(HTTPStatus.OK)
@ -250,6 +257,10 @@ def test_package(client: TestClient, package: Package):
expected = ["test_provider1", "test_provider2"]
assert provides[0].text.strip() == ", ".join(expected)
replaces = root.xpath('//tr[@id="replaces"]/td')
expected = ["test_replacer1", "test_replacer2"]
assert replaces[0].text.strip() == ", ".join(expected)
def test_package_comments(client: TestClient, user: User, package: Package):
now = (datetime.utcnow().timestamp())