Example #1
0
 def test_get_repositories(self):
     """Testing the GET repositories/ API"""
     rsp = self.apiGet(get_repository_list_url(),
                       expected_mimetype=repository_list_mimetype)
     self.assertEqual(rsp['stat'], 'ok')
     self.assertEqual(len(rsp['repositories']),
                      Repository.objects.accessible(self.user).count())
Example #2
0
    def _post_repository(self, use_local_site, data={}, expected_status=201):
        repo_name = 'Test Repository'
        repo_path = 'file://' + os.path.abspath(
            os.path.join(os.path.dirname(scmtools.__file__), 'testdata',
                         'svn_repo'))

        if 200 <= expected_status < 300:
            expected_mimetype = repository_item_mimetype
        else:
            expected_mimetype = None

        if use_local_site:
            local_site_name = self.local_site_name
        else:
            local_site_name = None

        rsp = self.apiPost(get_repository_list_url(local_site_name),
                           dict(
                               {
                                   'name': repo_name,
                                   'path': repo_path,
                                   'tool': 'Subversion',
                               }, **data),
                           expected_status=expected_status,
                           expected_mimetype=expected_mimetype)

        if 200 <= expected_status < 300:
            self._verify_repository_info(rsp, repo_name, repo_path, data)

            self.assertEqual(
                rsp['repository']['links']['self']['href'],
                self.base_url + get_repository_item_url(
                    rsp['repository']['id'], local_site_name))

        return rsp
Example #3
0
    def _post_repository(self, use_local_site, data={}, expected_status=201):
        repo_name = 'Test Repository'

        if 200 <= expected_status < 300:
            expected_mimetype = repository_item_mimetype
        else:
            expected_mimetype = None

        if use_local_site:
            local_site_name = self.local_site_name
        else:
            local_site_name = None

        rsp = self.apiPost(
            get_repository_list_url(local_site_name),
            dict({
                'name': repo_name,
                'path': self.sample_repo_path,
                'tool': 'Test',
            }, **data),
            expected_status=expected_status,
            expected_mimetype=expected_mimetype)

        if 200 <= expected_status < 300:
            self._verify_repository_info(rsp, repo_name, self.sample_repo_path,
                                         data)

            self.assertEqual(
                rsp['repository']['links']['self']['href'],
                self.base_url +
                get_repository_item_url(rsp['repository']['id'],
                                        local_site_name))

        return rsp
Example #4
0
 def test_get_with_show_visible(self):
     """Testing the GET repositories/ API with show_invisible=True"""
     rsp = self.apiGet(
         get_repository_list_url(), query={"show-invisible": True}, expected_mimetype=repository_list_mimetype
     )
     self.assertEqual(rsp["stat"], "ok")
     self.assertEqual(len(rsp["repositories"]), Repository.objects.accessible(self.user, visible_only=False).count())
Example #5
0
    def test_get_repositories_with_username_many(self):
        """Testing the GET repositories/?username= API
        and comma-separated list
        """
        hosting_account = HostingServiceAccount.objects.create(service_name="github", username="******")

        Repository.objects.create(
            name="My New Repository 1",
            path="https://example.com",
            tool=Tool.objects.get(name="Git"),
            hosting_account=hosting_account,
        )

        Repository.objects.create(
            name="My New Repository 2",
            path="https://example.com",
            username="******",
            tool=Tool.objects.get(name="Subversion"),
        )

        rsp = self.api_get(
            get_repository_list_url() + "?username=my-username,my-username-2",
            expected_mimetype=repository_list_mimetype,
        )
        self.assertEqual(rsp["stat"], "ok")
        self.assertEqual(len(rsp["repositories"]), 2)
        self.assertEqual(rsp["repositories"][0]["name"], "My New Repository 1")
        self.assertEqual(rsp["repositories"][1]["name"], "My New Repository 2")
Example #6
0
    def setup_basic_get_test(self, user, with_local_site, local_site_name, populate_items):
        if populate_items:
            items = [self.create_repository(tool_name="Test", with_local_site=with_local_site)]
        else:
            items = []

        return (get_repository_list_url(local_site_name), repository_list_mimetype, items)
Example #7
0
    def _post_repository(self, use_local_site, data={}, expected_status=201):
        repo_name = "Test Repository"

        if 200 <= expected_status < 300:
            expected_mimetype = repository_item_mimetype
        else:
            expected_mimetype = None

        if use_local_site:
            local_site_name = self.local_site_name
        else:
            local_site_name = None

        rsp = self.api_post(
            get_repository_list_url(local_site_name),
            dict({"name": repo_name, "path": self.sample_repo_path, "tool": "Test"}, **data),
            expected_status=expected_status,
            expected_mimetype=expected_mimetype,
        )

        if 200 <= expected_status < 300:
            self._verify_repository_info(rsp, repo_name, self.sample_repo_path, data)

            self.assertEqual(
                rsp["repository"]["links"]["self"]["href"],
                self.base_url + get_repository_item_url(rsp["repository"]["id"], local_site_name),
            )

        return rsp
