python类Repository()的实例源码

test_pipeline_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test__when_comment_data_is_valid__should_send_it_to_proper_github_endpoint(self):
        proper_data = {'repository': 'repo', 'sha': '123abc', 'body': 'Comment body', 'jobName': 'job'}

        request = mock({'headers': {'Authorization': f'Token {self.API_TOKEN}'}}, spec=aiohttp.web_request.Request)
        github_client = mock(spec=github.Github)
        github_repository = mock(spec=github.Repository)
        github_commit = mock(spec=github.Commit)

        pipeline_controller = PipelineController(github_client, mock(), self.API_TOKEN)

        # given
        when(request).json().thenReturn(async_value(proper_data))
        when(CommentRequestData).is_valid_comment_data(proper_data).thenReturn(True)
        when(github_client).get_repo('repo').thenReturn(github_repository)
        when(github_repository).get_commit('123abc').thenReturn(github_commit)
        when(github_commit).create_comment(body='job\nComments: Comment body')

        # when
        response: aiohttp.web.Response = await pipeline_controller.handle_comment(request)

        # then
        assert response.status == 200
        assert response.text == 'Comment ACK'
test_pipeline_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test__when_status_data_is_ok__should_call_github_client_to_create_status(self):
        proper_data = {'repository': 'repo', 'sha': '123abc', 'state': 'State', 'description': 'Description', 'context': 'Context', 'url': 'pr_url'}

        request = mock({'headers': {'Authorization': f'Token {self.API_TOKEN}'}}, spec=aiohttp.web_request.Request, strict=True)
        github_client = mock(spec=github.Github, strict=True)
        github_repository = mock(spec=github.Repository, strict=True)
        github_commit = mock(spec=github.Commit, strict=True)

        pipeline_controller = PipelineController(github_client, mock(), self.API_TOKEN)

        # given
        when(request).json().thenReturn(async_value(proper_data))
        when(StatusRequestData).is_valid_status_data(proper_data).thenReturn(True)
        when(github_client).get_repo('repo').thenReturn(github_repository)
        when(github_repository).get_commit('123abc').thenReturn(github_commit)
        when(github_commit).create_status(state='State', description='Description', target_url='pr_url', context='Context')

        # when
        response: aiohttp.web.Response = await pipeline_controller.handle_status(request)

        # then
        assert response.status == 200
        assert response.text == 'Status ACK'
test_pipeline_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test__when_github_entity_is_not_found__status_should_return_404_response_with_github_explanation(self):
        parameters = {'repository': 'repo', 'sha': 'null', 'state': 'State', 'description': 'Description', 'context': 'Context', 'url': 'pr_url'}
        request = mock({'headers': {'Authorization': f'Token {self.API_TOKEN}'}}, spec=aiohttp.web_request.Request, strict=True)
        github_client = mock(spec=github.Github, strict=True)
        github_repository = mock(spec=github.Repository, strict=True)

        pipeline_controller = PipelineController(github_client, mock(), self.API_TOKEN)

        # given
        when(request).json().thenReturn(async_value(parameters))
        when(StatusRequestData).is_valid_status_data(parameters).thenReturn(True)
        when(github_client).get_repo('repo').thenReturn(github_repository)
        github_exception_data = {'message': 'Not Found', 'documentation_url': 'https://developer.github.com/v3/'}
        when(github_repository).get_commit('null').thenRaise(github.GithubException(404, github_exception_data))

        # when
        response: aiohttp.web.Response = await pipeline_controller.handle_status(request)

        # then
        assert response.status == 404
        assert response.reason == str(github_exception_data)
