def _put_repository(self, use_local_site, data={}, expected_status=200): repo_name = 'New Test Repository' repo_path = 'file://' + os.path.abspath( os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'git_repo')) repo = self.create_repository(with_local_site=use_local_site) if use_local_site: local_site_name = self.local_site_name else: local_site_name = None if 200 <= expected_status < 300: expected_mimetype = repository_item_mimetype else: expected_mimetype = None rsp = self.apiPut( get_repository_item_url(repo, local_site_name), dict({ 'name': repo_name, 'path': repo_path, }, **data), expected_status=expected_status, expected_mimetype=expected_mimetype) if 200 <= expected_status < 300: self._verify_repository_info(rsp, repo_name, repo_path, data) return repo.pk
def _put_repository(self, data={}, use_local_site=False, use_admin=True, repository=None, expected_status=200): """Modify a repository via the API. This will build and send an API request to modify a repository, returning the resulting payload. By default, the form data will set the ``name`` to a default value. This can be overridden by the caller to another value. 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. repository (reviewboard.scmtools.models.Repository, optional): An existing repository to post to. If not provided, one will be created. expected_status (int, optional): The expected HTTP status code for the operation. Returns: dict: The response payload. """ repo_name = 'New Test Repository' if repository is None: repository = self.create_repository(with_local_site=use_local_site) if use_local_site: local_site_name = self.local_site_name else: local_site_name = None if 200 <= expected_status < 300: expected_mimetype = repository_item_mimetype else: expected_mimetype = None # Make the request to the API. if use_admin: self._login_user(local_site=use_local_site, admin=True) return self.api_put( get_repository_item_url(repository, local_site_name), dict({ 'name': repo_name, }, **data), expected_status=expected_status, expected_mimetype=expected_mimetype)
def _put_repository(self, use_local_site, data={}, expected_status=200): repo_name = 'New Test Repository' repo = self.create_repository(with_local_site=use_local_site) if use_local_site: local_site_name = self.local_site_name else: local_site_name = None if 200 <= expected_status < 300: expected_mimetype = repository_item_mimetype else: expected_mimetype = None rsp = self.apiPut( get_repository_item_url(repo, local_site_name), dict({ 'name': repo_name, 'path': self.sample_repo_path, }, **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) return repo.pk
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
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
def _put_repository(self, use_local_site, data={}, expected_status=200): repo_name = 'New Test Repository' repo_path = 'file://' + os.path.abspath( os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'git_repo')) repo = self.create_repository(with_local_site=use_local_site) if use_local_site: local_site_name = self.local_site_name else: local_site_name = None if 200 <= expected_status < 300: expected_mimetype = repository_item_mimetype else: expected_mimetype = None rsp = self.apiPut(get_repository_item_url(repo, local_site_name), dict({ 'name': repo_name, 'path': repo_path, }, **data), expected_status=expected_status, expected_mimetype=expected_mimetype) if 200 <= expected_status < 300: self._verify_repository_info(rsp, repo_name, repo_path, data) return repo.pk
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
def test_post_with_repository_name(self): """Testing the POST review-requests/ API with a repository name""" repository = self.create_repository() rsp = self.apiPost(get_review_request_list_url(), {'repository': repository.name}, expected_mimetype=review_request_item_mimetype) self.assertEqual(rsp['stat'], 'ok') self.assertEqual(rsp['review_request']['links']['repository']['href'], self.base_url + get_repository_item_url(repository)) # See if we can fetch this. Also return it for use in other # unit tests. return ReviewRequest.objects.get(pk=rsp['review_request']['id'])
def _delete_repository(self, use_local_site, expected_status=204, with_review_request=False): repo = self.create_repository(with_local_site=use_local_site) if use_local_site: local_site_name = self.local_site_name else: local_site_name = None if with_review_request: request = ReviewRequest.objects.create(self.user, repo) request.save() self.api_delete(get_repository_item_url(repo, local_site_name), expected_status=expected_status) return repo.pk
def test_post_with_repository_name(self): """Testing the POST review-requests/ API with a repository name""" repository = self.create_repository() rsp = self.apiPost( get_review_request_list_url(), {'repository': repository.name}, expected_mimetype=review_request_item_mimetype) self.assertEqual(rsp['stat'], 'ok') self.assertEqual( rsp['review_request']['links']['repository']['href'], self.base_url + get_repository_item_url(repository)) # See if we can fetch this. Also return it for use in other # unit tests. return ReviewRequest.objects.get(pk=rsp['review_request']['id'])
def _delete_repository(self, use_local_site=False, use_admin=True, expected_status=204, with_review_request=False): """Delete a repository via the API. This will build and send an API request to delete (or archive) a repository, returning the initial ID of the repository. Args: 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. with_review_request (bool, optional): Whether to create a review request against the repository before deleting. Returns: int: The initial ID of the repository. """ repo = self.create_repository(with_local_site=use_local_site) if use_local_site: local_site_name = self.local_site_name else: local_site_name = None if with_review_request: self.create_review_request(submitter=self.user, repository=repo) # Make the request to the API. if use_admin: self._login_user(local_site=use_local_site, admin=True) self.api_delete(get_repository_item_url(repo, local_site_name), expected_status=expected_status) return repo.pk
def _delete_repository(self, use_local_site, expected_status=204, with_review_request=False): repo = self.create_repository(with_local_site=use_local_site) if use_local_site: local_site_name = self.local_site_name else: local_site_name = None if with_review_request: request = ReviewRequest.objects.create(self.user, repo) request.save() self.apiDelete(get_repository_item_url(repo, local_site_name), expected_status=expected_status) return repo.pk
def setup_basic_put_test(self, user, with_local_site, local_site_name, put_valid_data): repository = self.create_repository( with_local_site=with_local_site, tool_name='Git', path=self.sample_repo_path, mirror_path='git@localhost:test.git') return (get_repository_item_url(repository, local_site_name), repository_item_mimetype, { 'bug_tracker': 'http://bugtracker/%s/', 'encoding': 'UTF-8', 'name': 'New Test Repository', 'username': '******', 'password': '******', 'public': False, 'raw_file_url': 'http://example.com/<filename>/<version>', }, repository, [])
def compare_item(self, item_rsp, repository): self.assertEqual(item_rsp['bug_tracker'], repository.bug_tracker) self.assertEqual(item_rsp['extra_data'], repository.extra_data) self.assertEqual(item_rsp['id'], repository.pk) self.assertEqual(item_rsp['mirror_path'], repository.mirror_path) self.assertEqual(item_rsp['name'], repository.name) self.assertEqual(item_rsp['path'], repository.path) self.assertEqual(item_rsp['tool'], repository.tool.name) self.assertEqual(item_rsp['visible'], repository.visible) if repository.local_site: local_site_name = repository.local_site.name else: local_site_name = None self.assertEqual( item_rsp['links']['self']['href'], '%s%s' % (self.base_url, get_repository_item_url(item_rsp['id'], local_site_name)))
def test_post_reviewrequests_with_submit_as(self): """Testing the POST review-requests/?submit_as= API""" self.user.is_superuser = True self.user.save() repository = self.create_repository() rsp = self.apiPost( get_review_request_list_url(), { 'repository': repository.path, 'submit_as': 'doc', }, expected_mimetype=review_request_item_mimetype) self.assertEqual(rsp['stat'], 'ok') self.assertEqual( rsp['review_request']['links']['repository']['href'], self.base_url + get_repository_item_url(repository)) self.assertEqual( rsp['review_request']['links']['submitter']['href'], self.base_url + get_user_item_url('doc')) ReviewRequest.objects.get(pk=rsp['review_request']['id'])
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
def setup_basic_get_test(self, user, with_local_site, local_site_name): repository = self.create_repository(with_local_site=with_local_site) return (get_repository_item_url(repository, local_site_name), repository_item_mimetype, repository)