Exemplo n.º 1
0
 def test_variants_tasks(self, sample_patch):
     patch = Patch(sample_patch, None)
     assert len(patch.variants_tasks) == len(sample_patch['variants_tasks'])
     for vt, svt in zip(patch.variants_tasks,
                        sample_patch['variants_tasks']):
         assert vt.name == svt['name']
         assert isinstance(vt.tasks, set)
Exemplo n.º 2
0
    def test_module_code_changes(self, sample_patch):
        patch = Patch(sample_patch, None)
        sample_code_changes = sample_patch["module_code_changes"][0]

        assert patch.module_code_changes[0].branch_name == sample_code_changes[
            "branch_name"]
        assert (patch.module_code_changes[0].commit_messages ==
                sample_code_changes["commit_messages"])
Exemplo n.º 3
0
    def patch_by_id(self, patch_id, params=None):
        """
        Get a patch by patch id.

        :param patch_id: Id of patch to query for.
        :param params: Parameters to pass to endpoint.
        :return: Patch queried for.
        """
        url = self._create_url('/patches/{patch_id}'.format(patch_id=patch_id))
        return Patch(self._call_api(url, params).json(), self)
Exemplo n.º 4
0
    def patch_by_id(self, patch_id: str, params: Dict = None) -> Patch:
        """
        Get a patch by patch id.

        :param patch_id: Id of patch to query for.
        :param params: Parameters to pass to endpoint.
        :return: Patch queried for.
        """
        url = self._create_url("/patches/{patch_id}".format(patch_id=patch_id))
        return Patch(self._call_api(url, params).json(), self)  # type: ignore[arg-type]
Exemplo n.º 5
0
    def patches_by_project(self, project_id: str, params: Dict = None) -> Iterable[Patch]:
        """
        Get a list of patches for the specified project.

        :param project_id: Id of project to query.
        :param params: parameters to pass to endpoint.
        :return: List of recent patches.
        """
        url = self._create_url("/projects/{project_id}/patches".format(project_id=project_id))
        patches = self._lazy_paginate_by_date(url, params)
        return (Patch(patch, self) for patch in patches)  # type: ignore[arg-type]
Exemplo n.º 6
0
    def patches_by_project(self, project_id, params=None):
        """
        Get a list of patches for the specified project.

        :param project_id: Id of project to query.
        :param params: parameters to pass to endpoint.
        :return: List of recent patches.
        """
        url = self._create_url(
            '/projects/{project_id}/patches'.format(project_id=project_id))
        patches = self._lazy_paginate_by_date(url, params)
        return (Patch(patch, self) for patch in patches)
Exemplo n.º 7
0
def test_list_patches(monkeypatch, sample_patch, output_fmt):
    evg_api_mock = _create_api_mock(monkeypatch)
    evg_api_mock.patches_by_project.return_value = [
        Patch(sample_patch, None) for _ in range(10)
    ]

    runner = CliRunner()
    cmd_list = ['list-patches', '--project', 'project', '--limit', '5']
    if output_fmt:
        cmd_list = [output_fmt] + cmd_list
    result = runner.invoke(under_test.cli, cmd_list)
    assert result.exit_code == 0
    assert sample_patch['patch_id'] in result.output
Exemplo n.º 8
0
def test_list_patches(monkeypatch, sample_patch, output_fmt):
    evg_api_mock = _create_api_mock(monkeypatch)
    evg_api_mock.patches_by_project.return_value = [
        Patch(sample_patch, None) for _ in range(10)
    ]

    runner = CliRunner()
    cmd_list = ["list-patches", "--project", "project", "--limit", "5"]
    if output_fmt:
        cmd_list = [output_fmt] + cmd_list
    result = runner.invoke(under_test.cli, cmd_list)
    assert result.exit_code == 0
    if output_fmt == "--json":
        assert len(json.loads(result.output)) == 5
    assert sample_patch["patch_id"] in result.output
Exemplo n.º 9
0
    def patches_by_user(
        self, user_id: str, start_at: Optional[datetime] = None, limit: Optional[int] = None
    ) -> Iterable[Patch]:
        """
        Get an iterable of recent patches by the given user.

        :param user_id: Id of user to query.
        :param start_at: If specified, query starting at the given date.
        :param limit: If specified, limit the output per page.
        """
        params: Dict[str, Any] = {}
        if start_at:
            params["start_at"] = start_at
        if limit:
            params["limit"] = limit
        url = self._create_url(f"/users/{user_id}/patches")
        return (Patch(patch, self) for patch in self._lazy_paginate(url, params))
Exemplo n.º 10
0
 def test_get_attributes(self, sample_patch):
     patch = Patch(sample_patch, None)
     assert patch.description == sample_patch['description']
     assert patch.version == sample_patch['version']
     assert patch.github_patch_data.pr_number == sample_patch[
         'github_patch_data']['pr_number']
Exemplo n.º 11
0
 def test_task_list_for_variant(self, sample_patch):
     patch = Patch(sample_patch, None)
     sample_variant = sample_patch['variants_tasks'][0]
     variant_name = sample_variant['name']
     assert patch.task_list_for_variant(variant_name) == set(
         sample_variant['tasks'])
Exemplo n.º 12
0
 def test_get_attributes(self, sample_patch):
     patch = Patch(sample_patch, None)
     assert patch.description == sample_patch["description"]
     assert patch.version == sample_patch["version"]
     assert patch.github_patch_data.pr_number == sample_patch[
         "github_patch_data"]["pr_number"]
Exemplo n.º 13
0
 def test_task_list_for_variant(self, sample_patch):
     patch = Patch(sample_patch, None)
     sample_variant = sample_patch["variants_tasks"][0]
     variant_name = sample_variant["name"]
     assert patch.task_list_for_variant(variant_name) == set(
         sample_variant["tasks"])