Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions frontend/coprs_frontend/coprs/logic/builds_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,11 @@ def create_new_from_distgit(cls, user, copr, package_name,
source_dict["clone_url"] = DistGitLogic.get_clone_url(
distgit_name, package_name, distgit_namespace)

if distgit_name:
source_dict["distgit"] = distgit_name

if distgit_namespace:
source_dict["namespace"] = distgit_namespace
if committish:
source_dict["committish"] = committish

Expand Down
8 changes: 6 additions & 2 deletions frontend/coprs_frontend/tests/test_apiv3/test_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
{
"clone_url": "git://prio.com/some/other/uri/mock/git",
"distgit": "prioritized",
},
{
"distgit": "prioritized",
Expand All @@ -43,8 +44,8 @@
"distgit": "fedora",
},
{
# no need to store "distgit" to source_json
"clone_url": "https://src.fedoraproject.org/rpms/cpio"
"clone_url": "https://src.fedoraproject.org/rpms/cpio",
"distgit": "fedora",
},
{
"distgit": "fedora",
Expand All @@ -60,6 +61,7 @@
{
"committish": "f15",
"clone_url": "git://prio.com/some/other/uri/tar/git",
"distgit": "prioritized",
},
{
"distgit": "prioritized",
Expand All @@ -76,6 +78,8 @@
},
{
"clone_url": "https://namespaced.org/some/other/uri/@copr/copr/blah/git",
"distgit": "namespaced",
"namespace": "@copr/copr",
},
{
"distgit": "namespaced",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,36 @@ def test_copr_user_can_add_distgit_build(self):
assert build.source_type == BuildSourceEnum.distgit
assert build.source_json == json.dumps({
"clone_url": "https://src.fedoraproject.org/rpms/mock",
"distgit": "fedora",
"committish": "master"})

assert len(build.chroots) == 1
assert build.chroots[0].name == "fedora-18-x86_64"

@TransactionDecorator("u1")
@pytest.mark.usefixtures("f_users", "f_coprs", "f_mock_chroots", "f_db")
def test_distgit_build_stores_namespace_distgit(self):
"""
Test that distgit_namespace and distgit source is stored in source_json when provided.
"""
self.db.session.add_all([self.u1, self.c1])
data = {
"package_name": "mock",
"committish": "master",
"namespace": "forks/testuser",
"chroots": ["fedora-18-x86_64"],
}
endpoint = "/coprs/{0}/{1}/new_build_distgit/".format(self.u1.name,
self.c1.name)
self.test_client.post(endpoint, data=data, follow_redirects=True)
build = self.models.Build.query.first()
assert build.source_type == BuildSourceEnum.distgit
source_dict = json.loads(build.source_json)
assert "namespace" in source_dict
assert "distgit" in source_dict
assert source_dict["namespace"] == "forks/testuser"
assert source_dict["distgit"] == "fedora"
Comment on lines +55 to +59

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The assertions in this test are not comprehensive. It's better to assert the entire source_json content to ensure all fields, including clone_url and committish, are correctly set. This makes the test more robust and consistent with test_copr_user_can_add_distgit_build.

Suggested change
source_dict = json.loads(build.source_json)
assert "namespace" in source_dict
assert "distgit" in source_dict
assert source_dict["namespace"] == "forks/testuser"
assert source_dict["distgit"] == "fedora"
expected_source_json = {
"clone_url": "https://src.fedoraproject.org/forks/testuser/rpms/mock",
"distgit": "fedora",
"namespace": "forks/testuser",
"committish": "master",
}
assert json.loads(build.source_json) == expected_source_json


@TransactionDecorator("u1")
@pytest.mark.usefixtures("f_users", "f_coprs", "f_mock_chroots", "f_db")
def test_copr_user_can_add_distgit_package(self):
Expand Down