def test_comment_overflow(self, mock_getenv, mock_client_session): mock_args, fake_client_session = self.create_mock_pr( mock_getenv, mock_client_session) reporter = github_reporter.create_reporter(mock_args) problems = [Problem('another_file', x, 'Wat') for x in range(1, 13)] async_report = reporter.report('unit-test-linter', problems) loop = asyncio.get_event_loop() loop.run_until_complete(async_report) overflow_message = textwrap.dedent('''\ unit-test-linter says: Too many lint errors to report inline! 12 lines have a problem. Only reporting the first 10.''') overflow_call = call.post( 'https://api.github.com/repos/foo/bar/issues/1234/comments', headers={'Authorization': 'token MY_TOKEN'}, data=json.dumps({ 'body': overflow_message, }, sort_keys=True)) self.assertIn(overflow_call, fake_client_session.calls) self.assertEqual(3 + github_reporter.MAX_LINT_ERROR_REPORTS, len(fake_client_session.calls))
def test_comment_overflow(self, mock_getenv, mock_client_session): mock_args, fake_client_session = self.create_mock_pr( mock_getenv, mock_client_session) reporter = github_reporter.create_reporter(mock_args) problems = [Problem('another_file', x, 'Wat') for x in range(1, 13)] async_report = reporter.report(problems) loop = asyncio.get_event_loop() loop.run_until_complete(async_report) overflow_message = textwrap.dedent('''\ :sparkles:Linty Fresh Says:sparkles:: Too many lint errors to report inline! 12 lines have a problem. Only reporting the first 10.''') overflow_call = call.post( 'https://api.github.com/repos/foo/bar/pulls/1234/comments', headers={ 'Authorization': 'token MY_TOKEN' }, data=json.dumps({ 'body': overflow_message, }, sort_keys=True) ) self.assertIn(overflow_call, fake_client_session.calls) self.assertEqual(3 + github_reporter.MAX_LINT_ERROR_REPORTS, len(fake_client_session.calls))
def test_comment_on_pr(self, mock_getenv, mock_client_session): mock_args, fake_client_session = self.create_mock_pr( mock_getenv, mock_client_session) reporter = github_reporter.create_reporter(mock_args) async_report = reporter.report('unit-test-linter', [ Problem('some_dir/some_file', 40, 'this made me sad'), Problem('some_dir/some_file', 40, 'really sad'), Problem('another_file', 2, 'This is OK'), Problem('another_file', 2, 'This is OK'), Problem('another_file', 3, 'I am a duplicate!'), Problem('another_file', 52, "#close_enough!!!"), Problem('missing_file', 42, "Missing file comment!!!"), ]) loop = asyncio.get_event_loop() loop.run_until_complete(async_report) diff_request = call.get( 'https://api.github.com/repos/foo/bar/pulls/1234', headers={ 'Accept': 'application/vnd.github.diff', 'Authorization': 'token MY_TOKEN' }) existing_comments_request = call.get( 'https://api.github.com/repos/foo/bar/pulls/1234/comments', headers={'Authorization': 'token MY_TOKEN'}) first_comment = call.post( 'https://api.github.com/repos/foo/bar/pulls/1234/comments', headers={'Authorization': 'token MY_TOKEN'}, data=json.dumps( { 'commit_id': 'abc123', 'path': 'another_file', 'body': textwrap.dedent('''\ unit-test-linter says: ``` This is OK ```'''), 'position': 2 }, sort_keys=True)) second_comment = call.post( 'https://api.github.com/repos/foo/bar/pulls/1234/comments', headers={'Authorization': 'token MY_TOKEN'}, data=json.dumps( { 'commit_id': 'abc123', 'path': 'some_dir/some_file', 'body': textwrap.dedent('''\ unit-test-linter says: ``` this made me sad really sad ```'''), 'position': 3 }, sort_keys=True)) close_enough_comment = call.post( 'https://api.github.com/repos/foo/bar/pulls/1234/comments', headers={'Authorization': 'token MY_TOKEN'}, data=json.dumps( { 'commit_id': 'abc123', 'path': 'another_file', 'body': textwrap.dedent('''\ unit-test-linter says: (From line 52) ``` #close_enough!!! ```'''), 'position': 12 }, sort_keys=True)) missing_file_call = call.post( 'https://api.github.com/repos/foo/bar/issues/1234/comments', headers={'Authorization': 'token MY_TOKEN'}, data=json.dumps( { 'body': textwrap.dedent('''\ unit-test-linter found some problems with lines not modified by this commit: ``` missing_file:42: \tMissing file comment!!! ```'''), }, sort_keys=True)) self.assertEqual(6, len(fake_client_session.calls)) self.assertIn(diff_request, fake_client_session.calls) self.assertIn(existing_comments_request, fake_client_session.calls) self.assertIn(first_comment, fake_client_session.calls) self.assertIn(second_comment, fake_client_session.calls) self.assertIn(close_enough_comment, fake_client_session.calls) self.assertIn(missing_file_call, fake_client_session.calls)
def test_comment_on_pr(self, mock_getenv, mock_client_session): mock_args, fake_client_session = self.create_mock_pr( mock_getenv, mock_client_session) reporter = github_reporter.create_reporter(mock_args) async_report = reporter.report([ Problem('some_dir/some_file', 40, 'this made me sad'), Problem('some_dir/some_file', 40, 'really sad'), Problem('another_file', 2, 'This is OK'), Problem('another_file', 2, 'This is OK'), Problem('another_file', 3, 'I am a duplicate!'), Problem('missing_file', 42, "Don't report me!!!"), ]) loop = asyncio.get_event_loop() loop.run_until_complete(async_report) diff_request = call.get( 'https://api.github.com/repos/foo/bar/pulls/1234', headers={ 'Accept': 'application/vnd.github.diff', 'Authorization': 'token MY_TOKEN' }) existing_comments_request = call.get( 'https://api.github.com/repos/foo/bar/pulls/1234/comments', headers={'Authorization': 'token MY_TOKEN'}) first_comment = call.post( 'https://api.github.com/repos/foo/bar/pulls/1234/comments', headers={'Authorization': 'token MY_TOKEN'}, data=json.dumps( { 'commit_id': 'abc123', 'path': 'another_file', 'body': textwrap.dedent('''\ :sparkles:Linty Fresh Says:sparkles:: ``` This is OK ```'''), 'position': 2 }, sort_keys=True)) second_comment = call.post( 'https://api.github.com/repos/foo/bar/pulls/1234/comments', headers={'Authorization': 'token MY_TOKEN'}, data=json.dumps( { 'commit_id': 'abc123', 'path': 'some_dir/some_file', 'body': textwrap.dedent('''\ :sparkles:Linty Fresh Says:sparkles:: ``` this made me sad really sad ```'''), 'position': 3 }, sort_keys=True)) self.assertEqual(4, len(fake_client_session.calls)) self.assertIn(diff_request, fake_client_session.calls) self.assertIn(existing_comments_request, fake_client_session.calls) self.assertIn(first_comment, fake_client_session.calls) self.assertIn(second_comment, fake_client_session.calls)
def test_comment_on_pr(self, mock_getenv, mock_client_session): mock_args, fake_client_session = self.create_mock_pr( mock_getenv, mock_client_session) reporter = github_reporter.create_reporter(mock_args) async_report = reporter.report([ Problem('some_dir/some_file', 40, 'this made me sad'), Problem('some_dir/some_file', 40, 'really sad'), Problem('another_file', 2, 'This is OK'), Problem('another_file', 2, 'This is OK'), Problem('another_file', 3, 'I am a duplicate!'), Problem('missing_file', 42, "Don't report me!!!"), ]) loop = asyncio.get_event_loop() loop.run_until_complete(async_report) diff_request = call.get( 'https://api.github.com/repos/foo/bar/pulls/1234', headers={ 'Accept': 'application/vnd.github.diff', 'Authorization': 'token MY_TOKEN' }) existing_comments_request = call.get( 'https://api.github.com/repos/foo/bar/pulls/1234/comments', headers={ 'Authorization': 'token MY_TOKEN' }) first_comment = call.post( 'https://api.github.com/repos/foo/bar/pulls/1234/comments', headers={ 'Authorization': 'token MY_TOKEN' }, data=json.dumps({ 'commit_id': 'abc123', 'path': 'another_file', 'body': textwrap.dedent('''\ :sparkles:Linty Fresh Says:sparkles:: ``` This is OK ```'''), 'position': 2 }, sort_keys=True) ) second_comment = call.post( 'https://api.github.com/repos/foo/bar/pulls/1234/comments', headers={ 'Authorization': 'token MY_TOKEN' }, data=json.dumps({ 'commit_id': 'abc123', 'path': 'some_dir/some_file', 'body': textwrap.dedent('''\ :sparkles:Linty Fresh Says:sparkles:: ``` this made me sad really sad ```'''), 'position': 3 }, sort_keys=True) ) self.assertEqual(4, len(fake_client_session.calls)) self.assertIn(diff_request, fake_client_session.calls) self.assertIn(existing_comments_request, fake_client_session.calls) self.assertIn(first_comment, fake_client_session.calls) self.assertIn(second_comment, fake_client_session.calls)