test_pipeline_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test__when_github_entity_is_not_found__comment_should_return_404_response_with_github_explanation(self):
        parameters = {'repository': 'repo', 'sha': 'null', 'body': 'Comment body', 'jobName': 'job'}
        request = mock({'headers': {'Authorization': f'Token {self.API_TOKEN}'}}, spec=aiohttp.web_request.Request, strict=True)
        github_client = mock(spec=github.Github, strict=True)
        github_repository = mock(spec=github.Repository, strict=True)

        pipeline_controller = PipelineController(github_client, mock(), self.API_TOKEN)

        # given
        when(request).json().thenReturn(async_value(parameters))
        when(CommentRequestData).is_valid_comment_data(parameters).thenReturn(True)
        when(github_client).get_repo('repo').thenReturn(github_repository)
        github_exception_data = {'message': 'Not Found', 'documentation_url': 'https://developer.github.com/v3/'}
        when(github_repository).get_commit('null').thenRaise(github.GithubException(404, github_exception_data))

        # when
        response: aiohttp.web.Response = await pipeline_controller.handle_comment(request)

        # then
        assert response.status == 404
        assert response.reason == str(github_exception_data)
test_github_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test__when_setting_pr_sync_label__if_github_raises_more_then_3_times__timeout_error_should_be_raised(self):
        github_client: github.Github = mock(spec=github.Github, strict=True)
        github_controller = GithubController(github_client, mock(), mock(), mock())
        github_repository: github.Repository.Repository = mock(spec=github.Repository.Repository, strict=True)
        mock(spec=asyncio)

        # when
        when(github_client).get_repo('repo')\
            .thenRaise(github.GithubException(404, 'repo not found'))\
            .thenRaise(github.GithubException(404, 'repo not found'))\
            .thenReturn(github_repository)
        when(github_repository).get_issue(43)\
            .thenRaise(github.GithubException(404, 'repo not found'))
        when(asyncio).sleep(1)\
            .thenReturn(async_value(None))\
            .thenReturn(async_value(None))\
            .thenReturn(async_value(None))

        # then
        with pytest.raises(TriggearTimeoutError) as timeout_error:
            await github_controller.set_pr_sync_label_with_retry('repo', 43)
        assert str(timeout_error.value) == 'Failed to set label on PR #43 in repo repo after 3 retries'
test_github_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test__when_get_repo_labels_is_called__only_label_names_are_returned(self):
        github_client: github.Github = mock(spec=github.Github, strict=True)
        github_controller = GithubController(github_client, mock(), mock(), mock())
        github_repository: github.Repository.Repository = mock(spec=github.Repository.Repository, strict=True)
        label: github.Label.Label = mock({'name': 'label'}, spec=github.Label.Label, strict=True)
        other_label: github.Label.Label = mock({'name': 'other_label'}, spec=github.Label.Label, strict=True)

        # given
        when(github_client).get_repo('repo')\
            .thenReturn(github_repository)
        when(github_repository).get_labels()\
            .thenReturn([label, other_label])

        # when
        result: List[str] = github_controller.get_repo_labels('repo')

        # then
        assert result == ['label', 'other_label']
test_github_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test__get_pr_labels__should_return_only_label_names(self):
        github_client: github.Github = mock(spec=github.Github, strict=True)
        github_controller = GithubController(github_client, mock(), mock(), mock())
        github_repository: github.Repository.Repository = mock(spec=github.Repository.Repository, strict=True)
        label: github.Label.Label = mock({'name': 'label'}, spec=github.Label.Label, strict=True)
        other_label: github.Label.Label = mock({'name': 'other_label'}, spec=github.Label.Label, strict=True)
        github_issue: github.Issue.Issue = mock({'labels': [label, other_label]}, spec=github.Issue.Issue, strict=True)

        when(github_client).get_repo('repo')\
            .thenReturn(github_repository)
        when(github_repository).get_issue(25)\
            .thenReturn(github_issue)

        labels: List[str] = github_controller.get_pr_labels('repo', 25)

        assert ['label', 'other_label'] == labels
Repository.py 文件源码 项目:t2-crash-reporter 作者: tessel 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def parent(self):
        """
        :type: :class:`github.Repository.Repository`
        """
        self._completeIfNotSet(self._parent)
        return self._parent.value
Repository.py 文件源码 项目:t2-crash-reporter 作者: tessel 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def source(self):
        """
        :type: :class:`github.Repository.Repository`
        """
        self._completeIfNotSet(self._source)
        return self._source.value
