示例#1
0
    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, publish=True)

        return (get_review_request_item_url(review_request.display_id,
                                            local_site_name),
                review_request_item_mimetype, review_request)
    def test_put_status_submitted_with_site(self):
        """Testing the PUT review-requests/<id>/?status=submitted API
        with a local site
        """
        self._login_user(local_site=True)
        r = self.create_review_request(submitter='doc', with_local_site=True,
                                       publish=True)

        rsp = self.apiPut(
            get_review_request_item_url(r.display_id, self.local_site_name),
            {
                'status': 'submitted',
                'description': 'comment'
            },
            expected_mimetype=review_request_item_mimetype)

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

        r = ReviewRequest.objects.get(pk=r.id)
        self.assertEqual(r.status, 'S')

        c = r.changedescs.latest('timestamp')
        self.assertEqual(c.text, 'comment')

        fc_status = c.fields_changed['status']
        self.assertEqual(fc_status['old'][0], 'P')
        self.assertEqual(fc_status['new'][0], 'S')
示例#3
0
    def test_put_status_submitted_with_site(self):
        """Testing the PUT review-requests/<id>/?status=submitted API
        with a local site
        """
        self._login_user(local_site=True)
        r = self.create_review_request(submitter='doc',
                                       with_local_site=True,
                                       publish=True)

        rsp = self.apiPut(get_review_request_item_url(r.display_id,
                                                      self.local_site_name),
                          {
                              'status': 'submitted',
                              'description': 'comment'
                          },
                          expected_mimetype=review_request_item_mimetype)

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

        r = ReviewRequest.objects.get(pk=r.id)
        self.assertEqual(r.status, 'S')

        c = r.changedescs.latest('timestamp')
        self.assertEqual(c.text, 'comment')

        fc_status = c.fields_changed['status']
        self.assertEqual(fc_status['old'][0], 'P')
        self.assertEqual(fc_status['new'][0], 'S')
    def test_get_not_modified(self):
        """Testing the GET review-requests/<id>/ API
        with Not Modified response
        """
        review_request = self.create_review_request(publish=True)

        self._testHttpCaching(get_review_request_item_url(review_request.id),
                              check_last_modified=True)
示例#5
0
    def test_get_not_modified(self):
        """Testing the GET review-requests/<id>/ API
        with Not Modified response
        """
        review_request = self.create_review_request(publish=True)

        self._testHttpCaching(get_review_request_item_url(review_request.id),
                              check_last_modified=True)
示例#6
0
    def test_put_reviewrequest_status_submitted_with_site_no_access(self):
        """Testing the PUT review-requests/<id>/?status=submitted API with a local site and Permission Denied error"""
        r = self.create_review_request(submitter='doc', with_local_site=True,
                                       publish=True)

        self.apiPut(
            get_review_request_item_url(r.display_id, self.local_site_name),
            {'status': 'submitted'},
            expected_status=403)
    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,
            publish=True)

        return (get_review_request_item_url(review_request.display_id,
                                            local_site_name),
                review_request_item_mimetype,
                review_request)
示例#8
0
    def test_delete_reviewrequest_with_permission_denied_error(self):
        """Testing the DELETE review-requests/<id>/ API with Permission Denied error"""
        review_request = self.create_review_request(publish=True)
        self.assertNotEqual(review_request.submitter, self.user)

        rsp = self.apiDelete(
            get_review_request_item_url(review_request.display_id),
            expected_status=403)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
示例#9
0
    def test_get_reviewrequest_with_non_public_and_permission_denied_error(self):
        """Testing the GET review-requests/<id>/ API with non-public and Permission Denied error"""
        review_request = self.create_review_request(public=False)
        self.assertNotEqual(review_request.submitter, self.user)

        rsp = self.apiGet(
            get_review_request_item_url(review_request.display_id),
            expected_status=403)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
示例#10
0
    def test_get_reviewrequest_with_site_no_access(self):
        """Testing the GET review-requests/<id>/ API with a local site and Permission Denied error"""
        group = self.create_review_group(with_local_site=True)
        review_request = self.create_review_request(with_local_site=True,
                                                    publish=True)
        review_request.target_groups.add(group)

        self.apiGet(get_review_request_item_url(review_request.display_id,
                                                self.local_site_name),
                    expected_status=403)
示例#11
0
    def test_delete_reviewrequest_with_does_not_exist_error(self):
        """Testing the DELETE review-requests/<id>/ API with Does Not Exist error"""
        self.user.user_permissions.add(
            Permission.objects.get(codename='delete_reviewrequest'))
        self.user.save()
        self.assert_(self.user.has_perm('reviews.delete_reviewrequest'))

        rsp = self.apiDelete(get_review_request_item_url(999),
                             expected_status=404)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], DOES_NOT_EXIST.code)
