From 62f0680683e3a086c660d5880041b6a3cea02e42 Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Mon, 7 Oct 2024 11:51:59 +0200 Subject: [PATCH] frontend: support build-time dependencies from other storages Fix #3446 When a Copr defines a build-time dependency on `copr://foo/bar` and the `foo/bar` project uses Pulp storage, the repository baseurl is now generated correctly. --- frontend/coprs_frontend/coprs/repos.py | 14 +++++++++---- frontend/coprs_frontend/tests/test_repos.py | 22 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/frontend/coprs_frontend/coprs/repos.py b/frontend/coprs_frontend/coprs/repos.py index ec9c03477..7185bb666 100644 --- a/frontend/coprs_frontend/coprs/repos.py +++ b/frontend/coprs_frontend/coprs/repos.py @@ -7,7 +7,9 @@ import posixpath from urllib.parse import urlparse, parse_qs, urlunparse, urlencode import flask +from sqlalchemy.orm.exc import NoResultFound from coprs import app +from coprs.logic.coprs_logic import CoprDirsLogic def generate_repo_url(mock_chroot, url, arch=None): @@ -71,10 +73,14 @@ def pre_process_repo_url(chroot, repo_url): if parsed_url.scheme == "copr": user = parsed_url.netloc prj = parsed_url.path.split("/")[1] - repo_url = "/".join([ - flask.current_app.config["BACKEND_BASE_URL"], - "results", user, prj, chroot - ]) + "/" + try: + coprdir = CoprDirsLogic.get_by_ownername(user, prj).one() + repo_url = "{0}/{1}/".format(coprdir.repo_url, chroot) + except NoResultFound: + repo_url = "/".join([ + flask.current_app.config["BACKEND_BASE_URL"], + "results", user, prj, chroot + ]) + "/" elif "priority" in query: query.pop("priority") diff --git a/frontend/coprs_frontend/tests/test_repos.py b/frontend/coprs_frontend/tests/test_repos.py index 96a20ca84..016a2d084 100644 --- a/frontend/coprs_frontend/tests/test_repos.py +++ b/frontend/coprs_frontend/tests/test_repos.py @@ -1,5 +1,6 @@ from copy import deepcopy from unittest import mock +import pytest from coprs import app from coprs.repos import ( generate_repo_url, @@ -7,6 +8,7 @@ parse_repo_params, ) from tests.coprs_test_case import CoprsTestCase +from copr_common.enums import StorageEnum class TestRepos(CoprsTestCase): @@ -84,6 +86,26 @@ def test_pre_process_repo_url(self): for url, exp in test_cases: assert pre_process_repo_url("fedora-rawhide-x86_64", url) == exp + @pytest.mark.usefixtures("f_users", "f_coprs", "f_pr_dir", "f_db") + def test_pre_process_repo_url_coprdir(self): + """ + Test that we generate correct URLs for CoprDirs. We use Pulp storage to + easily test this but this but that it only an implementation detail. + """ + app.config["BACKEND_BASE_URL"] = "http://backend" + app.config["PULP_CONTENT_URL"] = "http://pulp" + + # We set the storage to Pulp, therefore the fallback for constructing + # the repository URL won't be accurate anymore. + self.c1.storage = StorageEnum.pulp + self.db.session.add_all([self.c1, self.c4_dir]) + self.db.session.commit() + + assert self.c1.dirs[1].full_name == "user1/foocopr:PR" + url = "copr://user1/foocopr:PR" + expected = "http://pulp/user1/foocopr:PR/fedora-rawhide-x86_64/" + assert pre_process_repo_url("fedora-rawhide-x86_64", url) == expected + def test_parse_repo_params(self): test_cases = [ ("copr://foo/bar", {}),