Repository.py 文件源码 项目:t2-crash-reporter 作者: tessel 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_forks(self):
        """
        :calls: `GET /repos/:owner/:repo/forks <http://developer.github.com/v3/repos/forks>`_
        :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
        """
        return github.PaginatedList.PaginatedList(
            Repository,
            self._requester,
            self.url + "/forks",
            None
        )
Repository.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def parent(self):
        """
        :type: :class:`github.Repository.Repository`
        """
        self._completeIfNotSet(self._parent)
        return self._parent.value
Repository.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def source(self):
        """
        :type: :class:`github.Repository.Repository`
        """
        self._completeIfNotSet(self._source)
        return self._source.value
Repository.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def get_forks(self):
        """
        :calls: `GET /repos/:owner/:repo/forks <http://developer.github.com/v3/repos/forks>`_
        :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
        """
        return github.PaginatedList.PaginatedList(
            Repository,
            self._requester,
            self.url + "/forks",
            None
        )
test_github_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test__get_latest_commit_sha__should_call_proper_github_entities(self):
        github_client: github.Github = mock(spec=github.Github, strict=True)
        github_repo: github.Repository.Repository = mock(spec=github.Repository.Repository, strict=True)
        github_head: github.PullRequestPart.PullRequestPart = mock({'sha': '123zxc'}, spec=github.PullRequestPart, strict=True)
        github_pull_request: github.PullRequest.PullRequest = mock({'head': github_head}, spec=github.PullRequest.PullRequest, strict=True)
        github_controller = GithubController(github_client, mock(), mock(), mock())

        expect(github_client).get_repo('triggear').thenReturn(github_repo)
        expect(github_repo).get_pull(32).thenReturn(github_pull_request)

        sha: str = github_controller.get_latest_commit_sha(32, 'triggear')

        assert '123zxc' == sha
test_github_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test__get_pr_branch__should_call_proper_github_entities(self):
        github_client: github.Github = mock(spec=github.Github, strict=True)
        github_repo: github.Repository.Repository = mock(spec=github.Repository.Repository, strict=True)
        github_head: github.PullRequestPart.PullRequestPart = mock({'ref': '123zxc'}, spec=github.PullRequestPart, strict=True)
        github_pull_request: github.PullRequest.PullRequest = mock({'head': github_head}, spec=github.PullRequest.PullRequest, strict=True)
        github_controller = GithubController(github_client, mock(), mock(), mock())

        expect(github_client).get_repo('triggear').thenReturn(github_repo)
        expect(github_repo).get_pull(32).thenReturn(github_pull_request)

        sha: str = github_controller.get_pr_branch(32, 'triggear')

        assert '123zxc' == sha
test_github_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test__are_files_in_repo__should_return_false_on_any_missing_file(self):
        github_client: github.Github = mock(spec=github.Github, strict=True)
        github_repo: github.Repository.Repository = mock(spec=github.Repository.Repository, strict=True)
        github_controller = GithubController(github_client, mock(), mock(), mock())

        hook_details = mock({'repository': 'repo', 'sha': '123qwe', 'branch': 'master'}, spec=HookDetails, strict=True)
        files = ['app/main.py', '.gitignore']

        expect(github_client).get_repo('repo').thenReturn(github_repo)
        expect(github_repo).get_file_contents(path='app/main.py', ref='123qwe').thenReturn(None)
        expect(github_repo).get_file_contents(path='.gitignore', ref='123qwe').thenRaise(GithubException(404, 'File not found'))

        assert not await github_controller.are_files_in_repo(files, hook_details)
test_github_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test__create_pr_comment__calls_proper_github_entities(self):
        github_client: github.Github = mock(spec=github.Github, strict=True)
        github_repo: github.Repository.Repository = mock(spec=github.Repository.Repository, strict=True)
        github_issue: github.Issue.Issue = mock(spec=github.Issue.Issue, strict=True)
        github_controller = GithubController(github_client, mock(), mock(), mock())

        expect(github_client).get_repo('triggear').thenReturn(github_repo)
        expect(github_repo).get_issue(23).thenReturn(github_issue)
        expect(github_issue).create_comment(body='Comment to send')

        github_controller.create_pr_comment(23, 'triggear', 'Comment to send')
