Example #1
0
    def test_delete_with_permission_denied_error(self):
        """Testing the DELETE groups/<id>/ API with Permission Denied error"""
        group = Group.objects.create(name='test-group', invite_only=True)
        group.users.add(self.user)

        self.api_delete(get_review_group_item_url('test-group'),
                        expected_status=403)
 def test_get_with_site_no_access(self):
     """Testing the GET groups/<id>/ API
     with a local site and Permission Denied error
     """
     self.apiGet(
         get_review_group_item_url('sitegroup', self.local_site_name),
         expected_status=403)
    def test_put(self, local_site=None):
        """Testing the PUT groups/<name>/ API"""
        name = 'my-group'
        display_name = 'My Group'
        mailing_list = '*****@*****.**'

        group = self.create_review_group(
            with_local_site=(local_site is not None))

        self._login_user(admin=True)
        rsp = self.apiPut(
            get_review_group_item_url(group.name, local_site),
            {
                'name': name,
                'display_name': display_name,
                'mailing_list': mailing_list,
            },
            expected_mimetype=review_group_item_mimetype)

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

        group = Group.objects.get(pk=group.pk)
        self.assertEqual(group.local_site, local_site)
        self.assertEqual(group.name, name)
        self.assertEqual(group.display_name, display_name)
        self.assertEqual(group.mailing_list, mailing_list)
Example #4
0
    def test_delete_with_permission_denied_error(self):
        """Testing the DELETE groups/<id>/ API with Permission Denied error"""
        group = Group.objects.create(name='test-group', invite_only=True)
        group.users.add(self.user)

        self.apiDelete(get_review_group_item_url('test-group'),
                       expected_status=403)
Example #5
0
    def test_delete_group_with_local_site_and_permission_denied_error(self):
        """Testing the DELETE groups/<id>/ API with a local site and Permission Denied error"""
        self.create_review_group(name='sitegroup', with_local_site=True)

        self._login_user(local_site=True)
        self.apiDelete(get_review_group_item_url('sitegroup',
                                                 self.local_site_name),
                       expected_status=403)
    def test_get_group_invite_only_with_permission_denied_error(self):
        """Testing the GET groups/<id>/ API with invite-only and Permission Denied error"""
        group = Group.objects.create(name='test-group', invite_only=True)

        rsp = self.apiGet(get_review_group_item_url(group.name),
                          expected_status=403)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
    def test_delete_with_local_site(self):
        """Testing the DELETE groups/<id>/ API with a local site"""
        self.create_review_group(name='sitegroup', with_local_site=True)

        self._login_user(local_site=True, admin=True)
        self.apiDelete(
            get_review_group_item_url('sitegroup', self.local_site_name),
            expected_status=204)
    def test_delete_group_with_local_site_and_permission_denied_error(self):
        """Testing the DELETE groups/<id>/ API with a local site and Permission Denied error"""
        self.create_review_group(name='sitegroup', with_local_site=True)

        self._login_user(local_site=True)
        self.apiDelete(
            get_review_group_item_url('sitegroup', self.local_site_name),
            expected_status=403)
Example #9
0
    def test_delete_group_with_local_site(self):
        """Testing the DELETE groups/<id>/ API with a local site"""
        self.create_review_group(name='sitegroup', with_local_site=True)

        self._login_user(local_site=True, admin=True)
        self.apiDelete(get_review_group_item_url('sitegroup',
                                                 self.local_site_name),
                       expected_status=204)
Example #10
0
    def test_get_group_invite_only_with_permission_denied_error(self):
        """Testing the GET groups/<id>/ API with invite-only and Permission Denied error"""
        group = Group.objects.create(name='test-group', invite_only=True)

        rsp = self.apiGet(get_review_group_item_url(group.name),
                          expected_status=403)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
Example #11
0
    def test_delete_group(self):
        """Testing the DELETE groups/<id>/ API"""
        self._login_user(admin=True)
        group = Group.objects.create(name='test-group', invite_only=True)
        group.users.add(self.user)

        self.apiDelete(get_review_group_item_url('test-group'),
                       expected_status=204)
        self.assertFalse(Group.objects.filter(name='test-group').exists())
Example #12
0
    def test_get_invite_only(self):
        """Testing the GET groups/<id>/ API with invite-only"""
        group = Group.objects.create(name='test-group', invite_only=True)
        group.users.add(self.user)

        rsp = self.api_get(get_review_group_item_url(group.name),
                           expected_mimetype=review_group_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['group']['invite_only'], True)
Example #13
0
    def test_get_invite_only(self):
        """Testing the GET groups/<id>/ API with invite-only"""
        group = Group.objects.create(name='test-group', invite_only=True)
        group.users.add(self.user)

        rsp = self.apiGet(get_review_group_item_url(group.name),
                          expected_mimetype=review_group_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['group']['invite_only'], True)
    def test_delete(self):
        """Testing the DELETE groups/<id>/ API"""
        self._login_user(admin=True)
        group = Group.objects.create(name='test-group', invite_only=True)
        group.users.add(self.user)

        self.apiDelete(get_review_group_item_url('test-group'),
                       expected_status=204)
        self.assertFalse(Group.objects.filter(name='test-group').exists())
