diff --git a/packit_service/models.py b/packit_service/models.py index ca2725820..4f7b06eed 100644 --- a/packit_service/models.py +++ b/packit_service/models.py @@ -43,7 +43,6 @@ null, ) from sqlalchemy.dialects.postgresql import array as psql_array -from sqlalchemy.dialects.postgresql import dialect as psql_dialect from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import ( Session as SQLASession, @@ -2512,9 +2511,7 @@ def get_all_successful_or_in_progress_by_nvrs( session.query(BodhiUpdateTargetModel) .filter( BodhiUpdateTargetModel.status.in_(("queued", "retry", "success")), - BodhiUpdateTargetModel.koji_nvrs.regexp_match(regexp).compile( - dialect=psql_dialect(), - ), + BodhiUpdateTargetModel.koji_nvrs.regexp_match(regexp), ) .all(), ) diff --git a/tests_openshift/conftest.py b/tests_openshift/conftest.py index e417ab673..8f99a8591 100644 --- a/tests_openshift/conftest.py +++ b/tests_openshift/conftest.py @@ -158,6 +158,7 @@ class SampleValues: different_dist_git_branch = "f38" alias = "FEDORA-123" bodhi_url = "https://bodhi.fedoraproject.org/FEDORA-123" + sidetag = "f39-build-side-12345" # anitya anitya_project_id = 12345 @@ -199,6 +200,7 @@ def clean_db(): session.query(CoprBuildTargetModel).delete() session.query(CoprBuildGroupModel).delete() session.query(KojiBuildTargetModel).delete() + session.query(BodhiUpdateTargetModel).delete() session.query(SRPMBuildModel).delete() session.query(SyncReleaseTargetModel).delete() session.query(SyncReleaseModel).delete() @@ -2434,9 +2436,10 @@ def bodhi_update_model(branch_project_event_model): ) model = BodhiUpdateTargetModel.create( target=SampleValues.dist_git_branch, - koji_nvr=SampleValues.nvr, + koji_nvrs=SampleValues.nvr, status="queued", bodhi_update_group=group, + sidetag=SampleValues.sidetag, ) model.set_alias(SampleValues.alias) model.set_web_url(SampleValues.bodhi_url) @@ -2444,6 +2447,24 @@ def bodhi_update_model(branch_project_event_model): yield model +@pytest.fixture() +def successful_bodhi_update_model(branch_project_event_model): + group = BodhiUpdateGroupModel.create( + run_model=PipelineModel.create(project_event=branch_project_event_model), + ) + model = BodhiUpdateTargetModel.create( + target=SampleValues.dist_git_branch, + koji_nvrs=SampleValues.nvr, + status="queued", + bodhi_update_group=group, + sidetag=SampleValues.sidetag, + ) + model.set_alias(SampleValues.alias) + model.set_web_url(SampleValues.bodhi_url) + model.set_status("success") + yield model + + @pytest.fixture() def multiple_bodhi_update_runs(branch_project_event_model): group = BodhiUpdateGroupModel.create( @@ -2452,13 +2473,13 @@ def multiple_bodhi_update_runs(branch_project_event_model): yield [ BodhiUpdateTargetModel.create( target=SampleValues.dist_git_branch, - koji_nvr=SampleValues.nvr, + koji_nvrs=SampleValues.nvr, status="queued", bodhi_update_group=group, ), BodhiUpdateTargetModel.create( target=SampleValues.different_dist_git_branch, - koji_nvr=SampleValues.different_nvr, + koji_nvrs=SampleValues.different_nvr, status="queued", bodhi_update_group=group, ), diff --git a/tests_openshift/database/test_models.py b/tests_openshift/database/test_models.py index fe44a5df0..6baf3c2b4 100644 --- a/tests_openshift/database/test_models.py +++ b/tests_openshift/database/test_models.py @@ -7,6 +7,7 @@ from sqlalchemy.exc import IntegrityError, ProgrammingError from packit_service.models import ( + BodhiUpdateTargetModel, BuildStatus, CoprBuildGroupModel, CoprBuildTargetModel, @@ -1145,3 +1146,21 @@ def test_add_scan_to_copr_build(clean_before_and_after, a_copr_build_for_pr): a_copr_build_for_pr.add_scan(123) scan = OSHScanModel.get_by_task_id(123) assert scan.task_id == 123 + + +def test_bodhi_model_get_last_successful_by_sidetag( + clean_before_and_after, successful_bodhi_update_model +): + assert successful_bodhi_update_model.id + + model = BodhiUpdateTargetModel.get_last_successful_by_sidetag(SampleValues.sidetag) + assert model.id == successful_bodhi_update_model.id + + +def test_bodhi_model_get_all_successful_or_in_progress_by_nvrs( + clean_before_and_after, successful_bodhi_update_model +): + assert successful_bodhi_update_model.id + + [model] = BodhiUpdateTargetModel.get_all_successful_or_in_progress_by_nvrs(SampleValues.nvr) + assert model.id == successful_bodhi_update_model.id diff --git a/tests_openshift/service/test_api.py b/tests_openshift/service/test_api.py index 04770b12b..e03f5eb57 100644 --- a/tests_openshift/service/test_api.py +++ b/tests_openshift/service/test_api.py @@ -929,11 +929,11 @@ def test_bodhi_update_list( response_dict.reverse() assert response_dict[0]["status"] == "queued" - assert response_dict[0]["koji_nvr"] == SampleValues.nvr + assert response_dict[0]["koji_nvrs"] == SampleValues.nvr assert response_dict[0]["branch"] == SampleValues.dist_git_branch assert response_dict[0]["branch_name"] == SampleValues.branch - assert response_dict[1]["koji_nvr"] == SampleValues.different_nvr + assert response_dict[1]["koji_nvrs"] == SampleValues.different_nvr assert response_dict[1]["branch"] == SampleValues.different_dist_git_branch assert response_dict[0]["repo_namespace"] == SampleValues.repo_namespace @@ -953,7 +953,7 @@ def test_bodhi_update_info( assert response_dict["alias"] == SampleValues.alias assert response_dict["branch"] == SampleValues.dist_git_branch assert response_dict["web_url"] == SampleValues.bodhi_url - assert response_dict["koji_nvr"] == SampleValues.nvr + assert response_dict["koji_nvrs"] == SampleValues.nvr assert response_dict["branch_name"] == SampleValues.branch assert response_dict["repo_name"] == SampleValues.repo_name assert response_dict["repo_namespace"] == SampleValues.repo_namespace