示例#12
0
    def test_get_reviewrequest(self):
        """Testing the GET review-requests/<id>/ API"""
        review_request = self.create_review_request(publish=True)

        rsp = self.apiGet(
            get_review_request_item_url(review_request.display_id),
            expected_mimetype=review_request_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['review_request']['id'], review_request.display_id)
        self.assertEqual(rsp['review_request']['summary'],
                         review_request.summary)
示例#13
0
    def setup_basic_delete_test(self, user, with_local_site, local_site_name):
        user.user_permissions.add(
            Permission.objects.get(codename='delete_reviewrequest'))
        self.assertTrue(user.has_perm('reviews.delete_reviewrequest'))

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

        return (get_review_request_item_url(review_request.display_id,
                                            local_site_name),
                [review_request.pk])
示例#14
0
    def test_put_status_as_other_user_not_allowed(self):
        """Testing the PUT review-requests/<id>/?status=pending API
        as another user not allowed
        """
        review_request = self.create_review_request(publish=True)
        self.assertNotEqual(review_request.submitter.username,
                            self.user.username)

        self.apiPut(get_review_request_item_url(review_request.display_id), {
            'status': 'submitted',
        },
                    expected_status=403)
示例#15
0
    def test_put_reviewrequest_status_discarded_with_permission_denied(self):
        """Testing the PUT review-requests/<id>/?status=discarded API with Permission Denied"""
        r = self.create_review_request()
        self.assertNotEqual(r.submitter, self.user)

        rsp = self.apiPut(
            get_review_request_item_url(r.display_id),
            {'status': 'discarded'},
            expected_status=403)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
    def setup_basic_delete_test(self, user, with_local_site, local_site_name):
        user.user_permissions.add(
            Permission.objects.get(codename='delete_reviewrequest'))
        self.assertTrue(user.has_perm('reviews.delete_reviewrequest'))

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

        return (get_review_request_item_url(review_request.display_id,
                                            local_site_name),
                [review_request.pk])
    def setup_basic_put_test(self, user, with_local_site, local_site_name,
                             put_valid_data):
        review_request = \
            self.create_review_request(submitter=user, publish=True,
                                       with_local_site=with_local_site)

        return (get_review_request_item_url(review_request.display_id,
                                            local_site_name),
                review_request_item_mimetype,
                {
                    'extra_data.dummy': '',
                },
                review_request,
                [])
示例#18
0
    def test_delete_with_site_and_site_admin(self):
        """Testing the DELETE review-requests/<id>/ API
        with a local site and a site admin is not allowed
        """
        user = User.objects.get(username='******')

        self.user = self._login_user(local_site=True, admin=True)
        local_site = LocalSite.objects.get(name=self.local_site_name)

        review_request = self.create_review_request(with_local_site=True)

        rsp = self.apiDelete(get_review_request_item_url(
            review_request.display_id, self.local_site_name),
                             expected_status=403)
示例#19
0
    def test_put_status_pending(self):
        """Testing the PUT review-requests/<id>/?status=pending API"""
        r = self.create_review_request(submitter=self.user, publish=True)
        r.close(ReviewRequest.SUBMITTED)
        r.save()

        rsp = self.apiPut(get_review_request_item_url(r.display_id),
                          {'status': 'pending'},
                          expected_mimetype=review_request_item_mimetype)

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

        r = ReviewRequest.objects.get(pk=r.id)
        self.assertEqual(r.status, 'P')
    def test_put_status_as_other_user_not_allowed(self):
        """Testing the PUT review-requests/<id>/?status=pending API
        as another user not allowed
        """
        review_request = self.create_review_request(publish=True)
        self.assertNotEqual(review_request.submitter.username,
                            self.user.username)

        self.apiPut(
            get_review_request_item_url(review_request.display_id),
            {
                'status': 'submitted',
            },
            expected_status=403)
示例#21
0
    def test_get_reviewrequest_with_site(self):
        """Testing the GET review-requests/<id>/ API with a local site"""
        self._login_user(local_site=True)
        review_request = self.create_review_request(publish=True,
                                                    with_local_site=True)

        rsp = self.apiGet(
            get_review_request_item_url(review_request.display_id,
                                        self.local_site_name),
            expected_mimetype=review_request_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['review_request']['id'],
                         review_request.display_id)
        self.assertEqual(rsp['review_request']['summary'],
                         review_request.summary)
