def test_pr_url(): requester = Requester("") pr = PRReporter(requester, 'justinabrahms/imhotep', 10) pr.report_line(commit='sha', file_name='setup.py', line_number=10, position=0, message="test") assert requester.url == "https://api.github.com/repos/justinabrahms/imhotep/pulls/10/comments"
def test_pr__post_comment(): requester = mock.MagicMock() requester.username = '******' requester.post.return_value.status_code = 200 pr = PRReporter(requester, 'justinabrahms/imhotep', 10) pr.post_comment("my-message") assert requester.post.called
def test_pr_already_reported(): requester = mock.MagicMock() requester.username = '******' comments = [{'path': 'foo.py', 'position': 2, 'body': 'Get that out', 'user': {'login': '******'}}] pr = PRReporter(requester, 10) pr._comments = comments result = pr.report_line(repo_name='justinabrahms/imhotep', commit='sha', file_name='foo.py', line_number=2, position=2, message='Get that out') assert result is None
def test_pr_already_reported(): requester = mock.MagicMock() requester.username = '******' comments = [{ 'path': 'foo.py', 'position': 2, 'body': 'Get that out', 'user': { 'login': '******' } }] pr = PRReporter(requester, 'justinabrahms/imhotep', 10) pr._comments = comments result = pr.report_line(commit='sha', file_name='foo.py', line_number=2, position=2, message='Get that out') assert result is None
def test_github_post(): repo = 'imhotepbot/sacrificial-integration-tests' pr = 1 test_str = 'integration test error name' req = BasicAuthRequester(ghu, ghp) r = PRReporter(req, repo, pr) r.report_line('da6a127a285ae08d9bfcccb1cb62aef908485769', 'foo.py', 2, 3, test_str) comments = req.get('https://api.github.com/repos/%s/pulls/%s/comments' % (repo, pr)).json() posted = [x for x in comments if test_str in x['body']] try: assert len(posted) == 1 finally: for comment in comments: req.delete('https://api.github.com/repos/%s/pulls/comments/%s' % ( repo, comment['id']))
def test_github_post(): repo = 'imhotepbot/sacrificial-integration-tests' pr = 1 test_str = 'integration test error name' req = BasicAuthRequester(ghu, ghp) r = PRReporter(req, pr) r.report_line(repo, 'da6a127a285ae08d9bfcccb1cb62aef908485769', 'foo.py', 2, 3, test_str) comments = req.get('https://api.github.com/repos/%s/pulls/%s/comments' % (repo, pr)).json() posted = [x for x in comments if test_str in x['body']] try: assert len(posted) == 1 finally: for comment in comments: req.delete('https://api.github.com/repos/%s/pulls/comments/%s' % ( repo, comment['id']))
def test_dont_post_duplicate_comments(): repo = 'imhotepbot/sacrificial-integration-tests' pr = 1 test_str = 'integration test error name' req = BasicAuthRequester(ghu, ghp) r = PRReporter(req, pr) args = [repo, 'da6a127a285ae08d9bfcccb1cb62aef908485769', 'foo.py', 2, 3, test_str] r.report_line(*args) r.report_line(*args) # should dedupe. comment_url = 'https://api.github.com/repos/%s/pulls/%s/comments' % ( repo, pr) comments = req.get(comment_url).json() posted = [x for x in comments if test_str in x['body']] try: assert len(posted) == 1 finally: for comment in comments: req.delete('%s/%s' % (comment_url, comment['id']))
def test_dont_post_duplicate_comments(): repo = 'imhotepbot/sacrificial-integration-tests' pr = 1 test_str = 'integration test error name' req = BasicAuthRequester(ghu, ghp) r = PRReporter(req, repo, pr) args = [ 'da6a127a285ae08d9bfcccb1cb62aef908485769', 'foo.py', 2, 3, test_str ] r.report_line(*args) r.report_line(*args) # should dedupe. comment_url = 'https://api.github.com/repos/%s/pulls/%s/comments' % (repo, pr) comments = req.get(comment_url).json() posted = [x for x in comments if test_str in x['body']] try: assert len(posted) == 1 finally: for comment in comments: req.delete('%s/%s' % (comment_url, comment['id']))