Beispiel #1
0
    def test_delete_all_comments(self):
        comments.add_comment([self.execution], "Hello World!", self.user)
        comments.add_comment([self.execution], "More comments", self.user)
        self.rpc_client.TestExecution.remove_comment(self.execution.pk)

        result = comments.get_comments(self.execution)
        self.assertEqual(result.count(), 0)
Beispiel #2
0
    def _fixture_setup(self):
        super()._fixture_setup()

        self.execution = TestExecutionFactory()
        self.comments = ["Text for first comment", "Text for second comment"]

        for comment in self.comments:
            comments.add_comment([self.execution], comment, self.tester)
Beispiel #3
0
 def _record_changes(self, new_data):
     result = ""
     for field in self.fields:
         if self._values_before_update[field] != new_data[field]:
             result += "%s: %s -> %s\n" % (field.title(
             ), self._values_before_update[field], new_data[field])
     if result:
         add_comment([self.object], result, self.request.user)
Beispiel #4
0
    def form_valid(self, form):
        response = super().form_valid(form)

        if not self.object.assignee:
            self.object.assignee = New.find_assignee(self.request.POST)
            self.object.save()
        add_comment([self.object], form.cleaned_data['text'], self.request.user)

        return response
Beispiel #5
0
    def test_delete_one_comment(self):
        comments.add_comment([self.execution], "Hello World!", self.user)
        comment_2 = comments.add_comment([self.execution], "More comments", self.user)
        comment_2 = model_to_dict(comment_2[0])

        self.rpc_client.TestExecution.remove_comment(self.execution.pk, comment_2["id"])
        result = comments.get_comments(self.execution)
        first_comment = result.first()

        self.assertEqual(result.count(), 1)
        self.assertEqual("Hello World!", first_comment.comment)
Beispiel #6
0
    def setUpTestData(cls):
        super(TestGetCaseRunsComments, cls).setUpTestData()

        cls.submit_date = datetime(2017, 7, 7, 7, 7, 7)

        add_comment([cls.case_run_4, cls.case_run_5],
                    comments='new comment',
                    user=cls.tester,
                    submit_date=cls.submit_date)
        add_comment([cls.case_run_4],
                    comments='make better',
                    user=cls.tester,
                    submit_date=cls.submit_date)
Beispiel #7
0
def comment_case_runs(request):
    '''
    Add comment to one or more caseruns at a time.
    '''
    data    = request.REQUEST.copy()
    comment = data.get('comment', None)
    if not comment: return say_no('Comments needed')
    run_ids = [i for i in data.get('run', '').split(',') if i]
    if not run_ids: return say_no('No runs selected.');
    runs    = TestCaseRun.objects.filter(pk__in=run_ids)
    if not runs: return say_no('No caserun found.')
    add_comment(runs, comment, request.user)
    return say_yes()
Beispiel #8
0
 def _record_changes(self, new_data):
     result = ""
     for field in self.model._meta.fields:
         field = field.name
         if (
             field in new_data
             and self._values_before_update[field] != new_data[field]
         ):
             _before_update = self._values_before_update[field]
             _after_update = new_data[field]
             result += f"{field.title()}: {_before_update} -> {_after_update}\n"
     if result:
         add_comment([self.object], result, self.request.user)
Beispiel #9
0
 def _record_changes(self, new_data):
     result = ""
     for field in self.model._meta.fields:
         field = field.name
         if (field in new_data
                 and self._values_before_update[field] != new_data[field]):
             result += "%s: %s -> %s\n" % (
                 field.title(),
                 self._values_before_update[field],
                 new_data[field],
             )
     if result:
         add_comment([self.object], result, self.request.user)
Beispiel #10
0
    def setUpTestData(cls):
        super().setUpTestData()

        cls.submit_date = datetime(2017, 7, 7, 7, 7, 7)

        add_comment([cls.execution_4, cls.execution_5],
                    comments='new comment',
                    user=cls.tester,
                    submit_date=cls.submit_date)
        add_comment([cls.execution_4],
                    comments='make better',
                    user=cls.tester,
                    submit_date=cls.submit_date)
Beispiel #11
0
    def setUpTestData(cls):
        super(TestGetCaseRunsComments, cls).setUpTestData()

        cls.submit_date = datetime(2017, 7, 7, 7, 7, 7)

        add_comment([cls.case_run_4, cls.case_run_5],
                    comments='new comment',
                    user=cls.tester,
                    submit_date=cls.submit_date)
        add_comment([cls.case_run_4],
                    comments='make better',
                    user=cls.tester,
                    submit_date=cls.submit_date)
