Exemplo n.º 1
0
 def test_draft_details_no_base_file(self):
     request = MockRequest(User('*****@*****.**'), issue=self.issue)
     # add a comment and render
     cmt = models.Comment(patch=self.patches[0], parent=self.patches[0])
     cmt.text = 'test comment'
     cmt.lineno = 1
     cmt.left = False
     cmt.draft = True
     cmt.author = self.user
     cmt.save()
     tbd, comments = views._get_draft_comments(request, self.issue)
     self.assertEqual(len(comments), 1)
     # Try to render draft details:
     views._get_draft_details(request, comments)
Exemplo n.º 2
0
    def test_draft_details_no_base_file(self):
        request = MockRequest(User('*****@*****.**'), issue=self.issue)
        # add a comment and render
        cmt1 = models.Comment(patch_key=self.patches[0].key,
                              parent=self.patches[0].key)
        cmt1.text = 'test comment'
        cmt1.lineno = 1
        cmt1.left = False
        cmt1.draft = True
        cmt1.author = self.user
        cmt1.put()
        # Add a second comment
        cmt2 = models.Comment(patch_key=self.patches[1].key,
                              parent=self.patches[1].key)
        cmt2.text = 'test comment 2'
        cmt2.lineno = 2
        cmt2.left = False
        cmt2.draft = True
        cmt2.author = self.user
        cmt2.put()
        # Add fake content
        content1 = models.Content(text="foo\nbar\nbaz\nline\n")
        content1.put()
        content2 = models.Content(text="foo\nbar\nbaz\nline\n")
        content2.put()
        cmt1_patch = cmt1.patch_key.get()
        cmt1_patch.content_key = content1.key
        cmt1_patch.put()
        cmt2_patch = cmt2.patch_key.get()
        cmt2_patch.content_key = content2.key
        cmt2_patch.put()

        # Mock get content calls. The first fails with an FetchError,
        # the second succeeds (see issue384).
        def raise_err():
            raise models.FetchError()

        cmt1.patch_key.get().get_content = raise_err
        cmt2.patch_key.get().get_patched_content = lambda: content2
        tbd, comments = views._get_draft_comments(request, self.issue)
        self.assertEqual(len(comments), 2)
        # Try to render draft details using the patched Comment
        # instances from here.
        views._get_draft_details(request, [cmt1, cmt2])
Exemplo n.º 3
0
 def test_draft_details_no_base_file(self):
   request = MockRequest(User('*****@*****.**'), issue=self.issue)
   # add a comment and render
   cmt1 = models.Comment(
     patch_key=self.patches[0].key, parent=self.patches[0].key)
   cmt1.text = 'test comment'
   cmt1.lineno = 1
   cmt1.left = False
   cmt1.draft = True
   cmt1.author = self.user
   cmt1.put()
   # Add a second comment
   cmt2 = models.Comment(
     patch_key=self.patches[1].key, parent=self.patches[1].key)
   cmt2.text = 'test comment 2'
   cmt2.lineno = 2
   cmt2.left = False
   cmt2.draft = True
   cmt2.author = self.user
   cmt2.put()
   # Add fake content
   content1 = models.Content(text="foo\nbar\nbaz\nline\n")
   content1.put()
   content2 = models.Content(text="foo\nbar\nbaz\nline\n")
   content2.put()
   cmt1_patch = cmt1.patch_key.get()
   cmt1_patch.content_key = content1.key
   cmt1_patch.put()
   cmt2_patch = cmt2.patch_key.get()
   cmt2_patch.content_key = content2.key
   cmt2_patch.put()
   # Mock get content calls. The first fails with an FetchError,
   # the second succeeds (see issue384).
   def raise_err():
     raise models.FetchError()
   cmt1.patch_key.get().get_content = raise_err
   cmt2.patch_key.get().get_patched_content = lambda: content2
   _, comments = views._get_draft_comments(request, self.issue)
   self.assertEqual(len(comments), 2)
   # Try to render draft details using the patched Comment
   # instances from here.
   views._get_draft_details(request, [cmt1, cmt2])