Example #15
0
    def test_get_group_public(self):
        """Testing the GET groups/<id>/ API"""
        group = Group.objects.create(name='test-group')

        rsp = self.apiGet(get_review_group_item_url(group.name),
                          expected_mimetype=review_group_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['group']['name'], group.name)
        self.assertEqual(rsp['group']['display_name'], group.display_name)
        self.assertEqual(rsp['group']['invite_only'], False)
    def test_get_public(self):
        """Testing the GET groups/<id>/ API"""
        group = Group.objects.create(name='test-group')

        rsp = self.apiGet(get_review_group_item_url(group.name),
                          expected_mimetype=review_group_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['group']['name'], group.name)
        self.assertEqual(rsp['group']['display_name'], group.display_name)
        self.assertEqual(rsp['group']['invite_only'], False)
Example #17
0
    def setup_basic_put_test(self, user, with_local_site, local_site_name,
                             put_valid_data):
        group = self.create_review_group(with_local_site=with_local_site)

        return (get_review_group_item_url(group.name, local_site_name),
                review_group_item_mimetype, {
                    'name': 'my-group',
                    'display_name': 'My Group',
                    'mailing_list': '*****@*****.**',
                }, group, [])
Example #18
0
    def test_get_group_with_site(self):
        """Testing the GET groups/<id>/ API with a local site"""
        self._login_user(local_site=True)
        group = self.create_review_group(with_local_site=True)

        rsp = self.apiGet(get_review_group_item_url(group.name,
                                                    self.local_site_name),
                          expected_mimetype=review_group_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['group']['name'], group.name)
        self.assertEqual(rsp['group']['display_name'], group.display_name)
    def test_get_with_site(self):
        """Testing the GET groups/<id>/ API with a local site"""
        self._login_user(local_site=True)
        group = self.create_review_group(with_local_site=True)

        rsp = self.apiGet(
            get_review_group_item_url(group.name, self.local_site_name),
            expected_mimetype=review_group_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['group']['name'], group.name)
        self.assertEqual(rsp['group']['display_name'], group.display_name)
Example #20
0
    def test_put_group_with_conflict(self):
        """Testing the PUT groups/<name>/ API with Group Already Exists error"""
        group = self.create_review_group(name='group1')
        group2 = self.create_review_group(name='group2')

        self._login_user(admin=True)
        rsp = self.apiPut(get_review_group_item_url(group.name),
                          {'name': group2.name},
                          expected_status=409)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], GROUP_ALREADY_EXISTS.code)
    def test_put_group_with_conflict(self):
        """Testing the PUT groups/<name>/ API with Group Already Exists error"""
        group = self.create_review_group(name='group1')
        group2 = self.create_review_group(name='group2')

        self._login_user(admin=True)
        rsp = self.apiPut(
            get_review_group_item_url(group.name),
            {'name': group2.name},
            expected_status=409)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], GROUP_ALREADY_EXISTS.code)
Example #22
0
    def test_put_with_no_access(self, local_site=None):
        """Testing the PUT groups/<name>/ API with no access"""
        group = self.create_review_group(
            with_local_site=(local_site is not None))

        rsp = self.apiPut(get_review_group_item_url(group.name, local_site), {
            'name': 'mygroup',
            'display_name': 'My Group',
            'mailing_list': '*****@*****.**',
        },
                          expected_status=403)

        self.assertEqual(rsp['stat'], 'fail')
Example #23
0
    def setup_basic_put_test(self, user, with_local_site, local_site_name,
                             put_valid_data):
        group = self.create_review_group(with_local_site=with_local_site)

        return (get_review_group_item_url(group.name, local_site_name),
                review_group_item_mimetype,
                {
                    'name': 'my-group',
                    'display_name': 'My Group',
                    'mailing_list': '*****@*****.**',
                },
                group,
                [])
    def test_get(self):
        """Testing the GET users/<username>/watched/review-groups/<id>/ API"""
        group = self.create_review_group()
        profile = self.user.get_profile()
        profile.starred_groups.add(group)

        expected_url = self.base_url + get_review_group_item_url(group.name)

        self.api_get(get_watched_review_group_item_url(self.user.username,
                                                       group.pk),
                     expected_status=302,
                     expected_headers={
                         'Location': expected_url,
                     })
    def test_get(self):
        """Testing the GET users/<username>/watched/review-groups/<id>/ API"""
        group = self.create_review_group()
        profile = self.user.get_profile()
        profile.starred_groups.add(group)

        expected_url = self.base_url + get_review_group_item_url(group.name)

        self.apiGet(
            get_watched_review_group_item_url(self.user.username, group.pk),
            expected_status=302,
            expected_headers={
                'Location': expected_url,
            })
Example #26
0
    def test_put_with_no_access(self, local_site=None):
        """Testing the PUT groups/<name>/ API with no access"""
        group = self.create_review_group(
            with_local_site=(local_site is not None))

        rsp = self.api_put(
            get_review_group_item_url(group.name, local_site),
            {
                'name': 'mygroup',
                'display_name': 'My Group',
                'mailing_list': '*****@*****.**',
            },
            expected_status=403)

        self.assertEqual(rsp['stat'], 'fail')
