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'
评论列表
文章目录