fix(routers.packages): handle package source display

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-12-30 23:04:39 -08:00
parent be7a96076e
commit 8f8929f324
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
3 changed files with 66 additions and 4 deletions

View file

@ -5,12 +5,13 @@ import pytest
from fastapi import HTTPException
from fastapi.testclient import TestClient
from aurweb import asgi, db
from aurweb import asgi, config, db
from aurweb.models.account_type import USER_ID
from aurweb.models.official_provider import OFFICIAL_BASE, OfficialProvider
from aurweb.models.package import Package
from aurweb.models.package_base import PackageBase
from aurweb.models.package_notification import PackageNotification
from aurweb.models.package_source import PackageSource
from aurweb.models.package_vote import PackageVote
from aurweb.models.user import User
from aurweb.packages import util
@ -100,3 +101,36 @@ def test_query_notified(maintainer: User, package: Package):
def test_pkgreq_by_id_not_found():
with pytest.raises(HTTPException):
util.get_pkgreq_by_id(0)
def test_source_uri_file(package: Package):
FILE = "test_file"
with db.begin():
pkgsrc = db.create(PackageSource, Source=FILE,
Package=package, SourceArch="x86_64")
source_file_uri = config.get("options", "source_file_uri")
file, uri = util.source_uri(pkgsrc)
expected = source_file_uri % (pkgsrc.Source, package.PackageBase.Name)
assert (file, uri) == (FILE, expected)
def test_source_uri_named_uri(package: Package):
FILE = "test"
URL = "https://test.xyz"
with db.begin():
pkgsrc = db.create(PackageSource, Source=f"{FILE}::{URL}",
Package=package, SourceArch="x86_64")
file, uri = util.source_uri(pkgsrc)
assert (file, uri) == (FILE, URL)
def test_source_uri_unnamed_uri(package: Package):
URL = "https://test.xyz"
with db.begin():
pkgsrc = db.create(PackageSource, Source=f"{URL}",
Package=package, SourceArch="x86_64")
file, uri = util.source_uri(pkgsrc)
assert (file, uri) == (URL, URL)