Exemple #1
0
def test_get_all_builds(clean_before_and_after, multiple_copr_builds):
    builds_list = list(CoprBuildModel.get_all())
    assert len({builds_list[i].id for i in range(4)})
    # All builds has to have exactly one RunModel connected
    assert all(len(build.runs) == 1 for build in builds_list)
    # All builds has to have a different RunModel connected.
    assert len({build.runs[0] for build in builds_list}) == 4
    def get(self):
        """ List all Copr builds. """

        # Return relevant info thats concise
        # Usecases like the packit-dashboard copr-builds table

        result = []
        checklist = []
        first, last = indices()
        for build in islice(CoprBuildModel.get_all(), first, last):
            if int(build.build_id) not in checklist:

                build_dict = {
                    "project":
                    build.project_name,
                    "owner":
                    build.owner,
                    "build_id":
                    build.build_id,
                    "status":
                    build.status,  # Legacy, remove later.
                    "status_per_chroot": {},
                    "chroots": [],
                    "build_submitted_time":
                    optional_time(build.build_submitted_time),
                    "web_url":
                    build.web_url,
                }

                project = build.get_project()
                if project:
                    build_dict["repo_namespace"] = project.namespace
                    build_dict["repo_name"] = project.repo_name

                # same_buildid_builds are copr builds created due to the same trigger
                # multiple identical builds are created which differ only in target
                # so we merge them into one
                same_buildid_builds = CoprBuildModel.get_all_by_build_id(
                    str(build.build_id))
                for sbid_build in same_buildid_builds:
                    build_dict["chroots"].append(sbid_build.target)
                    # Get status per chroot as well
                    build_dict["status_per_chroot"][
                        sbid_build.target] = sbid_build.status

                checklist.append(int(build.build_id))
                result.append(build_dict)

        resp = make_response(dumps(result), HTTPStatus.PARTIAL_CONTENT)
        resp.headers[
            "Content-Range"] = f"copr-builds {first + 1}-{last}/{len(result)}"
        resp.headers["Content-Type"] = "application/json"

        return resp
Exemple #3
0
def test_get_all_builds(clean_before_and_after, multiple_copr_builds):
    builds_list = list(CoprBuildModel.get_all())
    assert len(builds_list) == 3
    # we just wanna check if result is iterable
    # order doesn't matter, so all of them are set to pending in supplied data
    assert builds_list[1].status == "pending"