def test_put_clear_users(self):
        """Testing PUT <URL> API with empty users field"""
        doc = User.objects.get(username='******')
        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')
        default_reviewer.people.add(doc)

        self._login_user(admin=True)

        rsp = self.api_put(
            get_default_reviewer_item_url(default_reviewer.pk),
            {
                'file_regex': '.*',
                'name': 'default1',
                'users': ''
            },
            expected_mimetype=default_reviewer_item_mimetype)

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

        default_reviewer = DefaultReviewer.objects.get(pk=default_reviewer.pk)
        self.assertEqual(list(default_reviewer.people.all()), [])

        self.assertIn('default_reviewer', rsp)
        self.compare_item(rsp['default_reviewer'], default_reviewer)
    def test_put_repositories_only_comma(self):
        """Testing PUT <URL> API with repositories field containing only
        commas
        """
        repository = self.create_repository()
        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')
        default_reviewer.repository.add(repository)

        self._login_user(admin=True)

        rsp = self.api_put(
            get_default_reviewer_item_url(default_reviewer.pk),
            {
                'file_regex': '.*',
                'name': 'default1',
                'repositories': ' , , , ',
            },
            expected_mimetype=default_reviewer_item_mimetype)

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

        default_reviewer = DefaultReviewer.objects.get(pk=default_reviewer.pk)
        self.assertEqual(list(default_reviewer.repository.all()), [])

        self.assertIn('default_reviewer', rsp)
        self.compare_item(rsp['default_reviewer'], default_reviewer)
Пример #3
0
    def test_get_default_reviewer(self):
        """Testing the GET default-reviewers/<id>/ API"""
        user = User.objects.get(username='******')
        group = Group.objects.create(name='group1')
        repository = self.create_repository()

        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')
        default_reviewer.people.add(user)
        default_reviewer.groups.add(group)
        default_reviewer.repository.add(repository)

        rsp = self.apiGet(get_default_reviewer_item_url(default_reviewer.pk),
                          expected_mimetype=default_reviewer_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['default_reviewer']['name'], 'default1')
        self.assertEqual(rsp['default_reviewer']['file_regex'], '.*')

        users = rsp['default_reviewer']['users']
        self.assertEqual(len(users), 1)
        self.assertEqual(users[0]['title'], user.username)

        groups = rsp['default_reviewer']['groups']
        self.assertEqual(len(groups), 1)
        self.assertEqual(groups[0]['title'], group.name)

        repos = rsp['default_reviewer']['repositories']
        self.assertEqual(len(repos), 1)
        self.assertEqual(repos[0]['title'], repository.name)
Пример #4
0
    def test_put_clear_users(self):
        """Testing PUT <URL> API with empty users field"""
        doc = User.objects.get(username='******')
        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')
        default_reviewer.people.add(doc)

        self._login_user(admin=True)

        rsp = self.api_put(
            get_default_reviewer_item_url(default_reviewer.pk),
            {
                'file_regex': '.*',
                'name': 'default1',
                'users': ''
            },
            expected_mimetype=default_reviewer_item_mimetype)

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

        default_reviewer = DefaultReviewer.objects.get(pk=default_reviewer.pk)
        self.assertEqual(list(default_reviewer.people.all()), [])

        self.assertIn('default_reviewer', rsp)
        self.compare_item(rsp['default_reviewer'], default_reviewer)