示例#22
0
    def test_get(self):
        """Testing the GET users/<username>/watched/review-requests/<id>/ API"""
        review_request = self.create_review_request(publish=True)
        profile = self.user.get_profile()
        profile.starred_review_requests.add(review_request)

        expected_url = (self.base_url +
                        get_review_request_item_url(review_request.display_id))

        self.apiGet(get_watched_review_request_item_url(
            self.user.username, review_request.display_id),
                    expected_status=302,
                    expected_headers={
                        'Location': expected_url,
                    })
    def test_put_status_pending(self):
        """Testing the PUT review-requests/<id>/?status=pending API"""
        r = self.create_review_request(submitter=self.user, publish=True)
        r.close(ReviewRequest.SUBMITTED)
        r.save()

        rsp = self.apiPut(
            get_review_request_item_url(r.display_id),
            {'status': 'pending'},
            expected_mimetype=review_request_item_mimetype)

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

        r = ReviewRequest.objects.get(pk=r.id)
        self.assertEqual(r.status, 'P')
    def test_delete_with_site_and_site_admin(self):
        """Testing the DELETE review-requests/<id>/ API
        with a local site and a site admin is not allowed
        """
        user = User.objects.get(username='******')

        self.user = self._login_user(local_site=True, admin=True)
        local_site = LocalSite.objects.get(name=self.local_site_name)

        review_request = self.create_review_request(with_local_site=True)

        rsp = self.apiDelete(
            get_review_request_item_url(review_request.display_id,
                                        self.local_site_name),
            expected_status=403)
示例#25
0
    def test_get_reviewrequest_with_invite_only_group_and_permission_denied_error(self):
        """Testing the GET review-requests/<id>/ API with invite-only group and Permission Denied error"""
        review_request = self.create_review_request(publish=True)
        self.assertNotEqual(review_request.submitter, self.user)

        group = Group(name='test-group', invite_only=True)
        group.save()

        review_request.target_groups.add(group)
        review_request.save()

        rsp = self.apiGet(
            get_review_request_item_url(review_request.display_id),
            expected_status=403)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
示例#26
0
    def test_delete_reviewrequest_with_site(self):
        """Testing the DELETE review-requests/<id>/ API with a lotal site"""
        user = User.objects.get(username='******')
        user.user_permissions.add(
            Permission.objects.get(codename='delete_reviewrequest'))
        user.save()

        self._login_user(local_site=True)
        review_request = self.create_review_request(with_local_site=True)

        rsp = self.apiDelete(
            get_review_request_item_url(review_request.display_id,
                                        self.local_site_name))
        self.assertEqual(rsp, None)
        self.assertRaises(ReviewRequest.DoesNotExist,
                          ReviewRequest.objects.get, pk=review_request.pk)
    def test_get(self):
        """Testing the GET users/<username>/watched/review_request/<id>/ API"""
        review_request = self.create_review_request(publish=True)
        profile = self.user.get_profile()
        profile.starred_review_requests.add(review_request)

        expected_url = (self.base_url +
                        get_review_request_item_url(review_request.display_id))

        self.apiGet(
            get_watched_review_request_item_url(self.user.username,
                                                review_request.display_id),
            expected_status=302,
            expected_headers={
                'Location': expected_url,
            })
示例#28
0
    def test_delete_reviewrequest(self):
        """Testing the DELETE review-requests/<id>/ API"""
        self.user.user_permissions.add(
            Permission.objects.get(codename='delete_reviewrequest'))
        self.user.save()
        self.assert_(self.user.has_perm('reviews.delete_reviewrequest'))

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

        rsp = self.apiDelete(
            get_review_request_item_url(review_request.display_id))
        self.assertEqual(rsp, None)
        self.assertRaises(ReviewRequest.DoesNotExist,
                          ReviewRequest.objects.get,
                          pk=review_request.pk)
示例#29
0
    def test_delete_with_site_and_local_permission(self):
        """Testing the DELETE review-requests/<id>/ API
        with a local site and a local permission is not allowed
        """
        self.user = self._login_user(local_site=True)
        local_site = LocalSite.objects.get(name=self.local_site_name)

        site_profile = LocalSiteProfile.objects.create(
            user=self.user,
            local_site=local_site,
            profile=self.user.get_profile())
        site_profile.permissions['reviews.delete_reviewrequest'] = True
        site_profile.save()

        review_request = self.create_review_request(with_local_site=True)

        rsp = self.apiDelete(get_review_request_item_url(
            review_request.display_id, self.local_site_name),
                             expected_status=403)