Exemplo n.º 4
0
    def test_draft_details_no_base_file(self):
        self.login(self.student_acc.email)

        request = MockRequest(self.student_acc.user, issue=self.issue)
        # add a comment and render
        cmt1 = models.Comment(patch=self.patches[0], parent=self.patches[0])
        cmt1.text = 'test comment'
        cmt1.lineno = 1
        cmt1.left = False
        cmt1.draft = True
        cmt1.author = self.student_acc.user
        cmt1.save()
        # Add a second comment
        cmt2 = models.Comment(patch=self.patches[1], parent=self.patches[1])
        cmt2.text = 'test comment 2'
        cmt2.lineno = 2
        cmt2.left = False
        cmt2.draft = True
        cmt2.author = self.student_acc.user
        cmt2.save()
        # Add fake content
        content1 = models.Content(text="foo\nbar\nbaz\nline\n")
        content1.put()
        content2 = models.Content(text="foo\nbar\nbaz\nline\n")
        content2.put()
        cmt1.patch.content = content1
        cmt1.patch.put()
        cmt2.patch.content = content2
        cmt2.patch.put()
        # Mock get content calls. The first fails with an FetchError,
        # the second succeeds (see issue384).
        def raise_err():
            raise models.FetchError()
        cmt1.patch.get_content = raise_err
        cmt2.patch.get_patched_content = lambda: content2
        tbd, comments = views._get_draft_comments(request, self.issue)
        self.assertEqual(len(comments), 2)
        # Try to render draft details using the patched Comment
        # instances from here.
        views._get_draft_details(request, [cmt1, cmt2])

        self.logout()
Exemplo n.º 5
0
def publish(request):
    """/<issue>/publish - Publish draft comments and send mail."""
    issue = request.issue
    case_id = get_case_id(request.issue)
    form_class = PublishForm
    draft_message = None
    if not request.POST.get('message_only', None):
        query = models.Message.gql(('WHERE issue = :1 AND sender = :2 '
                                    'AND draft = TRUE'), issue,
                                   request.user.email())
        draft_message = query.get()
    if request.method != 'POST':
        reviewers = issue.reviewers[:]
        cc = issue.cc[:] + [settings.DEFAULT_MAIL_CC]
        if request.user != issue.owner and (request.user.email()
                                            not in issue.reviewers):
            reviewers.append(request.user.email())
            if request.user.email() in cc:
                cc.remove(request.user.email())
        reviewers = [models.Account.get_nickname_for_email(reviewer,
                                                           default=reviewer)
                     for reviewer in reviewers]
        ccs = set([models.Account.get_nickname_for_email(email, default=email) for email in cc])
        tbd, comments = views._get_draft_comments(request, issue, True)
        preview = views._get_draft_details(request, comments)
        if draft_message is None:
            msg = ''
        else:
            msg = draft_message.text

        form = form_class(case_id, initial={
            'subject': issue.subject[:views.MAX_SUBJECT],
            'reviewers': ', '.join(reviewers),
            'cc': ', '.join(ccs),
            'send_mail': True,
            'tags': ['peer-reviewed'],
            'message': msg,
        })
        return views.respond(
            request, 'publish.html', {
                'form': form,
                'issue': issue,
                'preview': preview,
                'draft_message': draft_message,
                'case_id': case_id
            })

    form = form_class(case_id, request.POST)
    if not form.is_valid():
        return views.respond(request, 'publish.html', {'form': form, 'issue': issue})
    issue.subject = form.cleaned_data['subject']
    if form.is_valid() and not form.cleaned_data.get('message_only', False):
        reviewers = views._get_emails(form, 'reviewers')
    else:
        reviewers = issue.reviewers
        if request.user != issue.owner and request.user.email() not in reviewers:
            reviewers.append(db.Email(request.user.email()))
    if form.is_valid() and not form.cleaned_data.get('message_only', False):
        cc = views._get_emails(form, 'cc')
    else:
        cc = issue.cc
        # The user is in the reviewer list, remove them from CC if they're
        # there.
        if request.user.email() in cc:
            cc.remove(request.user.email())
    if not form.is_valid():
        return views.respond(request, 'publish.html', {'form': form, 'issue': issue})
    issue.reviewers = reviewers
    issue.cc = cc
    if not form.cleaned_data.get('message_only', False):
        tbd, comments = views._get_draft_comments(request, issue)
    else:
        tbd = []
        comments = []
    issue.update_comment_count(len(comments))
    tbd.append(issue)

    if comments:
        logging.warn('Publishing %d comments', len(comments))

    assign_to = form.cleaned_data.get('assign_to', None)

    msg = views._make_message(
        request, issue,
        form.cleaned_data['message'],
        comments,
        not assign_to and form.cleaned_data['send_mail'],
        draft=draft_message
    )
    tbd.append(msg)

    for obj in tbd:
        db.put(obj)
    measurements.measure_comments_per_user(request, issue)

    views._notify_issue(request, issue, 'Comments published')

    if assign_to:
        fogbugz_assign_case(request, case_id, assign_to, msg.text, form.cleaned_data['tags'])

    # There are now no comments here (modulo race conditions)
    models.Account.current_user_account.update_drafts(issue, 0)
    if form.cleaned_data.get('no_redirect', False):
        return HttpResponse('OK', content_type='text/plain')
    return HttpResponseRedirect(reverse(views.show, args=[issue.key().id()]))