Пример #5
0
    def test_put_repositories_only_comma(self):
        """Testing PUT <URL> API with repositories field containing only
        commas
        """
        repository = self.create_repository()
        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')
        default_reviewer.repository.add(repository)

        self._login_user(admin=True)

        rsp = self.api_put(
            get_default_reviewer_item_url(default_reviewer.pk),
            {
                'file_regex': '.*',
                'name': 'default1',
                'repositories': ' , , , ',
            },
            expected_mimetype=default_reviewer_item_mimetype)

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

        default_reviewer = DefaultReviewer.objects.get(pk=default_reviewer.pk)
        self.assertEqual(list(default_reviewer.repository.all()), [])

        self.assertIn('default_reviewer', rsp)
        self.compare_item(rsp['default_reviewer'], default_reviewer)
    def test_get_default_reviewer(self):
        """Testing the GET default-reviewers/<id>/ API"""
        user = User.objects.get(username='******')
        group = Group.objects.create(name='group1')
        repository = self.create_repository()

        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*')
        default_reviewer.people.add(user)
        default_reviewer.groups.add(group)
        default_reviewer.repository.add(repository)

        rsp = self.apiGet(get_default_reviewer_item_url(default_reviewer.pk),
                          expected_mimetype=default_reviewer_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['default_reviewer']['name'], 'default1')
        self.assertEqual(rsp['default_reviewer']['file_regex'], '.*')

        users = rsp['default_reviewer']['users']
        self.assertEqual(len(users), 1)
        self.assertEqual(users[0]['title'], user.username)

        groups = rsp['default_reviewer']['groups']
        self.assertEqual(len(groups), 1)
        self.assertEqual(groups[0]['title'], group.name)

        repos = rsp['default_reviewer']['repositories']
        self.assertEqual(len(repos), 1)
        self.assertEqual(repos[0]['title'], repository.name)
    def test_get_default_reviewer_not_modified(self):
        """Testing the GET default-reviewers/<id>/ API with Not Modified response"""
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*')

        self._testHttpCaching(
            get_default_reviewer_item_url(default_reviewer.pk),
            check_etags=True)
Пример #8
0
    def test_get_default_reviewer_not_modified(self):
        """Testing the GET default-reviewers/<id>/ API with Not Modified response"""
        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')

        self._testHttpCaching(get_default_reviewer_item_url(
            default_reviewer.pk),
                              check_etags=True)
