~vcs-imports/reviewboard/trunk

« back to all changes in this revision

Viewing changes to reviewboard/reviews/tests/test_batch_view.py

  • Committer: Christian Hammond
  • Date: 2023-11-07 06:16:03 UTC
  • mfrom: (4947.1.350)
  • Revision ID: git-v1:00c845582f57ac3df206a66fe9603a1958b87fb9
Merge branch 'release-6.x'

Show diffs side-by-side

added added

removed removed

Lines of Context:
748
748
        self.assertTrue(rr.public)
749
749
        self.assertEqual(rr.summary, 'Updated Summary')
750
750
 
 
751
    def test_publish_other_draft_as_admin(self) -> None:
 
752
        """Testing BatchOperationView publish op with an admin publishing
 
753
        a draft on another user's review request
 
754
        """
 
755
        self.client.login(username='admin', password='admin')
 
756
        grumpy = User.objects.get(username='grumpy')
 
757
 
 
758
        rr = self.create_review_request(publish=True,
 
759
                                        target_people=[grumpy])
 
760
        draft = self.create_review_request_draft(rr)
 
761
        draft.summary = 'Updated Summary'
 
762
        draft.save(update_fields=('summary',))
 
763
 
 
764
        response = self.client.post(self.url, data={
 
765
            'batch': json.dumps({
 
766
                'op': 'publish',
 
767
                'review_requests': [rr.pk],
 
768
            }),
 
769
        })
 
770
        self.assertEqual(response.status_code, 200)
 
771
 
 
772
        rr.refresh_from_db()
 
773
 
 
774
        self.assertTrue(rr.public)
 
775
        self.assertEqual(rr.summary, 'Updated Summary')
 
776
 
751
777
    def test_publish_permissions(self) -> None:
752
778
        """Testing BatchOperationView publish op with non-owner user"""
753
779
        self.client.login(username='grumpy', password='grumpy')
1085
1111
        self.assertVisibility(rr1, 'doc', ReviewRequestVisit.ARCHIVED)
1086
1112
        self.assertVisibility(rr2, 'doc', ReviewRequestVisit.ARCHIVED)
1087
1113
 
 
1114
    @add_fixtures(['test_scmtools'])
 
1115
    def test_publish_with_acls(self) -> None:
 
1116
        """Testing BatchOperationView when publishing a review on a review
 
1117
        request that has multiple groups with ACLs
 
1118
        """
 
1119
        # Review Board 6.0 had a bug where the way the batch endpoint was
 
1120
        # fetching reviews could return duplicates, which would then fail
 
1121
        # length comparisons. This test case is an example of something that
 
1122
        # triggered that bug before it was fixed.
 
1123
        doc = User.objects.get(username='doc')
 
1124
        grumpy = User.objects.get(username='grumpy')
 
1125
 
 
1126
        group1 = self.create_review_group(invite_only=True)
 
1127
        group1.users.add(doc, grumpy)
 
1128
 
 
1129
        group2 = self.create_review_group(invite_only=True)
 
1130
        group2.users.add(doc, grumpy)
 
1131
 
 
1132
        repository = self.create_repository(public=False)
 
1133
        repository.review_groups.set([group1])
 
1134
 
 
1135
        review_request = self.create_review_request(
 
1136
            publish=True,
 
1137
            repository=repository,
 
1138
            target_groups=[group1, group2])
 
1139
        review = self.create_review(review_request, user='doc')
 
1140
 
 
1141
        self.client.login(username='doc', password='doc')
 
1142
        response = self.client.post(self.url, data={
 
1143
            'batch': json.dumps({
 
1144
                'op': 'publish',
 
1145
                'review_requests': [],
 
1146
                'reviews': [review.pk],
 
1147
            }),
 
1148
        })
 
1149
        self.assertEqual(response.status_code, 200)
 
1150
 
 
1151
        reply = self.create_reply(review, user='grumpy')
 
1152
        self.client.login(username='grumpy', password='grumpy')
 
1153
        response = self.client.post(self.url, data={
 
1154
            'batch': json.dumps({
 
1155
                'op': 'publish',
 
1156
                'review_requests': [],
 
1157
                'reviews': [reply.pk],
 
1158
            }),
 
1159
        })
 
1160
        self.assertEqual(response.status_code, 200)
 
1161
 
1088
1162
    def assertVisibility(
1089
1163
        self,
1090
1164
        review_request: ReviewRequest,
1228
1302
                'model': ReviewRequest,
1229
1303
                'distinct': True,
1230
1304
                'num_joins': 3,
1231
 
                'order_by': ('pk',),
1232
1305
                'tables': {
1233
1306
                    'auth_user',
1234
1307
                    'reviews_reviewrequest_target_people',