def test_publish_summary(self): problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( IssueComment('Terrible things'), Comment(filename_1, 117, 117, 'Something bad'), Comment(filename_1, 119, 119, 'Something bad'), ) problems.add_many(errors) problems.set_changes([1]) review = Review(self.repo, self.pr, self.config) review.publish_summary(problems) assert self.pr.create_comment.called eq_(1, self.pr.create_comment.call_count) msg = """There are 3 errors: * Terrible things * Console/Command/Task/AssetBuildTask.php, line 117 - Something bad * Console/Command/Task/AssetBuildTask.php, line 119 - Something bad """ self.pr.create_comment.assert_called_with(msg)
def test_publish_summary(self): gh = Mock() problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( (filename_1, 117, 'Something bad'), (filename_1, 119, 'Something bad'), ) problems.add_many(errors) problems.set_changes([1]) sha = 'abc123' review = Review(gh, 3) review.publish_summary(problems) assert gh.issues.comments.create.called eq_(1, gh.issues.comments.create.call_count) calls = gh.issues.comments.create.call_args_list msg = """There are 2 errors: * Console/Command/Task/AssetBuildTask.php, line 117 - Something bad * Console/Command/Task/AssetBuildTask.php, line 119 - Something bad """ expected = call(3, msg) eq_(calls[0], expected)
def test_publish_summary(self): gh = Mock() problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( (filename_1, 117, 'Something bad'), (filename_1, 119, 'Something bad'), ) problems.add_many(errors) problems.set_changes([1]) sha = 'abc123' review = Review(gh, 3) review.publish_summary(problems) assert gh.issues.comments.create.called eq_(1, gh.issues.comments.create.call_count) calls = gh.issues.comments.create.call_args_list msg = """There are 2 errors: * Console/Command/Task/AssetBuildTask.php, line 117 - Something bad * Console/Command/Task/AssetBuildTask.php, line 119 - Something bad """ expected = call(3, msg) eq_(calls[0], expected)
def test_publish_summary(self): problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( IssueComment('Terrible things'), Comment(filename_1, 117, 117, 'Something bad'), Comment(filename_1, 119, 119, 'Something bad'), ) problems.add_many(errors) problems.set_changes([1]) review = Review(self.repo, self.pr, self.config) review.publish_summary(problems) assert self.pr.create_comment.called self.assertEqual(1, self.pr.create_comment.call_count) msg = """There are 3 errors: * Terrible things * Console/Command/Task/AssetBuildTask.php, line 117 - Something bad * Console/Command/Task/AssetBuildTask.php, line 119 - Something bad """ self.pr.create_comment.assert_called_with(msg)
def test_publish_review_no_count_change(self): fixture = load_fixture('comments_current.json') self.pr.review_comments.return_value = [ GhIssueComment(f) for f in json.loads(fixture) ] problems = Problems() # Match the line/positions in comments_current.json filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( Comment(filename_1, 40, 40, '2. Something bad'), Comment(filename_1, 87, 87, '1. Something bad'), Comment(filename_1, 89, 89, '2. Something bad'), ) problems.add_many(errors) problems.set_changes([1]) sha = 'abc123' config = build_review_config(fixer_ini, {'SUMMARY_THRESHOLD': 1}) review = Review(self.repo, self.pr, config) review.publish_summary = Mock() review.publish_status = Mock() review.publish_review(problems, sha) # Ensure publish_status(True) means the status=failed review.publish_status.assert_called_with(True)
def test_publish_summary(self): problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( (filename_1, 117, 'Something bad'), (filename_1, 119, 'Something bad'), ) problems.add_many(errors) problems.set_changes([1]) review = Review(self.gh, 3) review.publish_summary(problems) assert self.issue.create_comment.called eq_(1, self.issue.create_comment.call_count) msg = """There are 2 errors: * Console/Command/Task/AssetBuildTask.php, line 117 - Something bad * Console/Command/Task/AssetBuildTask.php, line 119 - Something bad """ self.issue.create_comment.assert_called_with(msg)
def test_publish_comment_threshold_checks(self): fixture = load_fixture('comments_current.json') self.pr.review_comments.return_value = [GhIssueComment(f) for f in json.loads(fixture)] problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( (filename_1, 117, 'Something bad'), (filename_1, 119, 'Something bad'), ) problems.add_many(errors) problems.set_changes([1]) sha = 'abc123' review = Review(self.gh, 3) review.publish_summary = Mock() review.publish(problems, sha, 1) assert review.publish_summary.called, 'Should have been called.'
def test_publish_review_comment_threshold_checks(self): fixture = load_fixture('comments_current.json') self.pr.review_comments.return_value = [ GhIssueComment(f) for f in json.loads(fixture)] problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( Comment(filename_1, 117, 117, 'Something bad'), Comment(filename_1, 119, 119, 'Something bad'), ) problems.add_many(errors) problems.set_changes([1]) sha = 'abc123' config = build_review_config(fixer_ini, {'SUMMARY_THRESHOLD': 1}) review = Review(self.repo, self.pr, config) review.publish_summary = Mock() review.publish_review(problems, sha) assert review.publish_summary.called, 'Should have been called.'
def test_publish_comment_threshold_checks(self, http): fixture_data = load_fixture('comments_current.json') response = Response() response._content = fixture_data http.return_value = response gh = Github() problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( (filename_1, 117, 'Something bad'), (filename_1, 119, 'Something bad'), ) problems.add_many(errors) problems.set_changes([1]) sha = 'abc123' review = Review(gh, 3) review.publish_summary = Mock() review.publish(problems, sha, 1) assert review.publish_summary.called, 'Should have been called.'
def test_publish_comment_threshold_checks(self, http): fixture_data = load_fixture('comments_current.json') response = Response() response._content = fixture_data http.return_value = response gh = Github() problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( (filename_1, 117, 'Something bad'), (filename_1, 119, 'Something bad'), ) problems.add_many(errors) problems.set_changes([1]) sha = 'abc123' review = Review(gh, 3) review.publish_summary = Mock() review.publish(problems, sha, 1) assert review.publish_summary.called, 'Should have been called.'