def create_general_comment(self, review, text='My comment', issue_opened=False, extra_fields=None, reply_to=None, **kwargs): """Creates a GeneralComment for testing. The comment is tied to the given Review. It is populated with default data that can be overridden by the caller. """ if issue_opened: issue_status = Comment.OPEN else: issue_status = None comment = GeneralComment(text=text, issue_opened=issue_opened, issue_status=issue_status, reply_to=reply_to) if extra_fields: comment.extra_data = extra_fields comment.save() review.general_comments.add(comment) return comment
def create_general_comment(self, review, text='My comment', issue_opened=False, extra_fields=None, reply_to=None, **kwargs): """Creates a GeneralComment for testing. The comment is tied to the given Review. It is populated with default data that can be overridden by the caller. """ if issue_opened: issue_status = Comment.OPEN else: issue_status = None comment = GeneralComment( text=text, issue_opened=issue_opened, issue_status=issue_status, reply_to=reply_to) if extra_fields: comment.extra_data = extra_fields comment.save() review.general_comments.add(comment) return comment
def create_general_comment(self, review, text='My comment', issue_opened=False, issue_status=None, extra_fields=None, reply_to=None, **kwargs): """Create a GeneralComment for testing. The comment is tied to the given Review. It is populated with default data that can be overridden by the caller. Args: review (reviewboard.reviews.models.review.Review): The review associated with the comment. text (unicode): The text for the comment. issue_opened (bool, optional): Whether an issue is to be opened for the comment. issue_status (unicode, optional): The issue status to set, if an issue is opened. Defaults to being an open issue. extra_fields (dict, optional): Extra data to set on the comment. reply_to (reviewboard.reviews.models.general_comment. GeneralComment, optional): The comment this comment replies to. **kwargs (dict): Additional model attributes to set on the comment. Returns: reviewboard.reviews.models.general_comment.GeneralComment: The resulting comment. """ if issue_opened and not issue_status: issue_status = GeneralComment.OPEN comment = GeneralComment(text=text, issue_opened=issue_opened, issue_status=issue_status, reply_to=reply_to, **kwargs) if extra_fields: comment.extra_data = extra_fields comment.save() review.general_comments.add(comment) return comment
def create_general_comment(self, review, text='My comment', issue_opened=False, issue_status=None, extra_fields=None, reply_to=None, **kwargs): """Create a GeneralComment for testing. The comment is tied to the given Review. It is populated with default data that can be overridden by the caller. Args: review (reviewboard.reviews.models.review.Review): The review associated with the comment. text (unicode): The text for the comment. issue_opened (bool, optional): Whether an issue is to be opened for the comment. issue_status (unicode, optional): The issue status to set, if an issue is opened. Defaults to being an open issue. extra_fields (dict, optional): Extra data to set on the comment. reply_to (reviewboard.reviews.models.general_comment. GeneralComment, optional): The comment this comment replies to. **kwargs (dict): Additional model attributes to set on the comment. Returns: reviewboard.reviews.models.general_comment.GeneralComment: The resulting comment. """ if issue_opened and not issue_status: issue_status = GeneralComment.OPEN comment = GeneralComment( text=text, issue_opened=issue_opened, issue_status=issue_status, reply_to=reply_to, **kwargs) if extra_fields: comment.extra_data = extra_fields comment.save() review.general_comments.add(comment) return comment
def test_add_comment_with_no_open_issues(self): """Testing ReviewEntry.add_comment with comment not opening an issue""" self.request.user = self.review_request.submitter entry = ReviewEntry(request=self.request, review_request=self.review_request, review=self.review, collapsed=True, data=self.data) self.assertFalse(entry.has_issues) self.assertEqual(entry.issue_open_count, 0) entry.add_comment('general_comments', GeneralComment()) self.assertFalse(entry.has_issues) self.assertEqual(entry.issue_open_count, 0) self.assertTrue(entry.collapsed)
def test_add_comment_with_open_issues(self): """Testing ReviewEntry.add_comment with comment opening an issue""" entry = ReviewEntry(request=self.request, review_request=self.review_request, review=self.review, collapsed=True, data=self.data) self.assertFalse(entry.has_issues) self.assertEqual(entry.issue_open_count, 0) entry.add_comment( 'general_comments', GeneralComment(issue_opened=True, issue_status=GeneralComment.OPEN)) self.assertTrue(entry.has_issues) self.assertEqual(entry.issue_open_count, 1) self.assertTrue(entry.collapsed)
def test_add_comment_with_open_issues_and_viewer_is_owner(self): """Testing ReviewEntry.add_comment with comment opening an issue and the review request owner is viewing the page """ self.request.user = self.review_request.submitter entry = ReviewEntry(request=self.request, review_request=self.review_request, review=self.review, collapsed=True, data=self.data) self.assertFalse(entry.has_issues) self.assertEqual(entry.issue_open_count, 0) entry.add_comment( 'general_comments', GeneralComment(issue_opened=True, issue_status=GeneralComment.OPEN)) self.assertTrue(entry.has_issues) self.assertEqual(entry.issue_open_count, 1) self.assertFalse(entry.collapsed)