Пример #9
0
    def test_get_default_reviewer_with_site_no_access(self):
        """Testing the GET default-reviewers/<id>/ API with a local site and Permission Denied error"""
        local_site = LocalSite.objects.get(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        self.apiGet(get_default_reviewer_item_url(default_reviewer.pk,
                                                  self.local_site_name),
                    expected_status=403)
Пример #10
0
    def test_delete_default_reviewer_with_permission_denied_error(self):
        """Testing the DELETE default-reviewers/<id>/ API with Permission Denied error"""
        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')

        self.apiDelete(get_default_reviewer_item_url(default_reviewer.pk),
                       expected_status=403)
        self.assertTrue(
            DefaultReviewer.objects.filter(name='default1').exists())
Пример #11
0
    def test_delete_default_reviewer_with_permission_denied_error(self):
        """Testing the DELETE default-reviewers/<id>/ API with Permission Denied error"""
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*')

        self.apiDelete(get_default_reviewer_item_url(default_reviewer.pk),
                       expected_status=403)
        self.assertTrue(
            DefaultReviewer.objects.filter(name='default1').exists())
Пример #12
0
    def test_get_default_reviewer_with_site_no_access(self):
        """Testing the GET default-reviewers/<id>/ API with a local site and Permission Denied error"""
        local_site = LocalSite.objects.get(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        self.apiGet(get_default_reviewer_item_url(default_reviewer.pk,
                                                  self.local_site_name),
                    expected_status=403)
Пример #13
0
    def test_put_default_reviewer_with_permission_denied(self):
        """Testing the POST default-reviewers/ API with Permission Denied error"""
        self._login_user()

        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')

        self.apiPut(get_default_reviewer_item_url(default_reviewer.pk),
                    {'name': 'default2'},
                    expected_status=403)
Пример #14
0
    def test_delete_default_reviewer(self):
        """Testing the DELETE default-reviewers/<id>/ API"""
        self._login_user(admin=True)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*')

        self.apiDelete(get_default_reviewer_item_url(default_reviewer.pk),
                       expected_status=204)
        self.assertFalse(
            DefaultReviewer.objects.filter(name='default1').exists())
Пример #15
0
    def test_delete_default_reviewer(self):
        """Testing the DELETE default-reviewers/<id>/ API"""
        self._login_user(admin=True)
        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')

        self.apiDelete(get_default_reviewer_item_url(default_reviewer.pk),
                       expected_status=204)
        self.assertFalse(
            DefaultReviewer.objects.filter(name='default1').exists())
Пример #16
0
    def test_put_default_reviewer_with_permission_denied(self):
        """Testing the POST default-reviewers/ API with Permission Denied error"""
        self._login_user()

        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*')

        self.apiPut(
            get_default_reviewer_item_url(default_reviewer.pk),
            {'name': 'default2'},
            expected_status=403)
Пример #17
0
    def test_delete_default_reviewer_with_site_and_permission_denied_error(self):
        """Testing the DELETE default-reviewers/<id>/ API with a local site and Permission Denied error"""
        local_site = LocalSite.objects.get(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        self.apiDelete(get_default_reviewer_item_url(default_reviewer.pk,
                                                     self.local_site_name),
                       expected_status=403)
        self.assertTrue(
            DefaultReviewer.objects.filter(name='default1').exists())
Пример #18
0
    def setup_basic_delete_test(self, user, with_local_site, local_site_name):
        if with_local_site:
            local_site = self.get_local_site(name=local_site_name)
        else:
            local_site = None

        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        return (get_default_reviewer_item_url(default_reviewer.pk,
                                              local_site_name), [])
Пример #19
0
    def test_put_default_reviewer_with_permission_denied_and_local_site(self):
        """Testing the PUT default-reviewers/<id>/ API with a local site and Permission Denied error"""
        self._login_user()

        local_site = LocalSite.objects.get(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        self.apiPut(get_default_reviewer_item_url(default_reviewer.pk,
                                                  self.local_site_name),
                    {'name': 'default2'},
                    expected_status=403)
Пример #20
0
    def test_delete_default_reviewer_with_site_and_permission_denied_error(
            self):
        """Testing the DELETE default-reviewers/<id>/ API with a local site and Permission Denied error"""
        local_site = LocalSite.objects.get(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        self.apiDelete(get_default_reviewer_item_url(default_reviewer.pk,
                                                     self.local_site_name),
                       expected_status=403)
        self.assertTrue(
            DefaultReviewer.objects.filter(name='default1').exists())
Пример #21
0
    def test_put_default_reviewer_with_permission_denied_and_local_site(self):
        """Testing the PUT default-reviewers/<id>/ API with a local site and Permission Denied error"""
        self._login_user()

        local_site = LocalSite.objects.get(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        self.apiPut(
            get_default_reviewer_item_url(default_reviewer.pk,
                                          self.local_site_name),
            {'name': 'default2'},
            expected_status=403)
Пример #22
0
    def test_put_default_reviewer_with_invalid_repository(self):
        """Testing the PUT default-reviewers/<id>/ API with invalid repository"""
        self._login_user(admin=True)

        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')

        rsp = self.apiPut(get_default_reviewer_item_url(default_reviewer.pk),
                          {'repositories': '12345'},
                          expected_status=400)

        self.assertTrue('fields' in rsp)
        self.assertTrue('repositories' in rsp['fields'])
Пример #23
0
    def test_delete_default_reviewer_with_site(self):
        """Testing the DELETE default-reviewers/<id>/ API with a local site"""
        self._login_user(local_site=True, admin=True)

        local_site = LocalSite.objects.get(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        self.apiDelete(get_default_reviewer_item_url(default_reviewer.pk,
                                                     self.local_site_name),
                       expected_status=204)
        self.assertFalse(
            DefaultReviewer.objects.filter(name='default1').exists())
Пример #24
0
    def test_put_with_invalid_group(self):
        """Testing the PUT default-reviewers/<id>/ API with invalid group"""
        self._login_user(admin=True)

        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')

        rsp = self.api_put(get_default_reviewer_item_url(default_reviewer.pk),
                           {'groups': 'foo'},
                           expected_status=400)

        self.assertIn('fields', rsp)
        self.assertIn('groups', rsp['fields'])
Пример #25
0
    def test_delete_default_reviewer_with_site(self):
        """Testing the DELETE default-reviewers/<id>/ API with a local site"""
        self._login_user(local_site=True, admin=True)

        local_site = LocalSite.objects.get(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        self.apiDelete(get_default_reviewer_item_url(default_reviewer.pk,
                                                     self.local_site_name),
                       expected_status=204)
        self.assertFalse(
            DefaultReviewer.objects.filter(name='default1').exists())
    def test_put_with_invalid_group(self):
        """Testing the PUT default-reviewers/<id>/ API with invalid group"""
        self._login_user(admin=True)

        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*')

        rsp = self.api_put(
            get_default_reviewer_item_url(default_reviewer.pk),
            {'groups': 'foo'},
            expected_status=400)

        self.assertIn('fields', rsp)
        self.assertIn('groups', rsp['fields'])
Пример #27
0
    def test_put_default_reviewer_with_user_invalid_site(self):
        """Testing the PUT default-reviewers/<id>/ API with user and invalid site"""
        self._login_user(admin=True)

        local_site = LocalSite.objects.get(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        rsp = self.apiPut(get_default_reviewer_item_url(
            default_reviewer.pk, self.local_site_name), {'users': 'grumpy'},
                          expected_status=400)

        self.assertTrue('fields' in rsp)
        self.assertTrue('users' in rsp['fields'])
Пример #28
0
    def test_get_default_reviewer_with_site(self):
        """Testing the GET default-reviewers/<id>/ API with a local site"""
        self._login_user(local_site=True)

        local_site = LocalSite.objects.get(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        rsp = self.apiGet(get_default_reviewer_item_url(
            default_reviewer.pk, self.local_site_name),
                          expected_mimetype=default_reviewer_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['default_reviewer']['name'], 'default1')
        self.assertEqual(rsp['default_reviewer']['file_regex'], '.*')
    def setup_basic_delete_test(self, user, with_local_site, local_site_name):
        if with_local_site:
            local_site = self.get_local_site(name=local_site_name)
        else:
            local_site = None

        default_reviewer = DefaultReviewer.objects.create(
            name='default1',
            file_regex='.*',
            local_site=local_site)

        return (get_default_reviewer_item_url(default_reviewer.pk,
                                              local_site_name),
                [])
Пример #30
0
    def test_put_default_reviewer_with_invalid_repository(self):
        """Testing the PUT default-reviewers/<id>/ API with invalid repository"""
        self._login_user(admin=True)

        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*')

        rsp = self.apiPut(
            get_default_reviewer_item_url(default_reviewer.pk),
            {'repositories': '12345'},
            expected_status=400)

        self.assertTrue('fields' in rsp)
        self.assertTrue('repositories' in rsp['fields'])
Пример #31
0
    def test_get_default_reviewer_with_site(self):
        """Testing the GET default-reviewers/<id>/ API with a local site"""
        self._login_user(local_site=True)

        local_site = LocalSite.objects.get(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        rsp = self.apiGet(get_default_reviewer_item_url(default_reviewer.pk,
                                                        self.local_site_name),
                          expected_mimetype=default_reviewer_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['default_reviewer']['name'], 'default1')
        self.assertEqual(rsp['default_reviewer']['file_regex'], '.*')
Пример #32
0
    def setup_basic_put_test(self, user, with_local_site, local_site_name,
                             put_valid_data):
        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')

        if with_local_site:
            local_site = self.get_local_site(name=local_site_name)
            local_site.users.add(User.objects.get(username='******'))
            local_site.users.add(User.objects.get(username='******'))

            default_reviewer.local_site = local_site
            default_reviewer.save()

        default_reviewer.people.add(User.objects.get(username='******'))
        default_reviewer.groups.add(
            self.create_review_group(name='group1',
                                     with_local_site=with_local_site))

        repo1 = self.create_repository(with_local_site=with_local_site,
                                       name='Test Repo 1',
                                       path='test-repo-1')
        default_reviewer.repository.add(repo1)

        if put_valid_data:
            self.create_review_group(name='group2',
                                     with_local_site=with_local_site)
            repo2 = self.create_repository(with_local_site=with_local_site,
                                           name='Test Repo 2',
                                           path='test-repo-2')

            put_data = {
                'name':
                'New name',
                'file_regex':
                '/foo/',
                'users':
                'doc,dopey',
                'groups':
                'group1,group2',
                'repositories':
                ','.join([six.text_type(repo1.pk),
                          six.text_type(repo2.pk)]),
            }
        else:
            put_data = {}

        return (get_default_reviewer_item_url(default_reviewer.pk,
                                              local_site_name),
                default_reviewer_item_mimetype, put_data, default_reviewer, [])
Пример #33
0
    def test_put_default_reviewer_with_repository_invalid_site(self):
        """Testing the PUT default-reviewers/<id>/ API with repository and invalid site"""
        repository = self.create_repository(with_local_site=True)

        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')

        self._login_user(admin=True)

        rsp = self.apiPut(get_default_reviewer_item_url(default_reviewer.pk),
                          {'repositories': str(repository.pk)},
                          expected_status=400)

        self.assertTrue('fields' in rsp)
        self.assertTrue('repositories' in rsp['fields'])
Пример #34
0
    def test_put_default_reviewer_with_group_invalid_site(self):
        """Testing the PUT default-reviewers/<id>/ API with group and invalid site"""
        self._login_user(admin=True)

        local_site = LocalSite.objects.get(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*')
        Group.objects.create(name='group1', local_site=local_site)

        rsp = self.apiPut(
            get_default_reviewer_item_url(default_reviewer.pk),
            {'groups': 'group1'},
            expected_status=400)

        self.assertTrue('fields' in rsp)
        self.assertTrue('groups' in rsp['fields'])
Пример #35
0
    def test_put_default_reviewer_with_repository_invalid_site(self):
        """Testing the PUT default-reviewers/<id>/ API with repository and invalid site"""
        repository = self.create_repository(with_local_site=True)

        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*')

        self._login_user(admin=True)

        rsp = self.apiPut(
            get_default_reviewer_item_url(default_reviewer.pk),
            {'repositories': str(repository.pk)},
            expected_status=400)

        self.assertTrue('fields' in rsp)
        self.assertTrue('repositories' in rsp['fields'])
    def setup_basic_put_test(self, user, with_local_site, local_site_name,
                             put_valid_data):
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*')

        if with_local_site:
            local_site = self.get_local_site(name=local_site_name)
            local_site.users.add(User.objects.get(username='******'))
            local_site.users.add(User.objects.get(username='******'))

            default_reviewer.local_site = local_site
            default_reviewer.save()

        default_reviewer.people.add(User.objects.get(username='******'))
        default_reviewer.groups.add(
            self.create_review_group(name='group1',
                                     with_local_site=with_local_site))

        repo1 = self.create_repository(with_local_site=with_local_site,
                                       name='Test Repo 1',
                                       path='test-repo-1')
        default_reviewer.repository.add(repo1)

        if put_valid_data:
            self.create_review_group(name='group2',
                                     with_local_site=with_local_site)
            repo2 = self.create_repository(with_local_site=with_local_site,
                                           name='Test Repo 2',
                                           path='test-repo-2')

            put_data = {
                'name': 'New name',
                'file_regex': '/foo/',
                'users': 'doc,dopey',
                'groups': 'group1,group2',
                'repositories': ','.join([six.text_type(repo1.pk),
                                          six.text_type(repo2.pk)]),
            }
        else:
            put_data = {}

        return (get_default_reviewer_item_url(default_reviewer.pk,
                                              local_site_name),
                default_reviewer_item_mimetype,
                put_data,
                default_reviewer,
                [])
Пример #37
0
    def test_put_with_group_invalid_site(self):
        """Testing the PUT default-reviewers/<id>/ API
        with group and invalid site
        """
        self._login_user(admin=True)

        local_site = self.get_local_site(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')
        Group.objects.create(name='group1', local_site=local_site)

        rsp = self.api_put(get_default_reviewer_item_url(default_reviewer.pk),
                           {'groups': 'group1'},
                           expected_status=400)

        self.assertIn('fields', rsp)
        self.assertIn('groups', rsp['fields'])
    def test_put_with_user_invalid_site(self):
        """Testing the PUT default-reviewers/<id>/ API
        with user and invalid site
        """
        self._login_user(admin=True)

        local_site = self.get_local_site(name=self.local_site_name)
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)

        rsp = self.api_put(
            get_default_reviewer_item_url(default_reviewer.pk,
                                          self.local_site_name),
            {'users': 'grumpy'},
            expected_status=400)

        self.assertIn('fields', rsp)
        self.assertIn('users', rsp['fields'])
Пример #39
0
    def setup_basic_get_test(self, user, with_local_site, local_site_name):
        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.*')

        if with_local_site:
            default_reviewer.local_site = \
                self.get_local_site(name=local_site_name)
            default_reviewer.save()

        default_reviewer.people.add(User.objects.get(username='******'))
        default_reviewer.groups.add(
            self.create_review_group(name='group1',
                                     with_local_site=with_local_site))
        default_reviewer.repository.add(
            self.create_repository(with_local_site=with_local_site))

        return (get_default_reviewer_item_url(default_reviewer.pk,
                                              local_site_name),
                default_reviewer_item_mimetype, default_reviewer)
    def setup_basic_get_test(self, user, with_local_site, local_site_name):
        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*')

        if with_local_site:
            default_reviewer.local_site = \
                self.get_local_site(name=local_site_name)
            default_reviewer.save()

        default_reviewer.people.add(User.objects.get(username='******'))
        default_reviewer.groups.add(
            self.create_review_group(name='group1',
                                     with_local_site=with_local_site))
        default_reviewer.repository.add(
            self.create_repository(with_local_site=with_local_site))

        return (get_default_reviewer_item_url(default_reviewer.pk,
                                              local_site_name),
                default_reviewer_item_mimetype,
                default_reviewer)
Пример #41
0
    def test_put_default_reviewer(self, local_site=None):
        """Testing the PUT default-reviewers/<id>/ API"""
        name = 'my-default-reviewer'
        file_regex = '/foo/'
        git_tool = Tool.objects.get(name='Git')

        old_user = User.objects.get(username='******')
        old_group = Group.objects.create(name='group3', local_site=local_site)
        old_repo = Repository.objects.create(name='Old Repo',
                                             local_site=local_site,
                                             path='old-repo',
                                             tool=git_tool)

        user1 = User.objects.get(username='******')
        user2 = User.objects.get(username='******')
        group1 = Group.objects.create(name='group1', local_site=local_site)
        group2 = Group.objects.create(name='group2', local_site=local_site)
        repo1 = Repository.objects.create(name='Test Repo 1',
                                          local_site=local_site,
                                          path='test-repo-1',
                                          tool=git_tool)
        repo2 = Repository.objects.create(name='Test Repo 2',
                                          local_site=local_site,
                                          path='test-repo-2',
                                          tool=git_tool)

        # For the tests, make sure these are what we expect.
        if local_site:
            local_site.users.add(user1)
            local_site.users.add(user2)
            local_site.users.add(old_user)

        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)
        default_reviewer.groups.add(old_group)
        default_reviewer.repository.add(old_repo)
        default_reviewer.people.add(old_user)

        self._login_user(admin=True)
        rsp = self.apiPut(
            get_default_reviewer_item_url(default_reviewer.pk, local_site), {
                'name': name,
                'file_regex': file_regex,
                'users': ','.join([user1.username, user2.username]),
                'groups': ','.join([group1.name, group2.name]),
                'repositories': ','.join([str(repo1.pk),
                                          str(repo2.pk)]),
            },
            expected_mimetype=default_reviewer_item_mimetype)

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

        default_reviewer = DefaultReviewer.objects.get(pk=default_reviewer.pk)
        self.assertEqual(default_reviewer.local_site, local_site)
        self.assertEqual(default_reviewer.name, name)
        self.assertEqual(default_reviewer.file_regex, file_regex)

        people = list(default_reviewer.people.all())
        self.assertEqual(len(people), 2)
        self.assertEqual(people[0], user1)
        self.assertEqual(people[1], user2)

        groups = list(default_reviewer.groups.all())
        self.assertEqual(len(groups), 2)
        self.assertEqual(groups[0], group1)
        self.assertEqual(groups[1], group2)

        repos = list(default_reviewer.repository.all())
        self.assertEqual(len(repos), 2)
        self.assertEqual(repos[0], repo1)
        self.assertEqual(repos[1], repo2)
Пример #42
0
    def test_put_default_reviewer(self, local_site=None):
        """Testing the PUT default-reviewers/<id>/ API"""
        name = 'my-default-reviewer'
        file_regex = '/foo/'
        git_tool = Tool.objects.get(name='Git')

        old_user = User.objects.get(username='******')
        old_group = Group.objects.create(name='group3', local_site=local_site)
        old_repo = Repository.objects.create(name='Old Repo',
                                             local_site=local_site,
                                             path='old-repo',
                                             tool=git_tool)

        user1 = User.objects.get(username='******')
        user2 = User.objects.get(username='******')
        group1 = Group.objects.create(name='group1', local_site=local_site)
        group2 = Group.objects.create(name='group2', local_site=local_site)
        repo1 = Repository.objects.create(name='Test Repo 1',
                                          local_site=local_site,
                                          path='test-repo-1',
                                          tool=git_tool)
        repo2 = Repository.objects.create(name='Test Repo 2',
                                          local_site=local_site,
                                          path='test-repo-2',
                                          tool=git_tool)

        # For the tests, make sure these are what we expect.
        if local_site:
            local_site.users.add(user1)
            local_site.users.add(user2)
            local_site.users.add(old_user)

        default_reviewer = DefaultReviewer.objects.create(
            name='default1', file_regex='.*', local_site=local_site)
        default_reviewer.groups.add(old_group)
        default_reviewer.repository.add(old_repo)
        default_reviewer.people.add(old_user)

        self._login_user(admin=True)
        rsp = self.apiPut(
            get_default_reviewer_item_url(default_reviewer.pk, local_site),
            {
                'name': name,
                'file_regex': file_regex,
                'users': ','.join([user1.username, user2.username]),
                'groups': ','.join([group1.name, group2.name]),
                'repositories': ','.join([str(repo1.pk), str(repo2.pk)]),
            },
            expected_mimetype=default_reviewer_item_mimetype)

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

        default_reviewer = DefaultReviewer.objects.get(pk=default_reviewer.pk)
        self.assertEqual(default_reviewer.local_site, local_site)
        self.assertEqual(default_reviewer.name, name)
        self.assertEqual(default_reviewer.file_regex, file_regex)

        people = list(default_reviewer.people.all())
        self.assertEqual(len(people), 2)
        self.assertEqual(people[0], user1)
        self.assertEqual(people[1], user2)

        groups = list(default_reviewer.groups.all())
        self.assertEqual(len(groups), 2)
        self.assertEqual(groups[0], group1)
        self.assertEqual(groups[1], group2)

        repos = list(default_reviewer.repository.all())
        self.assertEqual(len(repos), 2)
        self.assertEqual(repos[0], repo1)
        self.assertEqual(repos[1], repo2)