def test_get_with_site(self):
        """Testing the GET users/<username>/watched/review_request/ API
        with a local site
        """
        user = self._login_user(local_site=True)

        review_request = self.create_review_request(with_local_site=True,
                                                    publish=True)
        profile = Profile.objects.get(user=user)
        profile.starred_review_requests.add(review_request)

        rsp = self.apiGet(
            get_watched_review_request_list_url(user.username,
                                                self.local_site_name),
            expected_mimetype=watched_review_request_list_mimetype)

        watched = profile.starred_review_requests.filter(
            local_site__name=self.local_site_name)
        apiwatched = rsp['watched_review_requests']

        self.assertEqual(len(watched), len(apiwatched))
        for i in range(len(watched)):
            self.assertEqual(watched[i].display_id,
                             apiwatched[i]['watched_review_request']['id'])
            self.assertEqual(
                watched[i].summary,
                apiwatched[i]['watched_review_request']['summary'])
 def test_post_watched_review_request_with_does_not_exist_error(self):
     """Testing the POST users/<username>/watched/review_request/ with Does Not Exist error"""
     rsp = self.apiPost(
         get_watched_review_request_list_url(self.user.username),
         {'object_id': 999},
         expected_status=404)
     self.assertEqual(rsp['stat'], 'fail')
     self.assertEqual(rsp['err']['code'], DOES_NOT_EXIST.code)
 def test_post_watched_review_request_with_site_no_access(self):
     """Testing the POST users/<username>/watched/review_request/ API with a local site and Permission Denied error"""
     rsp = self.apiPost(
         get_watched_review_request_list_url('doc', self.local_site_name),
         {'object_id': 10},
         expected_status=403)
     self.assertEqual(rsp['stat'], 'fail')
     self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
 def test_post_watched_review_request_with_site_does_not_exist_error(self):
     """Testing the POST users/<username>/watched/review_request/ API with a local site and Does Not Exist error"""
     self._login_user(local_site=True)
     rsp = self.apiPost(
         get_watched_review_request_list_url('doc', self.local_site_name),
         {'object_id': 10},
         expected_status=404)
     self.assertEqual(rsp['stat'], 'fail')
     self.assertEqual(rsp['err']['code'], DOES_NOT_EXIST.code)
 def test_post_watched_review_request(self):
     """Testing the POST users/<username>/watched/review-request/ API"""
     review_request = self.create_review_request(publish=True)
     rsp = self.apiPost(
         get_watched_review_request_list_url(self.user.username),
         {'object_id': review_request.display_id},
         expected_mimetype=watched_review_request_item_mimetype)
     self.assertEqual(rsp['stat'], 'ok')
     self.assert_(review_request in
                  self.user.get_profile().starred_review_requests.all())
 def test_get_with_site_does_not_exist(self):
     """Testing the GET users/<username>/watched/review-requests/ API
     with a local site and Does Not Exist error
     """
     self._login_user(local_site=True)
     rsp = self.apiGet(
         get_watched_review_request_list_url(self.user.username,
                                             self.local_site_name),
         expected_status=404)
     self.assertEqual(rsp['stat'], 'fail')
     self.assertEqual(rsp['err']['code'], DOES_NOT_EXIST.code)
    def setup_basic_get_test(self, user, with_local_site, local_site_name,
                             populate_items):
        if populate_items:
            review_request = self.create_review_request(
                with_local_site=with_local_site,
                publish=True)

            profile = user.get_profile()
            profile.starred_review_requests.add(review_request)
            items = [review_request]
        else:
            items = []

        return (get_watched_review_request_list_url(user.username,
                                                    local_site_name),
                watched_review_request_list_mimetype,
                items)
    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,
            publish=True)

        if post_valid_data:
            post_data = {
                'object_id': review_request.display_id,
            }
        else:
            post_data = {}

        return (get_watched_review_request_list_url(user.username,
                                                    local_site_name),
                watched_review_request_item_mimetype,
                post_data,
                [review_request])
    def test_post_watched_review_request_with_site(self):
        """Testing the POST users/<username>/watched/review_request/ API with a local site"""
        self._login_user(local_site=True)

        username = 'doc'
        user = User.objects.get(username=username)
        review_request = self.create_review_request(with_local_site=True,
                                                    publish=True)

        rsp = self.apiPost(
            get_watched_review_request_list_url(username,
                                                self.local_site_name),
            {'object_id': review_request.display_id},
            expected_mimetype=watched_review_request_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertTrue(review_request in
                        user.get_profile().starred_review_requests.all())

        return review_request
    def test_get_watched_review_requests(self):
        """Testing the GET users/<username>/watched/review_request/ API"""
        self.test_post_watched_review_request()

        rsp = self.apiGet(
            get_watched_review_request_list_url(self.user.username),
            expected_mimetype=watched_review_request_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')

        watched = self.user.get_profile().starred_review_requests.all()
        apiwatched = rsp['watched_review_requests']

        self.assertEqual(len(watched), len(apiwatched))

        for i in range(len(watched)):
            self.assertEqual(watched[i].id,
                             apiwatched[i]['watched_review_request']['id'])
            self.assertEqual(
                watched[i].summary,
                apiwatched[i]['watched_review_request']['summary'])
    def test_get(self):
        """Testing the GET users/<username>/watched/review_request/ API"""
        review_request = self.create_review_request(publish=True)
        profile = Profile.objects.get(user=self.user)
        profile.starred_review_requests.add(review_request)

        rsp = self.apiGet(
            get_watched_review_request_list_url(self.user.username),
            expected_mimetype=watched_review_request_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')

        watched = profile.starred_review_requests.all()
        apiwatched = rsp['watched_review_requests']

        self.assertEqual(len(watched), len(apiwatched))

        for i in range(len(watched)):
            self.assertEqual(watched[i].id,
                             apiwatched[i]['watched_review_request']['id'])
            self.assertEqual(
                watched[i].summary,
                apiwatched[i]['watched_review_request']['summary'])
    def test_get_watched_review_requests_with_site(self):
        """Testing the GET users/<username>/watched/review_request/ API with a local site"""
        username = 'doc'
        user = User.objects.get(username=username)

        self.test_post_watched_review_request_with_site()

        rsp = self.apiGet(
            get_watched_review_request_list_url(username,
                                                self.local_site_name),
            expected_mimetype=watched_review_request_list_mimetype)

        watched = user.get_profile().starred_review_requests.filter(
            local_site__name=self.local_site_name)
        apiwatched = rsp['watched_review_requests']

        self.assertEqual(len(watched), len(apiwatched))
        for i in range(len(watched)):
            self.assertEqual(watched[i].display_id,
                             apiwatched[i]['watched_review_request']['id'])
            self.assertEqual(
                watched[i].summary,
                apiwatched[i]['watched_review_request']['summary'])