Beispiel #12
0
    def post(self, request, *args, **kwargs):
        form = BugCommentForm(request.POST)

        if form.is_valid():
            bug = form.cleaned_data['bug']
            if form.cleaned_data['text']:
                add_comment([bug], form.cleaned_data['text'], request.user)

            if request.POST.get('action') == 'close':
                bug.status = False
                bug.save()
                add_comment([bug], _('*bug closed*'), request.user)

        return HttpResponseRedirect(reverse('bugs-get', args=[bug.pk]))
Beispiel #13
0
def add_comment(execution_id, comment, **kwargs):
    """
    .. function:: XML-RPC TestExecution.add_comment(execution_id, comment)

        Add comment to selected test execution.

        :param execution_id: PK of a TestExecution object
        :param execution_id: int
        :param comment: The text to add as a comment
        :param comment: str
        :return: None or JSON string in case of errors
    """
    execution = TestExecution.objects.get(pk=execution_id)
    comments.add_comment([execution], comment, kwargs.get(REQUEST_KEY).user)
Beispiel #14
0
def add_comment(execution_id, comment, **kwargs):
    """
    .. function:: RPC TestExecution.add_comment(execution_id, comment)

        Add comment to selected test execution.

        :param execution_id: PK of a TestExecution object
        :type execution_id: int
        :param comment: The text to add as a comment
        :type comment: str
        :param kwargs: Dict providing access to the current request, protocol
                entry point name and handler instance from the rpc method
        :raises PermissionDenied: if missing *django_comments.add_comment* permission
    """
    execution = TestExecution.objects.get(pk=execution_id)
    comments.add_comment([execution], comment, kwargs.get(REQUEST_KEY).user)
Beispiel #15
0
def comment_case_runs(request):
    '''
    Add comment to one or more caseruns at a time.
    '''
    data = request.REQUEST.copy()
    comment = data.get('comment', None)
    if not comment:
        return say_no('Comments needed')
    run_ids = [i for i in data.get('run', '').split(',') if i]
    if not run_ids:
        return say_no('No runs selected.')
    runs = TestCaseRun.objects.filter(pk__in=run_ids).only('pk')
    if not runs:
        return say_no('No caserun found.')
    add_comment(runs, comment, request.user)
    return say_yes()
Beispiel #16
0
    def test_add_comment_to_case(self):
        cases = [self.case_1, self.case_2]
        add_comment(cases, 'new comment', self.reviewer)

        for case in cases:
            case_ct = ContentType.objects.get_for_model(case.__class__)
            comments = Comment.objects.filter(content_type=case_ct,
                                              object_pk=case.pk)
            self.assertEqual(1, len(comments))

            comment = comments[0]
            self.assertEqual('new comment', comment.comment)
            self.assertEqual(self.reviewer, comment.user)
            self.assertEqual(self.reviewer.username, comment.user_name)
            self.assertEqual(self.reviewer.email, comment.user_email)
            self.assertTrue(comment.is_public)
            self.assertFalse(comment.is_removed)
Beispiel #17
0
    def test_add_comment_to_case(self):
        cases = [self.case_1, self.case_2]
        add_comment(cases, 'new comment', self.reviewer)

        for case in cases:
            case_ct = ContentType.objects.get_for_model(case.__class__)
            comments = Comment.objects.filter(content_type=case_ct,
                                              object_pk=case.pk)
            self.assertEqual(1, len(comments))

            comment = comments[0]
            self.assertEqual('new comment', comment.comment)
            self.assertEqual(self.reviewer, comment.user)
            self.assertEqual(self.reviewer.username, comment.user_name)
            self.assertEqual(self.reviewer.email, comment.user_email)
            self.assertTrue(comment.is_public)
            self.assertFalse(comment.is_removed)
Beispiel #18
0
def comment_case_runs(request):
    """
    Add comment to one or more caseruns at a time.
    """
    data = request.POST.copy()
    comment = data.get('comment', None)
    if not comment:
        return say_no('Comments needed')
    run_ids = []
    for run_id in data.get('run', '').split(','):
        if run_id:
            run_ids.append(run_id)
    if not run_ids:
        return say_no('No runs selected.')
    runs = TestExecution.objects.filter(pk__in=run_ids).only('pk')
    if not runs:
        return say_no('No caserun found.')
    add_comment(runs, comment, request.user)
    return say_yes()