示例#30
0
    def test_get_reviewrequest_with_invite_only_group_and_target_user(self):
        """Testing the GET review-requests/<id>/ API with invite-only group and target user"""
        review_request = self.create_review_request(publish=True)
        self.assertNotEqual(review_request.submitter, self.user)

        group = Group(name='test-group', invite_only=True)
        group.save()

        review_request.target_groups.add(group)
        review_request.target_people.add(self.user)
        review_request.save()

        rsp = self.apiGet(
            get_review_request_item_url(review_request.display_id),
            expected_mimetype=review_request_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['review_request']['id'], review_request.display_id)
        self.assertEqual(rsp['review_request']['summary'],
                         review_request.summary)
    def test_delete_with_site_and_local_permission(self):
        """Testing the DELETE review-requests/<id>/ API
        with a local site and a local permission is not allowed
        """
        self.user = self._login_user(local_site=True)
        local_site = LocalSite.objects.get(name=self.local_site_name)

        site_profile = LocalSiteProfile.objects.create(
            user=self.user,
            local_site=local_site,
            profile=self.user.get_profile())
        site_profile.permissions['reviews.delete_reviewrequest'] = True
        site_profile.save()

        review_request = self.create_review_request(with_local_site=True)

        rsp = self.apiDelete(
            get_review_request_item_url(review_request.display_id,
                                        self.local_site_name),
            expected_status=403)
示例#32
0
    def test_get_with_site(self):
        """Testing the GET users/<username>/watched/review-requests/<id>/ API
        with access to a local site
        """
        user = self._login_user(local_site=True)

        review_request = self.create_review_request(with_local_site=True,
                                                    publish=True)
        profile = user.get_profile()
        profile.starred_review_requests.add(review_request)

        expected_url = (self.base_url + get_review_request_item_url(
            review_request.display_id, self.local_site_name))

        self.apiGet(get_watched_review_request_item_url(
            user.username, review_request.display_id, self.local_site_name),
                    expected_status=302,
                    expected_headers={
                        'Location': expected_url,
                    })
示例#33
0
    def _test_put_status_as_other_user(self, local_site=None):
        review_request = self.create_review_request(
            submitter='dopey',
            publish=True,
            with_local_site=(local_site is not None))

        if local_site:
            local_site_name = local_site.name
        else:
            local_site_name = None

        rsp = self.apiPut(get_review_request_item_url(
            review_request.display_id, local_site_name), {
                'status': 'submitted',
            },
                          expected_mimetype=review_request_item_mimetype)

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

        review_request = ReviewRequest.objects.get(pk=review_request.id)
        self.assertEqual(review_request.status, 'S')
示例#34
0
    def test_put_status_discarded(self):
        """Testing the PUT review-requests/<id>/?status=discarded API"""
        r = self.create_review_request(submitter=self.user, publish=True)

        rsp = self.apiPut(get_review_request_item_url(r.display_id), {
            'status': 'discarded',
            'description': 'comment',
        },
                          expected_mimetype=review_request_item_mimetype)

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

        r = ReviewRequest.objects.get(pk=r.id)
        self.assertEqual(r.status, 'D')

        c = r.changedescs.latest('timestamp')
        self.assertEqual(c.text, 'comment')

        fc_status = c.fields_changed['status']
        self.assertEqual(fc_status['old'][0], 'P')
        self.assertEqual(fc_status['new'][0], 'D')
    def test_put_status_discarded(self):
        """Testing the PUT review-requests/<id>/?status=discarded API"""
        r = self.create_review_request(submitter=self.user, publish=True)

        rsp = self.apiPut(
            get_review_request_item_url(r.display_id),
            {
                'status': 'discarded',
                'description': 'comment',
            },
            expected_mimetype=review_request_item_mimetype)

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

        r = ReviewRequest.objects.get(pk=r.id)
        self.assertEqual(r.status, 'D')

        c = r.changedescs.latest('timestamp')
        self.assertEqual(c.text, 'comment')

        fc_status = c.fields_changed['status']
        self.assertEqual(fc_status['old'][0], 'P')
        self.assertEqual(fc_status['new'][0], 'D')
    def test_get_with_site(self):
        """Testing the GET users/<username>/watched/review_request/<id>/ API
        with access to a local site
        """
        user = self._login_user(local_site=True)

        review_request = self.create_review_request(with_local_site=True,
                                                    publish=True)
        profile = user.get_profile()
        profile.starred_review_requests.add(review_request)

        expected_url = (self.base_url +
                        get_review_request_item_url(review_request.display_id,
                                                    self.local_site_name))

        self.apiGet(
            get_watched_review_request_item_url(user.username,
                                                review_request.display_id,
                                                self.local_site_name),
            expected_status=302,
            expected_headers={
                'Location': expected_url,
            })
    def _test_put_status_as_other_user(self, local_site=None):
        review_request = self.create_review_request(
            submitter='dopey',
            publish=True,
            with_local_site=(local_site is not None))

        if local_site:
            local_site_name = local_site.name
        else:
            local_site_name = None

        rsp = self.apiPut(
            get_review_request_item_url(review_request.display_id,
                                        local_site_name),
            {
                'status': 'submitted',
            },
            expected_mimetype=review_request_item_mimetype)

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

        review_request = ReviewRequest.objects.get(pk=review_request.id)
        self.assertEqual(review_request.status, 'S')