test_github_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test__create_github_build_status__calls_github_client_properly(self):
        github_client: github.Github = mock(spec=github.Github, strict=True)
        github_repo: github.Repository.Repository = mock(spec=github.Repository.Repository, strict=True)
        github_commit: github.Commit.Commit = mock(spec=github.Commit.Commit, strict=True)
        github_controller = GithubController(github_client, mock(), mock(), mock())

        expect(github_client).get_repo('repo').thenReturn(github_repo)
        expect(github_repo).get_commit('123456').thenReturn(github_commit)
        expect(github_commit).create_status(state='pending',
                                            target_url='http://example.com',
                                            description='whatever you need',
                                            context='job')

        await github_controller.create_github_build_status('repo', '123456', 'pending', 'http://example.com', 'whatever you need', 'job')
Repository.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def parent(self):
        """
        :type: :class:`github.Repository.Repository`
        """
        self._completeIfNotSet(self._parent)
        return self._parent.value
Repository.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def source(self):
        """
        :type: :class:`github.Repository.Repository`
        """
        self._completeIfNotSet(self._source)
        return self._source.value
Repository.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get_forks(self):
        """
        :calls: `GET /repos/:owner/:repo/forks <http://developer.github.com/v3/repos/forks>`_
        :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
        """
        return github.PaginatedList.PaginatedList(
            Repository,
            self._requester,
            self.url + "/forks",
            None
        )
models.py 文件源码 项目:enamble 作者: enamble 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_or_create_from_repo(cls, repo: Repository) -> 'Repo':
        try:
            return cls.objects.get(id=repo.id)
        except cls.DoesNotExist:
            owner = GitHubUser.get_or_create(username=repo.owner.login)
            return cls.objects.create(owner=owner, name=repo.name, id=repo.id)
Repository.py 文件源码 项目:skill-for-github 作者: dkavanagh 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def parent(self):
        """
        :type: :class:`github.Repository.Repository`
        """
        self._completeIfNotSet(self._parent)
        return self._parent.value
Repository.py 文件源码 项目:skill-for-github 作者: dkavanagh 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def source(self):
        """
        :type: :class:`github.Repository.Repository`
        """
        self._completeIfNotSet(self._source)
        return self._source.value
Repository.py 文件源码 项目:skill-for-github 作者: dkavanagh 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_forks(self):
        """
        :calls: `GET /repos/:owner/:repo/forks <http://developer.github.com/v3/repos/forks>`_
        :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
        """
        return github.PaginatedList.PaginatedList(
            Repository,
            self._requester,
            self.url + "/forks",
            None
        )
BaseAnalyser.py 文件源码 项目:repo-classifier 作者: linkvt 项目源码 文件源码 阅读 51 收藏 0 点赞 0 评论 0
def _get_data_entry(self, repo: GithubRepository):
        pass
LanguageAnalyser.py 文件源码 项目:repo-classifier 作者: linkvt 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _get_data_entry(self, repo: GithubRepository):
        return repo.get_languages()
DescriptionAnalyser.py 文件源码 项目:repo-classifier 作者: linkvt 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _get_data_entry(self, repo: GithubRepository):
        return repo.description
FileExtensionAnalyser.py 文件源码 项目:repo-classifier 作者: linkvt 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _get_data_entry(self, repo: GithubRepository):
        git_tree = repo.get_git_tree(repo.default_branch, recursive=True)
        items = git_tree.tree if git_tree else []
        files = [item for item in items if item.type == 'blob']
        extensions = [os.path.splitext(file.path)[1] for file in files]
        return extensions
FileNameAnalyser.py 文件源码 项目:repo-classifier 作者: linkvt 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _get_data_entry(self, repo: GithubRepository):
        return repo.get_dir_contents('')


问题


面经


文章

微信
公众号

扫码关注公众号