Example #27
0
    def test_delete_with_review_requests(self):
        """Testing the DELETE groups/<id>/ API with existing review requests"""
        self._login_user(admin=True)

        group = Group.objects.create(name='test-group', invite_only=True)
        group.users.add(self.user)

        repository = self.create_repository()
        request = ReviewRequest.objects.create(self.user, repository)
        request.target_groups.add(group)

        self.apiDelete(get_review_group_item_url('test-group'),
                       expected_status=204)

        request = ReviewRequest.objects.get(pk=request.id)
        self.assertEqual(request.target_groups.count(), 0)
Example #28
0
    def test_delete_with_review_requests(self):
        """Testing the DELETE groups/<id>/ API with existing review requests"""
        self._login_user(admin=True)

        group = Group.objects.create(name='test-group', invite_only=True)
        group.users.add(self.user)

        repository = self.create_repository()
        request = ReviewRequest.objects.create(self.user, repository)
        request.target_groups.add(group)

        self.api_delete(get_review_group_item_url('test-group'),
                        expected_status=204)

        request = ReviewRequest.objects.get(pk=request.id)
        self.assertEqual(request.target_groups.count(), 0)
    def test_get_with_site(self):
        """Testing the GET users/<username>/watched/review-groups/<id>/ API
        with access to a local site
        """
        user = self._login_user(local_site=True)

        group = self.create_review_group(with_local_site=True)
        profile = user.get_profile()
        profile.starred_groups.add(group)

        expected_url = (
            self.base_url +
            get_review_group_item_url(group.name, self.local_site_name))

        self.api_get(get_watched_review_group_item_url(user.username, group.pk,
                                                       self.local_site_name),
                     expected_status=302,
                     expected_headers={
                         'Location': expected_url,
                     })
    def test_get_with_site(self):
        """Testing the GET users/<username>/watched/review-groups/<id>/ API
        with access to a local site
        """
        user = self._login_user(local_site=True)

        group = self.create_review_group(with_local_site=True)
        profile = user.get_profile()
        profile.starred_groups.add(group)

        expected_url = (
            self.base_url +
            get_review_group_item_url(group.name, self.local_site_name))

        self.apiGet(
            get_watched_review_group_item_url(user.username, group.pk,
                                              self.local_site_name),
            expected_status=302,
            expected_headers={
                'Location': expected_url,
            })
Example #31
0
    def test_put_group(self, local_site=None):
        """Testing the PUT groups/<name>/ API"""
        name = 'my-group'
        display_name = 'My Group'
        mailing_list = '*****@*****.**'

        group = self.create_review_group(
            with_local_site=(local_site is not None))

        self._login_user(admin=True)
        rsp = self.apiPut(get_review_group_item_url(group.name, local_site), {
            'name': name,
            'display_name': display_name,
            'mailing_list': mailing_list,
        },
                          expected_mimetype=review_group_item_mimetype)

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

        group = Group.objects.get(pk=group.pk)
        self.assertEqual(group.local_site, local_site)
        self.assertEqual(group.name, name)
        self.assertEqual(group.display_name, display_name)
        self.assertEqual(group.mailing_list, mailing_list)
Example #32
0
 def test_get_group_with_site_no_access(self):
     """Testing the GET groups/<id>/ API with a local site and Permission Denied error"""
     self.apiGet(get_review_group_item_url('sitegroup',
                                           self.local_site_name),
                 expected_status=403)
Example #33
0
    def test_get_not_modified(self):
        """Testing the GET groups/<id>/ API with Not Modified response"""
        Group.objects.create(name='test-group')

        self._testHttpCaching(get_review_group_item_url('test-group'),
                              check_etags=True)
Example #34
0
    def setup_basic_get_test(self, user, with_local_site, local_site_name):
        group = self.create_review_group(with_local_site=with_local_site)

        return (get_review_group_item_url(group.name, local_site_name),
                review_group_item_mimetype,
                group)
Example #35
0
    def setup_basic_delete_test(self, user, with_local_site, local_site_name):
        group = self.create_review_group(with_local_site=with_local_site)

        return (get_review_group_item_url(group.name, local_site_name),
                [group.name])
Example #36
0
    def setup_basic_delete_test(self, user, with_local_site, local_site_name):
        group = self.create_review_group(with_local_site=with_local_site)

        return (get_review_group_item_url(group.name,
                                          local_site_name), [group.name])
Example #37
0
    def setup_basic_get_test(self, user, with_local_site, local_site_name):
        group = self.create_review_group(with_local_site=with_local_site)

        return (get_review_group_item_url(group.name, local_site_name),
                review_group_item_mimetype, group)
Example #38
0
    def test_get_not_modified(self):
        """Testing the GET groups/<id>/ API with Not Modified response"""
        Group.objects.create(name='test-group')

        self._testHttpCaching(get_review_group_item_url('test-group'),
                              check_etags=True)