def test_get_or_create_pr(clean_before_and_after): with get_sa_session() as session: expected_pr = PullRequestModel.get_or_create( pr_id=42, namespace="clapton", repo_name="layla", project_url="https://github.com/clapton/layla", ) actual_pr = PullRequestModel.get_or_create( pr_id=42, namespace="clapton", repo_name="layla", project_url="https://github.com/clapton/layla", ) assert session.query(PullRequestModel).count() == 1 assert expected_pr.project_id == actual_pr.project_id expected_pr = PullRequestModel.get_or_create( pr_id=42, namespace="clapton", repo_name="cocaine", project_url="https://github.com/clapton/layla", ) actual_pr = PullRequestModel.get_or_create( pr_id=42, namespace="clapton", repo_name="cocaine", project_url="https://github.com/clapton/layla", ) assert session.query(PullRequestModel).count() == 2 assert expected_pr.project_id == actual_pr.project_id
def test_tmt_test_multiple_runs(clean_before_and_after, multiple_new_test_runs): assert multiple_new_test_runs assert multiple_new_test_runs[1].pipeline_id == "123457" assert multiple_new_test_runs[2].pipeline_id == "98765" with get_sa_session() as session: test_runs = session.query(TFTTestRunModel).all() assert len(test_runs) == 3
def test_get_or_create_pr(): clean_db() s = get_sa_session() try: expected_pr = PullRequest.get_or_create(pr_id=42, namespace="clapton", repo_name="layla") actual_pr = PullRequest.get_or_create(pr_id=42, namespace="clapton", repo_name="layla") assert s.query(PullRequest).count() == 1 assert expected_pr.project_id == actual_pr.project_id expected_pr = PullRequest.get_or_create(pr_id=42, namespace="clapton", repo_name="cocaine") actual_pr = PullRequest.get_or_create(pr_id=42, namespace="clapton", repo_name="cocaine") assert s.query(PullRequest).count() == 2 assert expected_pr.project_id == actual_pr.project_id finally: clean_db()
def multiple_installation_entries(installation_events): with get_sa_session() as session: session.query(InstallationModel).delete() yield [ InstallationModel.create(event=installation_events[0],), InstallationModel.create(event=installation_events[1],), ] clean_db()
def test_errors_while_doing_db(clean_before_and_after): with get_sa_session() as session: try: PullRequestModel.get_or_create(pr_id="nope", namespace="", repo_name=False) except ProgrammingError: pass assert len(session.query(PullRequestModel).all()) == 0 PullRequestModel.get_or_create(pr_id=111, namespace="asd", repo_name="qwe") assert len(session.query(PullRequestModel).all()) == 1
def multiple_task_results_entries(task_results): with get_sa_session() as session: session.query(TaskResultModel).delete() yield [ TaskResultModel.add_task_result(task_id="ab1", task_result_dict=task_results[0]), TaskResultModel.add_task_result(task_id="ab2", task_result_dict=task_results[1]), ] clean_db()
def test_tmt_test_multiple_runs(clean_before_and_after, multiple_new_test_runs): assert multiple_new_test_runs assert multiple_new_test_runs[0].pipeline_id == SampleValues.pipeline_id assert multiple_new_test_runs[1].pipeline_id == SampleValues.different_pipeline_id with get_sa_session() as session: test_runs = session.query(TFTTestRunModel).all() assert len(test_runs) == 4 # Separate RunModel for each TFTTestRunModel assert len({m.runs[0] for m in multiple_new_test_runs}) == 4 # Exactly one RunModel for each TFTTestRunModel assert all(len(m.runs) == 1 for m in multiple_new_test_runs) # Two JobTriggerModels: assert len({m.get_trigger_object() for m in multiple_new_test_runs}) == 2
def multiple_copr_builds(): with get_sa_session() as session: session.query(CoprBuild).delete() srpm_build = SRPMBuild.create("asd\nqwe\n") yield [ CoprBuild.get_or_create( pr_id=1, build_id="123456", commit_sha="687abc76d67d", repo_name="lithium", namespace="nirvana", project_name="SomeUser-hello-world-9", owner="packit", web_url="https://copr.something.somewhere/123456", target="fedora-42-x86_64", status="pending", srpm_build=srpm_build, ), # Same build_id but different chroot CoprBuild.get_or_create( pr_id=1, build_id="123456", commit_sha="687abc76d67d", repo_name="lithium", namespace="nirvana", project_name="SomeUser-hello-world-9", owner="packit", web_url="https://copr.something.somewhere/123456", target="fedora-43-x86_64", status="pending", srpm_build=srpm_build, ), # Completely different build CoprBuild.get_or_create( pr_id=4, build_id="987654", commit_sha="987def76d67e", repo_name="cockpit-project", namespace="cockpit", project_name="SomeUser-random-text-7", owner="cockpit-project", web_url="https://copr.something.somewhere/987654", target="fedora-43-x86_64", status="pending", srpm_build=srpm_build, ), ] clean_db()
def multiple_whitelist_entries(): with get_sa_session() as session: session.query(Whitelist).delete() yield [ Whitelist.add_account(account_name="Rayquaza", status="approved_manually"), Whitelist.add_account(account_name="Deoxys", status="approved_manually"), # Not a typo, account_name repeated intentionally to check behaviour Whitelist.add_account(account_name="Deoxys", status="waiting"), Whitelist.add_account(account_name="Solgaleo", status="waiting"), Whitelist.add_account(account_name="Zacian", status="approved_manually"), ] clean_db()
def a_copr_build(): with get_sa_session() as session: session.query(CoprBuild).delete() srpm_build = SRPMBuild.create("asd\nqwe\n") yield CoprBuild.get_or_create( pr_id=1, build_id="123456", commit_sha="687abc76d67d", repo_name="lithium", namespace="nirvana", web_url="https://copr.something.somewhere/123456", target=TARGET, status="pending", srpm_build=srpm_build, ) clean_db()
def multiple_allowlist_entries(): with get_sa_session() as session: session.query(AllowlistModel).delete() yield [ AllowlistModel.add_account(account_name="Rayquaza", status="approved_manually"), AllowlistModel.add_account(account_name="Deoxys", status="approved_manually"), # Not a typo, account_name repeated intentionally to check behaviour AllowlistModel.add_account(account_name="Deoxys", status="waiting"), AllowlistModel.add_account(account_name="Solgaleo", status="waiting"), AllowlistModel.add_account(account_name="Zacian", status="approved_manually"), ]
def clean_db(): with get_sa_session() as session: session.query(CoprBuildModel).delete() session.query(KojiBuildModel).delete() session.query(SRPMBuildModel).delete() session.query(TFTTestRunModel).delete() session.query(TaskResultModel).delete() session.query(WhitelistModel).delete() session.query(InstallationModel).delete() session.query(JobTriggerModel).delete() session.query(GitBranchModel).delete() session.query(ProjectReleaseModel).delete() session.query(PullRequestModel).delete() session.query(IssueModel).delete() session.query(GitProjectModel).delete()
def packit_build_752(): with get_sa_session() as session: session.query(CoprBuild).delete() srpm_build = SRPMBuild.create("asd\nqwe\n") yield CoprBuild.get_or_create( pr_id=752, build_id=str(BUILD_ID), commit_sha="687abc76d67d", repo_name="packit", namespace="packit-service", project_name="packit-service-packit-752", owner="packit", web_url=("https://download.copr.fedorainfracloud.org/" "results/packit/packit-service-packit-752"), target="fedora-rawhide-x86_64", status="pending", srpm_build=srpm_build, ) clean_db()
def test_errors_while_doing_db(clean_before_and_after): with get_sa_session() as session: try: PullRequestModel.get_or_create( pr_id="nope", namespace="", repo_name=False, project_url="https://github.com/the-namespace/the-repo", ) except ProgrammingError: pass assert len(session.query(PullRequestModel).all()) == 0 PullRequestModel.get_or_create( pr_id=111, namespace="asd", repo_name="qwe", project_url="https://github.com/asd/qwe", ) assert len(session.query(PullRequestModel).all()) == 1
def clean_db(): s = get_sa_session() s.query(CoprBuild).delete() s.query(PullRequest).delete() s.query(GitProject).delete() s.commit()
def clean_db(): with get_sa_session() as session: session.query(CoprBuild).delete() session.query(PullRequest).delete() session.query(GitProject).delete()
def new_whitelist_entry(): with get_sa_session() as session: session.query(WhitelistModel).delete() yield WhitelistModel.add_account(account_name="Rayquaza", status="approved_manually")