feat(fastapi): add id="licenses" to package details licenses

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-11 19:55:04 -08:00
parent 7aa959150e
commit 686c032290
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
2 changed files with 17 additions and 1 deletions

View file

@ -64,7 +64,7 @@
</tr> </tr>
{% endif %} {% endif %}
{% if show_package_details and licenses and licenses.count() %} {% if show_package_details and licenses and licenses.count() %}
<tr> <tr id="licenses">
<th>{{ "Licenses" | tr }}:</th> <th>{{ "Licenses" | tr }}:</th>
<td>{{ licenses.all() | join(', ', attribute='License.Name') }} </td> <td>{{ licenses.all() | join(', ', attribute='License.Name') }} </td>
</tr> </tr>

View file

@ -11,6 +11,7 @@ from fastapi.testclient import TestClient
from sqlalchemy import and_ from sqlalchemy import and_
from aurweb import asgi, db, defaults from aurweb import asgi, db, defaults
from aurweb.models import License, PackageLicense
from aurweb.models.account_type import USER_ID, AccountType from aurweb.models.account_type import USER_ID, AccountType
from aurweb.models.dependency_type import DependencyType from aurweb.models.dependency_type import DependencyType
from aurweb.models.official_provider import OfficialProvider from aurweb.models.official_provider import OfficialProvider
@ -240,6 +241,17 @@ def test_package(client: TestClient, package: Package):
RelTypeID=CONFLICTS_ID, RelTypeID=CONFLICTS_ID,
RelName="test_conflict2") RelName="test_conflict2")
# Create some licenses.
licenses = [
db.create(License, Name="test_license1"),
db.create(License, Name="test_license2")
]
db.create(PackageLicense, PackageID=package.ID,
License=licenses[0])
db.create(PackageLicense, PackageID=package.ID,
License=licenses[1])
with client as request: with client as request:
resp = request.get(package_endpoint(package)) resp = request.get(package_endpoint(package))
assert resp.status_code == int(HTTPStatus.OK) assert resp.status_code == int(HTTPStatus.OK)
@ -260,6 +272,10 @@ def test_package(client: TestClient, package: Package):
pkgbase = row.find("./td/a") pkgbase = row.find("./td/a")
assert pkgbase.text.strip() == package.PackageBase.Name assert pkgbase.text.strip() == package.PackageBase.Name
licenses = root.xpath('//tr[@id="licenses"]/td')
expected = ["test_license1", "test_license2"]
assert licenses[0].text.strip() == ", ".join(expected)
provides = root.xpath('//tr[@id="provides"]/td') provides = root.xpath('//tr[@id="provides"]/td')
expected = ["test_provider1", "test_provider2"] expected = ["test_provider1", "test_provider2"]
assert provides[0].text.strip() == ", ".join(expected) assert provides[0].text.strip() == ", ".join(expected)