Example #8
0
 def test_get_repositories(self):
     """Testing the GET repositories/ API"""
     rsp = self.apiGet(get_repository_list_url(),
                       expected_mimetype=repository_list_mimetype)
     self.assertEqual(rsp['stat'], 'ok')
     self.assertEqual(len(rsp['repositories']),
                      Repository.objects.accessible(self.user).count())
Example #9
0
    def test_get_repositories_with_username_many(self):
        """Testing the GET repositories/?username= API
        and comma-separated list
        """
        hosting_account = HostingServiceAccount.objects.create(
            service_name='github',
            username='******')

        Repository.objects.create(
            name='My New Repository 1',
            path='https://example.com',
            tool=Tool.objects.get(name='Git'),
            hosting_account=hosting_account)

        Repository.objects.create(
            name='My New Repository 2',
            path='https://example.com',
            username='******',
            tool=Tool.objects.get(name='Subversion'))

        rsp = self.apiGet(
            get_repository_list_url() + '?username=my-username,my-username-2',
            expected_mimetype=repository_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(len(rsp['repositories']), 2)
        self.assertEqual(rsp['repositories'][0]['name'],
                         'My New Repository 1')
        self.assertEqual(rsp['repositories'][1]['name'],
                         'My New Repository 2')
Example #10
0
    def setup_basic_post_test(self, user, with_local_site, local_site_name, post_valid_data):

        return (
            get_repository_list_url(local_site_name),
            repository_item_mimetype,
            {"name": "Test Repository", "path": self.sample_repo_path, "tool": "Test"},
            [],
        )
Example #11
0
 def test_get_repositories_with_site(self):
     """Testing the GET repositories/ API with a local site"""
     self._login_user(local_site=True)
     rsp = self.apiGet(get_repository_list_url(self.local_site_name),
                       expected_mimetype=repository_list_mimetype)
     self.assertEqual(len(rsp['repositories']),
                      Repository.objects.filter(
                          local_site__name=self.local_site_name).count())
Example #12
0
    def test_get_repositories_with_name_or_path(self):
        """Testing the GET repositories/?name-or-path= API"""
        self.create_repository(name='test1', path='dummy1', tool_name='Test')
        self.create_repository(name='test2', path='dummy2', tool_name='Test')
        self.create_repository(name='test3', path='dummy3', tool_name='Test')

        rsp = self.apiGet(get_repository_list_url() + '?name-or-path=test1',
                          expected_mimetype=repository_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(len(rsp['repositories']), 1)
        self.assertEqual(rsp['repositories'][0]['name'], 'test1')

        rsp = self.apiGet(get_repository_list_url() + '?name-or-path=dummy2',
                          expected_mimetype=repository_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(len(rsp['repositories']), 1)
        self.assertEqual(rsp['repositories'][0]['name'], 'test2')
Example #13
0
    def test_get_repositories_with_tool(self):
        """Testing the GET repositories/?tool= API"""
        self.create_repository(name="test1", path="dummy1", tool_name="Git")
        self.create_repository(name="test2", path="dummy2", tool_name="Test")

        rsp = self.api_get(get_repository_list_url() + "?tool=Git", expected_mimetype=repository_list_mimetype)
        self.assertEqual(rsp["stat"], "ok")
        self.assertEqual(len(rsp["repositories"]), 1)
        self.assertEqual(rsp["repositories"][0]["name"], "test1")
Example #14
0
    def setup_basic_post_test(self, user, with_local_site, local_site_name,
                              post_valid_data):

        return (get_repository_list_url(local_site_name),
                repository_item_mimetype, {
                    'name': 'Test Repository',
                    'path': self.sample_repo_path,
                    'tool': 'Test',
                }, [])
Example #15
0
 def test_get_repositories_with_site(self):
     """Testing the GET repositories/ API with a local site"""
     self._login_user(local_site=True)
     rsp = self.apiGet(get_repository_list_url(self.local_site_name),
                       expected_mimetype=repository_list_mimetype)
     self.assertEqual(
         len(rsp['repositories']),
         Repository.objects.filter(
             local_site__name=self.local_site_name).count())
Example #16
0
    def test_get_repositories_with_name_search(self):
        """Testing the GET <URL>?q= API"""
        self.create_repository(name='test1', tool_name='Test')
        self.create_repository(name='tset2', tool_name='Test')

        rsp = self.api_get(get_repository_list_url() + '?q=te',
                           expected_mimetype=repository_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(len(rsp['repositories']), 1)
        self.assertEqual(rsp['repositories'][0]['name'], 'test1')
Example #17
0
 def test_get_repositories_with_show_visible(self):
     """Testing the GET repositories/ API with show_invisible=True"""
     rsp = self.apiGet(get_repository_list_url(),
                       query={'show-invisible': True},
                       expected_mimetype=repository_list_mimetype)
     self.assertEqual(rsp['stat'], 'ok')
     self.assertEqual(
         len(rsp['repositories']),
         Repository.objects.accessible(self.user,
                                       visible_only=False).count())
Example #18
0
    def test_get_repositories_with_name_many(self):
        """Testing the GET repositories/?name= API and comma-separated list"""
        self.create_repository(name="test1", tool_name="Test")
        self.create_repository(name="test2", tool_name="Test")
        self.create_repository(name="test3", tool_name="Test")

        rsp = self.api_get(get_repository_list_url() + "?name=test1,test2", expected_mimetype=repository_list_mimetype)
        self.assertEqual(rsp["stat"], "ok")
        self.assertEqual(len(rsp["repositories"]), 2)
        self.assertEqual(rsp["repositories"][0]["name"], "test1")
        self.assertEqual(rsp["repositories"][1]["name"], "test2")
    def setup_basic_post_test(self, user, with_local_site, local_site_name,
                              post_valid_data):

        return (get_repository_list_url(local_site_name),
                repository_item_mimetype,
                {
                    'name': 'Test Repository',
                    'path': self.sample_repo_path,
                    'tool': 'Test',
                },
                [])
Example #20
0
    def test_get_repositories_with_path_many(self):
        """Testing the GET repositories/?path= API and comma-separated lists"""
        self.create_repository(name='test1', path='dummy1', tool_name='Test')
        self.create_repository(name='test2', path='dummy2', tool_name='Test')
        self.create_repository(name='test3', path='dummy3', tool_name='Test')

        rsp = self.apiGet(get_repository_list_url() + '?path=dummy1,dummy2',
                          expected_mimetype=repository_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(len(rsp['repositories']), 2)
        self.assertEqual(rsp['repositories'][0]['name'], 'test1')
        self.assertEqual(rsp['repositories'][1]['name'], 'test2')
Example #21
0
    def setup_basic_get_test(self, user, with_local_site, local_site_name,
                             populate_items):
        if populate_items:
            items = [
                self.create_repository(tool_name='Test',
                                       with_local_site=with_local_site)
            ]
        else:
            items = []

        return (get_repository_list_url(local_site_name),
                repository_list_mimetype, items)
Example #22
0
    def test_get_with_show_visible(self):
        """Testing the GET repositories/ API with show_invisible=True"""
        self.create_repository(name='test1', tool_name='Test', visible=False)
        self.create_repository(name='test2', tool_name='Test', visible=True)

        rsp = self.apiGet(get_repository_list_url(),
                          query={'show-invisible': True},
                          expected_mimetype=repository_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(len(rsp['repositories']), 2)
        self.assertEqual(rsp['repositories'][0]['name'], 'test1')
        self.assertEqual(rsp['repositories'][1]['name'], 'test2')
Example #23
0
    def test_get_with_show_visible(self):
        """Testing the GET repositories/ API with show_invisible=True"""
        self.create_repository(name="test1", tool_name="Test", visible=False)
        self.create_repository(name="test2", tool_name="Test", visible=True)

        rsp = self.api_get(
            get_repository_list_url(), query={"show-invisible": True}, expected_mimetype=repository_list_mimetype
        )
        self.assertEqual(rsp["stat"], "ok")
        self.assertEqual(len(rsp["repositories"]), 2)
        self.assertEqual(rsp["repositories"][0]["name"], "test1")
        self.assertEqual(rsp["repositories"][1]["name"], "test2")
Example #24
0
    def test_get_repositories_with_tool_many(self):
        """Testing the GET repositories/?tool= API and comma-separated list"""
        self.create_repository(name="test1", path="dummy1", tool_name="Git")
        self.create_repository(name="test2", path="dummy2", tool_name="Test")
        self.create_repository(name="test3", path="dummy3", tool_name="Subversion")

        rsp = self.api_get(
            get_repository_list_url() + "?tool=Git,Subversion", expected_mimetype=repository_list_mimetype
        )
        self.assertEqual(rsp["stat"], "ok")
        self.assertEqual(len(rsp["repositories"]), 2)
        self.assertEqual(rsp["repositories"][0]["name"], "test1")
        self.assertEqual(rsp["repositories"][1]["name"], "test3")
Example #25
0
    def test_get_repositories_with_hosting_service(self):
        """Testing the GET repositories/?hosting-service= API"""
        hosting_account = HostingServiceAccount.objects.create(
            service_name='github', username='******')

        Repository.objects.create(name='My New Repository',
                                  path='https://example.com',
                                  tool=Tool.objects.get(name='Git'),
                                  hosting_account=hosting_account)

        rsp = self.api_get(get_repository_list_url() +
                           '?hosting-service=github',
                           expected_mimetype=repository_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(len(rsp['repositories']), 1)
        self.assertEqual(rsp['repositories'][0]['name'], 'My New Repository')
Example #26
0
    def test_get_repositories_with_hosting_service(self):
        """Testing the GET repositories/?hosting-service= API"""
        hosting_account = HostingServiceAccount.objects.create(service_name="github", username="******")

        Repository.objects.create(
            name="My New Repository",
            path="https://example.com",
            tool=Tool.objects.get(name="Git"),
            hosting_account=hosting_account,
        )

        rsp = self.api_get(
            get_repository_list_url() + "?hosting-service=github", expected_mimetype=repository_list_mimetype
        )
        self.assertEqual(rsp["stat"], "ok")
        self.assertEqual(len(rsp["repositories"]), 1)
        self.assertEqual(rsp["repositories"][0]["name"], "My New Repository")
    def test_get_repositories_with_hosting_service(self):
        """Testing the GET repositories/?hosting-service= API"""
        hosting_account = HostingServiceAccount.objects.create(
            service_name='github',
            username='******')

        Repository.objects.create(
            name='My New Repository',
            path='https://example.com',
            tool=Tool.objects.get(name='Git'),
            hosting_account=hosting_account)

        rsp = self.apiGet(
            get_repository_list_url() + '?hosting-service=github',
            expected_mimetype=repository_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(len(rsp['repositories']), 1)
        self.assertEqual(rsp['repositories'][0]['name'],
                         'My New Repository')
Example #28
0
    def _post_repository(self, use_local_site, data={}, expected_status=201):
        repo_name = 'Test Repository'
        repo_path = 'file://' + os.path.abspath(
            os.path.join(os.path.dirname(scmtools.__file__), 'testdata',
                         'svn_repo'))

        if 200 <= expected_status < 300:
            expected_mimetype = repository_item_mimetype
        else:
            expected_mimetype = None

        if use_local_site:
            local_site_name = self.local_site_name
        else:
            local_site_name = None

        rsp = self.apiPost(
            get_repository_list_url(local_site_name),
            dict({
                'name': repo_name,
                'path': repo_path,
                'tool': 'Subversion',
            }, **data),
            expected_status=expected_status,
            expected_mimetype=expected_mimetype)

        if 200 <= expected_status < 300:
            self._verify_repository_info(rsp, repo_name, repo_path, data)

            self.assertEqual(
                rsp['repository']['links']['self']['href'],
                self.base_url +
                get_repository_item_url(rsp['repository']['id'],
                                        local_site_name))

        return rsp
Example #29
0
 def test_get_repositories_with_site_no_access(self):
     """Testing the GET repositories/ API with a local site and Permission Denied error"""
     self.apiGet(get_repository_list_url(self.local_site_name),
                 expected_status=403)
Example #30
0
 def test_get_repositories_with_site_no_access(self):
     """Testing the GET repositories/ API with a local site and Permission Denied error"""
     self.apiGet(get_repository_list_url(self.local_site_name),
                 expected_status=403)
Example #31
0
    def _post_repository(self, data={}, use_local_site=None, use_admin=True,
                         expected_status=201, expected_tool_id='test',
                         expected_attrs={}):
        """Create a repository via the API.

        This will build and send an API request to create a repository,
        returning the resulting payload.

        By default, the form data will set the ``name``, ``path``, and
        ``tool`` to default values. These can be overridden by the caller to
        other values.

        Args:
            data (dict, optional):
                Form data to send in the request.

            use_local_site (bool, optional):
                Whether to test this against a repository owned by a
                Local Site.

            use_admin (bool, optional):
                Whether to use an administrator account to perform the
                request.

            expected_status (int, optional):
                The expected HTTP status code for the operation.

        Returns:
            dict:
            The response payload.
        """
        repo_name = 'Test Repository'

        if 200 <= expected_status < 300:
            expected_mimetype = repository_item_mimetype
        else:
            expected_mimetype = None

        if use_local_site:
            local_site_name = self.local_site_name
        else:
            local_site_name = None

        # Build the payload that we'll sent to the API.
        post_data = {
            'name': repo_name,
            'tool': 'Test',
        }

        if 'hosting_type' not in data:
            post_data['path'] = self.sample_repo_path

        post_data.update(data)

        # Make the request to the API.
        if use_admin:
            self._login_user(local_site=use_local_site,
                             admin=True)

        return self.api_post(
            get_repository_list_url(local_site_name),
            post_data,
            expected_status=expected_status,
            expected_mimetype=expected_mimetype)