Ejemplo n.º 1
0
def test_dist_git_push_release_handle(release_event):
    packit_yaml = (
        "{'specfile_path': '', 'synced_files': []"
        ", jobs: [{trigger: release, job: propose_downstream, metadata: {targets:[]}}]}"
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    flexmock(
        GithubProject,
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
    steve = SteveJobs()
    flexmock(SteveJobs, _is_private=False)
    config = Config()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(Config).should_receive("get_service_config").and_return(config)
    # it would make sense to make LocalProject offline
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="master", version="0.3.0", create_pr=False).once()

    results = steve.process_message(release_event)
    assert "propose_downstream" in results.get("jobs", {})
    assert results.get("jobs", {}).get("propose_downstream", {}).get("success")
    assert results["trigger"] == str(JobTriggerType.release)
Ejemplo n.º 2
0
def test_process_message(event):
    packit_yaml = {
        "specfile_path": "",
        "synced_files": [],
        "jobs": [{"trigger": "release", "job": "propose_downstream"}],
    }
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    flexmock(
        GithubProject,
        get_file_content=lambda path, ref: dumps(packit_yaml),
        full_repo_name="foo/bar",
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    config = Config()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(Config).should_receive("get_service_config").and_return(config)

    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="master", version="1.2.3", create_pr=False
    ).once()
    flexmock(Whitelist, check_and_report=True)
    flexmock(SteveJobs, _is_private=False)

    results = SteveJobs().process_message(event)
    assert "propose_downstream" in results.get("jobs", {})
    assert results["trigger"] == str(JobTriggerType.release)
Ejemplo n.º 3
0
def test_handler_cleanup(tmpdir):
    t = Path(tmpdir)
    t.joinpath("a").mkdir()
    t.joinpath("b").write_text("a")
    t.joinpath("c").symlink_to("b")
    t.joinpath("d").symlink_to("a", target_is_directory=True)
    t.joinpath("e").symlink_to("nope", target_is_directory=False)
    t.joinpath("f").symlink_to("nopez", target_is_directory=True)
    t.joinpath(".g").write_text("g")
    t.joinpath(".h").symlink_to(".g", target_is_directory=False)

    c = Config()
    c.command_handler_work_dir = t
    jc = JobConfig(JobType.copr_build, [], JobTriggerType.pull_request, {})
    j = JobHandler(c, jc, Event(JobTriggerType.pull_request))

    j._clean_workplace()

    assert len(list(t.iterdir())) == 0
Ejemplo n.º 4
0
    def test_parse_pr(self, pull_request):
        event_object = Parser.parse_event(pull_request)

        assert isinstance(event_object, PullRequestEvent)
        assert event_object.trigger == JobTriggerType.pull_request
        assert event_object.action == PullRequestAction.opened
        assert event_object.pr_id == 342
        assert event_object.base_repo_namespace == "packit-service"
        assert event_object.base_repo_name == "packit"
        assert event_object.base_ref == "528b803be6f93e19ca4130bf4976f2800a3004c4"
        assert event_object.target_repo == "packit-service/packit"
        assert event_object.https_url == "https://github.com/packit-service/packit"
        assert event_object.commit_sha == "528b803be6f93e19ca4130bf4976f2800a3004c4"

        def _get_f_c(*args, **kwargs):
            raise FileNotFoundError()

        flexmock(GithubProject, get_file_content=_get_f_c)
        flexmock(Config, get_service_config=Config())
        assert event_object.get_package_config() is None