Beispiel #19
0
    def create_bug(data):
        """
        Helper method used within Issue Tracker integration.

        :param data: Untrusted input, usually via HTTP request
        :type data: dict
        :return: bug
        :rtype: Model
        """
        bug = None

        if "assignee" not in data or not data["assignee"]:
            data["assignee"] = New.find_assignee(data)

        text = data["text"]
        del data["text"]

        bug = Bug.objects.create(**data)
        add_comment([bug], text, bug.reporter)

        return bug
Beispiel #20
0
    def test_email_sent_to_all_commenters(self, send_mail):
        bug = BugFactory(assignee=self.assignee, reporter=self.tester)
        commenter = UserFactory()
        tracker = UserFactory()
        add_comment([bug], _("*bug created*"), tracker)
        add_comment([bug], _("*bug created*"), commenter)

        expected_body = render_to_string(
            "email/post_bug_save/email.txt",
            {
                "bug": bug,
                "comment": get_comments(bug).last()
            },
        )
        expected_recipients = [
            self.assignee.email,
            self.tester.email,
            commenter.email,
            tracker.email,
        ]
        expected_recipients.sort()

        expected_subject = _("Bug #%(pk)d - %(summary)s") % {
            "pk": bug.pk,
            "summary": bug.summary,
        }

        self.assertTrue(send_mail.called)
        self.assertEqual(
            settings.EMAIL_SUBJECT_PREFIX + expected_subject,
            send_mail.call_args.args[0],
        )
        self.assertEqual(expected_body, send_mail.call_args.args[1])
        self.assertEqual(settings.DEFAULT_FROM_EMAIL,
                         send_mail.call_args.args[2])
        self.assertTrue(
            len(send_mail.call_args.args[3]) == len(expected_recipients))
        self.assertIn(expected_recipients[0], send_mail.call_args.args[3])
        self.assertIn(expected_recipients[1], send_mail.call_args.args[3])
Beispiel #21
0
def add_comment(execution_id, comment, **kwargs):
    """
    .. function:: RPC TestExecution.add_comment(execution_id, comment)

        Add comment to selected test execution.

        :param execution_id: PK of a TestExecution object
        :type execution_id: int
        :param comment: The text to add as a comment
        :type comment: str
        :param kwargs: Dict providing access to the current request, protocol
                entry point name and handler instance from the rpc method
        :return: Serialized :class:`django_comments.models.Comment` object
        :rtype: dict
        :raises PermissionDenied: if missing *django_comments.add_comment* permission
    """
    execution = TestExecution.objects.get(pk=execution_id)
    created = comments.add_comment([execution], comment, kwargs.get(REQUEST_KEY).user)
    # we always create only one comment
    return model_to_dict(created[0])
Beispiel #22
0
    def post(self, request):
        form = BugCommentForm(request.POST)
        request_action = request.POST.get("action")

        if form.is_valid():
            bug = form.cleaned_data["bug"]
            if form.cleaned_data["text"]:
                add_comment([bug], form.cleaned_data["text"], request.user)

            if request_action == "close":
                bug.status = False
                add_comment([bug], _("*bug closed*"), request.user)

            if request_action == "reopen":
                bug.status = True
                add_comment([bug], _("*bug reopened*"), request.user)
            bug.save()

        return HttpResponseRedirect(reverse("bugs-get", args=[bug.pk]))
Beispiel #23
0
    def post(self, request):
        form = BugCommentForm(request.POST)
        request_action = request.POST.get('action')

        if form.is_valid():
            bug = form.cleaned_data['bug']
            if form.cleaned_data['text']:
                add_comment([bug], form.cleaned_data['text'], request.user)
                post_save.send(instance=bug, sender=bug.__class__)

            if request_action == 'close':
                bug.status = False
                add_comment([bug], _('*bug closed*'), request.user)

            if request_action == 'reopen':
                bug.status = True
                add_comment([bug], _('*bug reopened*'), request.user)
            bug.save()

        return HttpResponseRedirect(reverse('bugs-get', args=[bug.pk]))
Beispiel #24
0
    def verify_api_without_permission(self):
        comments.add_comment([self.execution], "Hello World!", self.user)

        with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):
            self.rpc_client.TestExecution.remove_comment(self.execution.pk)
Beispiel #25
0
    def verify_api_with_permission(self):
        comments.add_comment([self.execution], "Hello World!", self.user)
        self.rpc_client.TestExecution.remove_comment(self.execution.pk)

        result = comments.get_comments(self.execution)
        self.assertEqual(result.count(), 0)