Ejemplo n.º 1
0
    def _test_put_with_text_type_escaping_all_fields(
            self, text_type, text, expected_text):
        self.assertIn(text_type, ('markdown', 'plain'))
        rich_text = (text_type == 'markdown')

        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)
        review_request.rich_text = not rich_text
        review_request.description = text
        review_request.testing_done = text
        review_request.save()

        draft = ReviewRequestDraft.create(review_request)
        draft.changedesc.text = text
        draft.changedesc.save()

        rsp = self.apiPut(
            get_review_request_draft_url(review_request),
            {
                'text_type': text_type,
            },
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        draft_rsp = rsp['draft']
        self.assertEqual(draft_rsp['text_type'], text_type)
        self.assertEqual(draft_rsp['changedescription'], expected_text)
        self.assertEqual(draft_rsp['description'], expected_text)
        self.assertEqual(draft_rsp['testing_done'], expected_text)

        draft = ReviewRequestDraft.objects.get(pk=rsp['draft']['id'])
        self.compare_item(draft_rsp, draft)
    def setup_basic_get_test(self, user, with_local_site, local_site_name):
        review_request = self.create_review_request(
            with_local_site=with_local_site, submitter=user, publish=True)
        draft = ReviewRequestDraft.create(review_request)

        return (get_review_request_draft_url(review_request, local_site_name),
                review_request_draft_item_mimetype, draft)
    def test_put_reviewrequestdraft_with_depends_on_and_site(self):
        """Testing the PUT review-requests/<id>/draft/ API with depends_on field and local site"""
        review_request = self.create_review_request(submitter='doc',
                                                    with_local_site=True)

        self._login_user(local_site=True)

        depends_1 = self.create_review_request(
            with_local_site=True,
            submitter=self.user,
            summary='Test review request',
            local_id=3,
            publish=True)

        # This isn't the review request we want to match.
        bad_depends = self.create_review_request(id=3, publish=True)

        rsp = self.apiPut(
            get_review_request_draft_url(review_request, self.local_site_name),
            {'depends_on': '3'},
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        depends_on = rsp['draft']['depends_on']
        self.assertEqual(len(depends_on), 1)
        self.assertNotEqual(rsp['draft']['depends_on'][0]['title'],
                            bad_depends.summary)
        self.assertEqual(rsp['draft']['depends_on'][0]['title'],
                         depends_1.summary)

        draft = ReviewRequestDraft.objects.get(pk=rsp['draft']['id'])
        self.assertEqual(list(draft.depends_on.all()), [depends_1])
        self.assertEqual(list(depends_1.draft_blocks.all()), [draft])
        self.assertEqual(bad_depends.draft_blocks.count(), 0)
    def test_put_without_text_type_and_escaping_provided_fields(self):
        """Testing the PUT review-requests/<id>/draft/ API
        without changing text_type and with escaping provided fields
        """
        review_request = self.create_review_request(submitter=self.user, publish=True)
        review_request.rich_text = True
        review_request.save()

        draft = ReviewRequestDraft.create(review_request)

        self.assertTrue(draft.rich_text)
        self.assertTrue(draft.changedesc.rich_text)

        rsp = self.api_put(
            get_review_request_draft_url(review_request),
            {
                "description": "This is **Description**",
                "testing_done": "This is **Testing Done**",
                "changedescription": "This is **Change Description**",
            },
            expected_mimetype=review_request_draft_item_mimetype,
        )

        self.assertEqual(rsp["stat"], "ok")

        draft_rsp = rsp["draft"]
        self.assertEqual(draft_rsp["text_type"], "markdown")
        self.assertEqual(draft_rsp["description"], "This is \*\*Description\*\*")
        self.assertEqual(draft_rsp["testing_done"], "This is \*\*Testing Done\*\*")
        self.assertEqual(draft_rsp["changedescription"], "This is \*\*Change Description\*\*")

        draft = ReviewRequestDraft.objects.get(pk=rsp["draft"]["id"])
        self.compare_item(draft_rsp, draft)
    def test_put_publish_with_new_review_request(self):
        """Testing the PUT review-requests/<id>/draft/?public=1 API
        with a new review request
        """
        self.siteconfig.set('mail_send_review_mail', True)
        self.siteconfig.save()

        # Set some data first.
        review_request = self.create_review_request(submitter=self.user)
        review_request.target_people = [
            User.objects.get(username='******')
        ]
        review_request.save()

        self._create_update_review_request(self.api_put, 200, review_request)

        rsp = self.api_put(
            get_review_request_draft_url(review_request),
            {'public': True},
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        review_request = ReviewRequest.objects.get(pk=review_request.id)
        self.assertEqual(review_request.summary, "My Summary")
        self.assertEqual(review_request.description, "My Description")
        self.assertEqual(review_request.testing_done, "My Testing Done")
        self.assertEqual(review_request.branch, "My Branch")
        self.assertTrue(review_request.public)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject,
                         "Review Request %s: My Summary" % review_request.pk)
        self.assertValidRecipients(["doc", "grumpy"], [])
Ejemplo n.º 6
0
    def test_post_with_publish_and_custom_field(self):
        """Testing the POST review-requests/<id>/draft/ API with custom
        field set in same request and public=1
        """
        class CustomField(BaseReviewRequestField):
            can_record_change_entry = True
            field_id = 'my-test'

        fieldset = get_review_request_fieldset('info')
        fieldset.add_field(CustomField)

        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)

        rsp = self.api_post(
            get_review_request_draft_url(review_request), {
                'extra_data.my-test': 123,
                'public': True
            },
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        review_request = ReviewRequest.objects.get(pk=review_request.id)
        self.assertIn('my-test', review_request.extra_data)
        self.assertEqual(review_request.extra_data['my-test'], 123)
        self.assertTrue(review_request.public)
    def test_get_or_create_user_auth_backend(self):
        """Testing the PUT review-requests/<id>/draft/ API
        with AuthBackend.get_or_create_user failure
        """
        class SandboxAuthBackend(AuthBackend):
            backend_id = 'test-id'
            name = 'test'

            def get_or_create_user(self, username, request=None,
                                   password=None):
                raise Exception

        backend = SandboxAuthBackend()

        self.spy_on(auth.get_backends, call_fake=lambda: [backend])

        # The first spy messes with permissions, this lets it through
        self.spy_on(ReviewRequest.is_mutable_by, call_fake=lambda x, y: True)
        self.spy_on(backend.get_or_create_user)

        review_request = self.create_review_request(
            submitter=self.user)

        ReviewRequestDraft.create(review_request)

        rsp = self.api_put(
            get_review_request_draft_url(review_request, None),
            {
                'target_people': 'Target',
            },
            expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertTrue(backend.get_or_create_user.called)
    def test_put_with_depends_on(self):
        """Testing the PUT review-requests/<id>/draft/ API
        with depends_on field
        """
        review_request = self.create_review_request(submitter=self.user, publish=True)

        depends_1 = self.create_review_request(summary="Dependency 1", publish=True)
        depends_2 = self.create_review_request(summary="Dependency 2", publish=True)

        rsp = self.apiPut(
            get_review_request_draft_url(review_request),
            {"depends_on": "%s, %s" % (depends_1.pk, depends_2.pk)},
            expected_mimetype=review_request_draft_item_mimetype,
        )

        self.assertEqual(rsp["stat"], "ok")

        depends_on = rsp["draft"]["depends_on"]
        self.assertEqual(len(depends_on), 2)
        depends_on.sort(key=lambda x: x["title"])
        self.assertEqual(depends_on[0]["title"], depends_1.summary)
        self.assertEqual(depends_on[1]["title"], depends_2.summary)

        draft = ReviewRequestDraft.objects.get(pk=rsp["draft"]["id"])
        self.assertEqual(list(draft.depends_on.order_by("pk")), [depends_1, depends_2])
        self.assertEqual(list(depends_1.draft_blocks.all()), [draft])
        self.assertEqual(list(depends_2.draft_blocks.all()), [draft])
    def test_put_reviewrequestdraft_publish(self):
        """Testing the PUT review-requests/<id>/draft/?public=1 API"""
        self.siteconfig.set('mail_send_review_mail', True)
        self.siteconfig.save()

        # Set some data first.
        self.test_put_reviewrequestdraft()

        mail.outbox = []

        review_request = ReviewRequest.objects.from_user(self.user.username)[0]

        rsp = self.apiPut(
            get_review_request_draft_url(review_request),
            {'public': True},
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        review_request = ReviewRequest.objects.get(pk=review_request.id)
        self.assertEqual(review_request.summary, "My Summary")
        self.assertEqual(review_request.description, "My Description")
        self.assertEqual(review_request.testing_done, "My Testing Done")
        self.assertEqual(review_request.branch, "My Branch")
        self.assertTrue(review_request.public)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject,
                         "Review Request %s: My Summary" % review_request.pk)
        self.assertValidRecipients(["doc", "grumpy"])
Ejemplo n.º 10
0
    def _test_put_with_text_type_all_fields(self, text_type):
        text = '`This` is a **test**'

        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)

        rsp = self.api_put(
            get_review_request_draft_url(review_request),
            {
                'text_type': text_type,
                'changedescription': text,
                'description': text,
                'testing_done': text,
            },
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        draft_rsp = rsp['draft']
        self.assertEqual(draft_rsp['text_type'], text_type)
        self.assertEqual(draft_rsp['changedescription'], text)
        self.assertEqual(draft_rsp['description'], text)
        self.assertEqual(draft_rsp['testing_done'], text)

        draft = ReviewRequestDraft.objects.get(pk=rsp['draft']['id'])
        self.compare_item(draft_rsp, draft)
Ejemplo n.º 11
0
    def _test_put_with_text_type_escaping_all_fields(
            self, text_type, text, expected_text):
        self.assertIn(text_type, ('markdown', 'plain'))
        rich_text = (text_type == 'markdown')

        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)
        review_request.rich_text = not rich_text
        review_request.description = text
        review_request.testing_done = text
        review_request.save()

        draft = ReviewRequestDraft.create(review_request)
        draft.changedesc.text = text
        draft.changedesc.save()

        rsp = self.api_put(
            get_review_request_draft_url(review_request),
            {
                'text_type': text_type,
            },
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        draft_rsp = rsp['draft']
        self.assertEqual(draft_rsp['text_type'], text_type)
        self.assertEqual(draft_rsp['changedescription'], expected_text)
        self.assertEqual(draft_rsp['description'], expected_text)
        self.assertEqual(draft_rsp['testing_done'], expected_text)

        draft = ReviewRequestDraft.objects.get(pk=rsp['draft']['id'])
        self.compare_item(draft_rsp, draft)
    def test_put_with_depends_on(self):
        """Testing the PUT review-requests/<id>/draft/ API
        with depends_on field
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)

        depends_1 = self.create_review_request(
            summary='Dependency 1',
            publish=True)
        depends_2 = self.create_review_request(
            summary='Dependency 2',
            publish=True)

        rsp = self.api_put(
            get_review_request_draft_url(review_request),
            {'depends_on': '%s, %s' % (depends_1.pk, depends_2.pk)},
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        depends_on = rsp['draft']['depends_on']
        self.assertEqual(len(depends_on), 2)
        depends_on.sort(key=lambda x: x['title'])
        self.assertEqual(depends_on[0]['title'], depends_1.summary)
        self.assertEqual(depends_on[1]['title'], depends_2.summary)

        draft = ReviewRequestDraft.objects.get(pk=rsp['draft']['id'])
        self.assertEqual(list(draft.depends_on.order_by('pk')),
                         [depends_1, depends_2])
        self.assertEqual(list(depends_1.draft_blocks.all()), [draft])
        self.assertEqual(list(depends_2.draft_blocks.all()), [draft])
    def test_post_with_publish_and_custom_field(self):
        """Testing the POST review-requests/<id>/draft/ API with custom
        field set in same request and public=1
        """
        class CustomField(BaseReviewRequestField):
            can_record_change_entry = True
            field_id = 'my-test'

        fieldset = get_review_request_fieldset('info')
        fieldset.add_field(CustomField)

        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)

        rsp = self.api_post(
            get_review_request_draft_url(review_request),
            {
                'extra_data.my-test': 123,
                'public': True
            },
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        review_request = ReviewRequest.objects.get(pk=review_request.id)
        self.assertIn('my-test', review_request.extra_data)
        self.assertEqual(review_request.extra_data['my-test'], 123)
        self.assertTrue(review_request.public)
    def _test_put_with_text_type_escaping_unspecified_fields(self, text_type, text, expected_text):
        self.assertIn(text_type, ("markdown", "plain"))
        rich_text = text_type == "markdown"

        description = "`This` is the **description**"

        review_request = self.create_review_request(submitter=self.user, publish=True)
        review_request.rich_text = not rich_text
        review_request.description = text
        review_request.testing_done = text
        review_request.save()

        draft = ReviewRequestDraft.create(review_request)
        draft.changedesc.text = text
        draft.changedesc.save()

        rsp = self.api_put(
            get_review_request_draft_url(review_request),
            {"text_type": text_type, "description": description},
            expected_mimetype=review_request_draft_item_mimetype,
        )

        self.assertEqual(rsp["stat"], "ok")

        draft_rsp = rsp["draft"]
        self.assertEqual(draft_rsp["text_type"], text_type)
        self.assertEqual(draft_rsp["changedescription"], expected_text)
        self.assertEqual(draft_rsp["description"], description)
        self.assertEqual(draft_rsp["testing_done"], expected_text)

        draft = ReviewRequestDraft.objects.get(pk=rsp["draft"]["id"])
        self.compare_item(draft_rsp, draft)
    def setup_basic_delete_test(self, user, with_local_site, local_site_name):
        review_request = self.create_review_request(
            with_local_site=with_local_site, submitter=user, publish=True)
        ReviewRequestDraft.create(review_request)

        return (get_review_request_draft_url(review_request, local_site_name),
                [review_request])
Ejemplo n.º 16
0
    def test_put_without_text_type_and_escaping_provided_fields(self):
        """Testing the PUT review-requests/<id>/draft/ API
        without changing text_type and with escaping provided fields
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)
        review_request.rich_text = True
        review_request.save()

        draft = ReviewRequestDraft.create(review_request)

        self.assertTrue(draft.rich_text)
        self.assertTrue(draft.changedesc.rich_text)

        rsp = self.api_put(
            get_review_request_draft_url(review_request), {
                'description': 'This is **Description**',
                'testing_done': 'This is **Testing Done**',
                'changedescription': 'This is **Change Description**',
            },
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        draft_rsp = rsp['draft']
        self.assertEqual(draft_rsp['text_type'], 'markdown')
        self.assertEqual(draft_rsp['description'],
                         'This is \*\*Description\*\*')
        self.assertEqual(draft_rsp['testing_done'],
                         'This is \*\*Testing Done\*\*')
        self.assertEqual(draft_rsp['changedescription'],
                         'This is \*\*Change Description\*\*')

        draft = ReviewRequestDraft.objects.get(pk=rsp['draft']['id'])
        self.compare_item(draft_rsp, draft)
Ejemplo n.º 17
0
    def test_put_publish(self):
        """Testing the PUT review-requests/<id>/draft/?public=1 API"""
        self.siteconfig.set('mail_send_review_mail', True)
        self.siteconfig.save()

        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)
        draft = ReviewRequestDraft.create(review_request)
        draft.summary = 'My Summary'
        draft.description = 'My Description'
        draft.testing_done = 'My Testing Done'
        draft.branch = 'My Branch'
        draft.target_people.add(User.objects.get(username='******'))
        draft.save()

        mail.outbox = []

        rsp = self.api_put(
            get_review_request_draft_url(review_request), {'public': True},
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        review_request = ReviewRequest.objects.get(pk=review_request.id)
        self.assertEqual(review_request.summary, "My Summary")
        self.assertEqual(review_request.description, "My Description")
        self.assertEqual(review_request.testing_done, "My Testing Done")
        self.assertEqual(review_request.branch, "My Branch")
        self.assertTrue(review_request.public)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(
            mail.outbox[0].subject,
            "Re: Review Request %s: My Summary" % review_request.pk)
        self.assertValidRecipients(["doc", "grumpy"])
    def test_put_with_depends_on_and_site(self):
        """Testing the PUT review-requests/<id>/draft/ API
        with depends_on field and local site
        """
        review_request = self.create_review_request(submitter="doc", with_local_site=True)

        self._login_user(local_site=True)

        depends_1 = self.create_review_request(
            with_local_site=True, submitter=self.user, summary="Test review request", local_id=3, publish=True
        )

        # This isn't the review request we want to match.
        bad_depends = self.create_review_request(id=3, publish=True)

        rsp = self.apiPut(
            get_review_request_draft_url(review_request, self.local_site_name),
            {"depends_on": "3"},
            expected_mimetype=review_request_draft_item_mimetype,
        )

        self.assertEqual(rsp["stat"], "ok")

        depends_on = rsp["draft"]["depends_on"]
        self.assertEqual(len(depends_on), 1)
        self.assertNotEqual(rsp["draft"]["depends_on"][0]["title"], bad_depends.summary)
        self.assertEqual(rsp["draft"]["depends_on"][0]["title"], depends_1.summary)

        draft = ReviewRequestDraft.objects.get(pk=rsp["draft"]["id"])
        self.assertEqual(list(draft.depends_on.all()), [depends_1])
        self.assertEqual(list(depends_1.draft_blocks.all()), [draft])
        self.assertEqual(bad_depends.draft_blocks.count(), 0)
    def test_put_publish(self):
        """Testing the PUT review-requests/<id>/draft/?public=1 API"""
        self.siteconfig.set('mail_send_review_mail', True)
        self.siteconfig.save()

        # Set some data first.
        self.test_put()

        mail.outbox = []

        review_request = ReviewRequest.objects.from_user(self.user.username)[0]

        rsp = self.apiPut(
            get_review_request_draft_url(review_request),
            {'public': True},
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        review_request = ReviewRequest.objects.get(pk=review_request.id)
        self.assertEqual(review_request.summary, "My Summary")
        self.assertEqual(review_request.description, "My Description")
        self.assertEqual(review_request.testing_done, "My Testing Done")
        self.assertEqual(review_request.branch, "My Branch")
        self.assertTrue(review_request.public)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(
            mail.outbox[0].subject,
            "Re: Review Request %s: My Summary" % review_request.pk)
        self.assertValidRecipients(["doc", "grumpy"])
    def test_put_with_commit_id_and_used_in_draft(self):
        """Testing the PUT review-requests/<id>/draft/ API with commit_id
        used in another review request draft
        """
        commit_id = 'abc123'

        existing_review_request = self.create_review_request(
            submitter=self.user,
            publish=True)
        existing_draft = ReviewRequestDraft.create(existing_review_request)
        existing_draft.commit_id = commit_id
        existing_draft.save()

        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)

        self.api_put(
            get_review_request_draft_url(review_request),
            {
                'commit_id': commit_id,
            },
            expected_status=409)

        review_request = ReviewRequest.objects.get(pk=review_request.pk)
        self.assertIsNone(review_request.commit_id, None)
    def _test_put_with_rich_text_escaping_unspecified_fields(
            self, rich_text, text, expected_text):

        description = '`This` is the **description**'

        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)
        review_request.rich_text = not rich_text
        review_request.description = text
        review_request.testing_done = text
        review_request.save()

        draft = ReviewRequestDraft.create(review_request)
        draft.changedesc.text = text
        draft.changedesc.save()

        rsp = self.apiPut(
            get_review_request_draft_url(review_request),
            {
                'rich_text': rich_text,
                'description': description,
            },
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        draft_rsp = rsp['draft']
        self.assertEqual(draft_rsp['rich_text'], rich_text)
        self.assertEqual(draft_rsp['changedescription'], expected_text)
        self.assertEqual(draft_rsp['description'], description)
        self.assertEqual(draft_rsp['testing_done'], expected_text)

        draft = ReviewRequestDraft.objects.get(pk=rsp['draft']['id'])
        self.compare_item(draft_rsp, draft)
    def test_put_publish(self):
        """Testing the PUT review-requests/<id>/draft/?public=1 API"""
        self.siteconfig.set("mail_send_review_mail", True)
        self.siteconfig.save()

        review_request = self.create_review_request(submitter=self.user, publish=True)
        draft = ReviewRequestDraft.create(review_request)
        draft.summary = "My Summary"
        draft.description = "My Description"
        draft.testing_done = "My Testing Done"
        draft.branch = "My Branch"
        draft.target_people.add(User.objects.get(username="******"))
        draft.save()

        mail.outbox = []

        rsp = self.apiPut(
            get_review_request_draft_url(review_request),
            {"public": True},
            expected_mimetype=review_request_draft_item_mimetype,
        )

        self.assertEqual(rsp["stat"], "ok")

        review_request = ReviewRequest.objects.get(pk=review_request.id)
        self.assertEqual(review_request.summary, "My Summary")
        self.assertEqual(review_request.description, "My Description")
        self.assertEqual(review_request.testing_done, "My Testing Done")
        self.assertEqual(review_request.branch, "My Branch")
        self.assertTrue(review_request.public)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject, "Re: Review Request %s: My Summary" % review_request.pk)
        self.assertValidRecipients(["doc", "grumpy"])
Ejemplo n.º 23
0
    def test_put_with_depends_on(self):
        """Testing the PUT review-requests/<id>/draft/ API
        with depends_on field
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)

        depends_1 = self.create_review_request(summary='Dependency 1',
                                               publish=True)
        depends_2 = self.create_review_request(summary='Dependency 2',
                                               publish=True)

        rsp = self.api_put(
            get_review_request_draft_url(review_request),
            {'depends_on': '%s, %s' % (depends_1.pk, depends_2.pk)},
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        depends_on = rsp['draft']['depends_on']
        self.assertEqual(len(depends_on), 2)
        depends_on.sort(key=lambda x: x['title'])
        self.assertEqual(depends_on[0]['title'], depends_1.summary)
        self.assertEqual(depends_on[1]['title'], depends_2.summary)

        draft = ReviewRequestDraft.objects.get(pk=rsp['draft']['id'])
        self.assertEqual(list(draft.depends_on.order_by('pk')),
                         [depends_1, depends_2])
        self.assertEqual(list(depends_1.draft_blocks.all()), [draft])
        self.assertEqual(list(depends_2.draft_blocks.all()), [draft])
Ejemplo n.º 24
0
    def _test_put_with_text_type_all_fields(self, text_type):
        text = '`This` is a **test**'

        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)

        rsp = self.apiPut(
            get_review_request_draft_url(review_request),
            {
                'text_type': text_type,
                'changedescription': text,
                'description': text,
                'testing_done': text,
            },
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        draft_rsp = rsp['draft']
        self.assertEqual(draft_rsp['text_type'], text_type)
        self.assertEqual(draft_rsp['changedescription'], text)
        self.assertEqual(draft_rsp['description'], text)
        self.assertEqual(draft_rsp['testing_done'], text)

        draft = ReviewRequestDraft.objects.get(pk=rsp['draft']['id'])
        self.compare_item(draft_rsp, draft)
    def test_get_or_create_user_auth_backend(self):
        """Testing the PUT review-requests/<id>/draft/ API
        with AuthBackend.get_or_create_user failure
        """
        class SandboxAuthBackend(AuthBackend):
            backend_id = 'test-id'
            name = 'test'

            def get_or_create_user(self,
                                   username,
                                   request=None,
                                   password=None):
                raise Exception

        backend = SandboxAuthBackend()

        self.spy_on(auth.get_backends, call_fake=lambda: [backend])

        # The first spy messes with permissions, this lets it through
        self.spy_on(ReviewRequest.is_mutable_by, call_fake=lambda x, y: True)
        self.spy_on(backend.get_or_create_user)

        review_request = self.create_review_request(submitter=self.user)

        ReviewRequestDraft.create(review_request)

        rsp = self.api_put(get_review_request_draft_url(review_request, None),
                           {
                               'target_people': 'Target',
                           },
                           expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertTrue(backend.get_or_create_user.called)
    def setup_basic_post_test(self, user, with_local_site, local_site_name, post_valid_data):
        review_request = self.create_review_request(with_local_site=with_local_site, submitter=user, publish=True)

        return (
            get_review_request_draft_url(review_request, local_site_name),
            review_request_draft_item_mimetype,
            {"description": "New description"},
            [review_request],
        )
    def setup_basic_delete_test(self, user, with_local_site, local_site_name):
        review_request = self.create_review_request(
            with_local_site=with_local_site,
            submitter=user,
            publish=True)
        ReviewRequestDraft.create(review_request)

        return (get_review_request_draft_url(review_request, local_site_name),
                [review_request])
    def setup_basic_get_test(self, user, with_local_site, local_site_name):
        review_request = self.create_review_request(with_local_site=with_local_site, submitter=user, publish=True)
        draft = ReviewRequestDraft.create(review_request)

        return (
            get_review_request_draft_url(review_request, local_site_name),
            review_request_draft_item_mimetype,
            draft,
        )
    def test_delete_reviewrequestdraft_with_site_no_access(self):
        """Testing the DELETE review-requests/<id>/draft/ API with a local site and Permission Denied error"""
        review_request = self.create_review_request(submitter='doc',
                                                    with_local_site=True)

        rsp = self.apiDelete(
            get_review_request_draft_url(review_request, self.local_site_name),
            expected_status=403)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
    def test_put_with_invalid_field_name(self):
        """Testing the PUT review-requests/<id>/draft/ API
        with Invalid Form Data error
        """
        review_request = self.create_review_request(submitter=self.user)

        rsp = self.apiPut(get_review_request_draft_url(review_request), {"foobar": "foo"}, expected_status=400)

        self.assertEqual(rsp["stat"], "fail")
        self.assertEqual(rsp["err"]["code"], INVALID_FORM_DATA.code)
        self.assertTrue("foobar" in rsp["fields"])
    def test_put_reviewrequestdraft_with_invalid_field_name(self):
        """Testing the PUT review-requests/<id>/draft/ API with Invalid Form Data error"""
        review_request = self.create_review_request(submitter=self.user)

        rsp = self.apiPut(
            get_review_request_draft_url(review_request),
            {'foobar': 'foo'},
            expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertTrue('foobar' in rsp['fields'])
    def test_put_with_depends_on_invalid_id(self):
        """Testing the PUT review-requests/<id>/draft/ API
        with depends_on field and invalid ID
        """
        review_request = self.create_review_request(submitter=self.user, publish=True)

        rsp = self.apiPut(get_review_request_draft_url(review_request), {"depends_on": "10000"}, expected_status=400)

        self.assertEqual(rsp["stat"], "fail")

        draft = review_request.get_draft()
        self.assertEqual(draft.depends_on.count(), 0)
    def setup_basic_put_test(self, user, with_local_site, local_site_name,
                             put_valid_data):
        review_request = self.create_review_request(
            with_local_site=with_local_site,
            submitter=user,
            publish=True)
        draft = ReviewRequestDraft.create(review_request)

        return (get_review_request_draft_url(review_request, local_site_name),
                review_request_draft_item_mimetype,
                {'description': 'New description'},
                draft,
                [review_request])
    def test_put_reviewrequestdraft_with_permission_denied_error(self):
        """Testing the PUT review-requests/<id>/draft/ API with Permission Denied error"""
        bugs_closed = '123,456'
        review_request = self.create_review_request()
        self.assertNotEqual(review_request.submitter, self.user)

        rsp = self.apiPut(
            get_review_request_draft_url(review_request),
            {'bugs_closed': bugs_closed},
            expected_status=403)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
    def test_put_reviewrequestdraft_with_depends_on_invalid_id(self):
        """Testing the PUT review-requests/<id>/draft/ API with depends_on field and invalid ID"""
        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)

        rsp = self.apiPut(
            get_review_request_draft_url(review_request),
            {'depends_on': '10000'},
            expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')

        draft = review_request.get_draft()
        self.assertEqual(draft.depends_on.count(), 0)
    def test_delete_reviewrequestdraft(self):
        """Testing the DELETE review-requests/<id>/draft/ API"""
        review_request = self.create_review_request(submitter=self.user)
        summary = review_request.summary
        description = review_request.description

        # Set some data.
        self.test_put_reviewrequestdraft(review_request)

        self.apiDelete(get_review_request_draft_url(review_request))

        review_request = ReviewRequest.objects.get(pk=review_request.id)
        self.assertEqual(review_request.summary, summary)
        self.assertEqual(review_request.description, description)
    def test_delete(self):
        """Testing the DELETE review-requests/<id>/draft/ API"""
        review_request = self.create_review_request(submitter=self.user)
        summary = review_request.summary
        description = review_request.description

        # Set some data.
        self.test_put(review_request)

        self.apiDelete(get_review_request_draft_url(review_request))

        review_request = ReviewRequest.objects.get(pk=review_request.id)
        self.assertEqual(review_request.summary, summary)
        self.assertEqual(review_request.description, description)
    def test_put_with_commit_id_and_used_in_review_request(self):
        """Testing the PUT review-requests/<id>/draft/ API with commit_id
        used in another review request
        """
        commit_id = "abc123"

        self.create_review_request(submitter=self.user, commit_id=commit_id, publish=True)

        review_request = self.create_review_request(submitter=self.user, publish=True)

        self.api_put(get_review_request_draft_url(review_request), {"commit_id": commit_id}, expected_status=409)

        review_request = ReviewRequest.objects.get(pk=review_request.pk)
        self.assertIsNone(review_request.commit_id, None)
    def test_put_with_commit_id_empty_string(self):
        """Testing the PUT review-requests/<id>/draft/ API with commit_id=''"""
        review_request = self.create_review_request(submitter=self.user, publish=True)

        rsp = self.api_put(
            get_review_request_draft_url(review_request),
            {"commit_id": ""},
            expected_mimetype=review_request_draft_item_mimetype,
        )
        self.assertEqual(rsp["stat"], "ok")
        self.assertIsNone(rsp["draft"]["commit_id"])

        review_request = ReviewRequest.objects.get(pk=review_request.pk)
        self.assertIsNone(review_request.commit_id)
    def test_put_with_permission_denied_error(self):
        """Testing the PUT review-requests/<id>/draft/ API
        with Permission Denied error
        """
        bugs_closed = "123,456"
        review_request = self.create_review_request()
        self.assertNotEqual(review_request.submitter, self.user)

        rsp = self.apiPut(
            get_review_request_draft_url(review_request), {"bugs_closed": bugs_closed}, expected_status=403
        )

        self.assertEqual(rsp["stat"], "fail")
        self.assertEqual(rsp["err"]["code"], PERMISSION_DENIED.code)
    def _create_update_review_request(self, api_func, expected_status,
                                      review_request=None,
                                      local_site_name=None):
        summary = "My Summary"
        description = "My Description"
        testing_done = "My Testing Done"
        branch = "My Branch"
        bugs = "#123,456"

        if review_request is None:
            review_request = self.create_review_request(submitter=self.user,
                                                        publish=True)
            review_request.target_people.add(
                User.objects.get(username='******'))

        func_kwargs = {
            'summary': summary,
            'description': description,
            'testing_done': testing_done,
            'branch': branch,
            'bugs_closed': bugs,
        }

        if expected_status >= 400:
            expected_mimetype = None
        else:
            expected_mimetype = review_request_draft_item_mimetype

        rsp = api_func(
            get_review_request_draft_url(review_request, local_site_name),
            func_kwargs,
            expected_status=expected_status,
            expected_mimetype=expected_mimetype)

        if expected_status >= 200 and expected_status < 300:
            self.assertEqual(rsp['stat'], 'ok')
            self.assertEqual(rsp['draft']['summary'], summary)
            self.assertEqual(rsp['draft']['description'], description)
            self.assertEqual(rsp['draft']['testing_done'], testing_done)
            self.assertEqual(rsp['draft']['branch'], branch)
            self.assertEqual(rsp['draft']['bugs_closed'], ['123', '456'])

            draft = ReviewRequestDraft.objects.get(pk=rsp['draft']['id'])
            self.assertEqual(draft.summary, summary)
            self.assertEqual(draft.description, description)
            self.assertEqual(draft.testing_done, testing_done)
            self.assertEqual(draft.branch, branch)
            self.assertEqual(draft.get_bug_list(), ['123', '456'])

        return rsp
    def _test_put_with_text_types(self, text_type_field, text_type_value,
                                  expected_change_text_type,
                                  expected_description_text_type,
                                  expected_testing_done_text_type,
                                  expected_custom_field_text_type):
        text = '`This` is a **test**'

        class CustomField(BaseTextAreaField):
            field_id = 'mytext'

        fieldset = get_review_request_fieldset('main')
        fieldset.add_field(CustomField)

        try:
            review_request = self.create_review_request(submitter=self.user,
                                                        publish=True)

            rsp = self.api_put(
                get_review_request_draft_url(review_request),
                {
                    'changedescription': text,
                    'description': text,
                    'testing_done': text,
                    'extra_data.mytext': text,
                    text_type_field: text_type_value,
                },
                expected_mimetype=review_request_draft_item_mimetype)

            self.assertEqual(rsp['stat'], 'ok')

            draft_rsp = rsp['draft']
            extra_data = draft_rsp['extra_data']
            self.assertEqual(draft_rsp['changedescription'], text)
            self.assertEqual(draft_rsp['description'], text)
            self.assertEqual(draft_rsp['testing_done'], text)
            self.assertEqual(extra_data['mytext'], text)
            self.assertEqual(draft_rsp['changedescription_text_type'],
                             expected_change_text_type)
            self.assertEqual(draft_rsp['description_text_type'],
                             expected_description_text_type)
            self.assertEqual(draft_rsp['testing_done_text_type'],
                             expected_testing_done_text_type)
            self.assertEqual(extra_data['mytext_text_type'],
                             expected_custom_field_text_type)

            draft = ReviewRequestDraft.objects.get(pk=rsp['draft']['id'])
            self.compare_item(draft_rsp, draft)
        finally:
            fieldset.remove_field(CustomField)
    def test_delete_reviewrequestdraft_with_site(self):
        """Testing the DELETE review-requests/<id>/draft/ API with a local site"""
        review_request = self.create_review_request(submitter='doc',
                                                    with_local_site=True)
        summary = review_request.summary
        description = review_request.description

        self.test_put_reviewrequestdraft_with_site(review_request)

        self.apiDelete(get_review_request_draft_url(review_request,
                                                    self.local_site_name))

        review_request = ReviewRequest.objects.get(pk=review_request.id)
        self.assertEqual(review_request.summary, summary)
        self.assertEqual(review_request.description, description)
Ejemplo n.º 44
0
    def test_put_with_no_changes(self):
        """Testing the PUT review-requests/<id>/draft/ API
        with no changes made to the fields
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)

        ReviewRequestDraft.create(review_request)

        rsp = self.api_put(get_review_request_draft_url(review_request),
                           {'public': True},
                           expected_status=NOTHING_TO_PUBLISH.http_status)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], NOTHING_TO_PUBLISH.code)
    def test_put_reviewrequestdraft_with_changedesc(self):
        """Testing the PUT review-requests/<id>/draft/ API with a change description"""
        changedesc = 'This is a test change description.'
        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)

        rsp = self.apiPost(
            get_review_request_draft_url(review_request),
            {'changedescription': changedesc},
            expected_mimetype=review_request_draft_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['draft']['changedescription'], changedesc)

        draft = ReviewRequestDraft.objects.get(pk=rsp['draft']['id'])
        self.assertNotEqual(draft.changedesc, None)
        self.assertEqual(draft.changedesc.text, changedesc)
Ejemplo n.º 46
0
    def test_put_with_commit_id_and_used_in_review_request(self):
        """Testing the PUT review-requests/<id>/draft/ API with commit_id
        used in another review request
        """
        commit_id = 'abc123'

        self.create_review_request(submitter=self.user,
                                   commit_id=commit_id,
                                   publish=True)

        review_request = self.create_review_request(submitter=self.user,
                                                    publish=True)

        self.api_put(get_review_request_draft_url(review_request), {
            'commit_id': commit_id,
        },
                     expected_status=409)

        review_request = ReviewRequest.objects.get(pk=review_request.pk)
        self.assertIsNone(review_request.commit_id, None)