def test_get_branches_hg(self): """Testing ReviewBoardGateway.get_branches for an Hg repository""" payload = self.dump_json([ { 'name': 'default', 'id': '9b1153b8a8eb2f7b1661ed7695c432f5a2b25729', }, { 'name': 'some-bookmark', 'id': '0731875ed7a14bdd53503b27b30a08a0452068cf', }, ]) with self.setup_http_test(payload=payload, expected_http_calls=1) as ctx: repository = ctx.create_repository(tool_name='Mercurial') branches = ctx.service.get_branches(repository) ctx.assertHTTPCall(0, url='https://example.com/repos/myrepo/branches', username=None, password=None, headers={ 'PRIVATE-TOKEN': 'abc123', }) self.assertEqual(branches, [ Branch(id='default', commit='9b1153b8a8eb2f7b1661ed7695c432f5a2b25729', default=True), Branch(id='some-bookmark', commit='0731875ed7a14bdd53503b27b30a08a0452068cf'), ])
def test_get_branches(self): """Testing GitHub get_branches implementation""" branches_api_response = json.dumps([ { 'ref': 'refs/heads/master', 'object': { 'sha': '859d4e148ce3ce60bbda6622cdbe5c2c2f8d9817', } }, { 'ref': 'refs/heads/release-1.7.x', 'object': { 'sha': '92463764015ef463b4b6d1a1825fee7aeec8cb15', } }, { 'ref': 'refs/heads/some-component/fix', 'object': { 'sha': '764015ef492c8cb1546363b45fee7ab6d1a182ee', } }, { 'ref': 'refs/tags/release-1.7.11', 'object': { 'sha': 'f5a35f1d8a8dcefb336a8e3211334f1f50ea7792', } }, ]) def _http_get(self, *args, **kwargs): return branches_api_response, None account = self._get_hosting_account() account.data['authorization'] = {'token': 'abc123'} repository = Repository(hosting_account=account) repository.extra_data = { 'repository_plan': 'public', 'github_public_repo_name': 'myrepo', } service = account.service self.spy_on(service.client.http_get, call_fake=_http_get) branches = service.get_branches(repository) self.assertTrue(service.client.http_get.called) self.assertEqual(len(branches), 3) self.assertEqual(branches, [ Branch(id='master', commit='859d4e148ce3ce60bbda6622cdbe5c2c2f8d9817', default=True), Branch(id='release-1.7.x', commit='92463764015ef463b4b6d1a1825fee7aeec8cb15', default=False), Branch(id='some-component/fix', commit='764015ef492c8cb1546363b45fee7ab6d1a182ee', default=False), ])
def test_get_branches_git(self): """Testing ReviewBoardGateway.get_branches for a Git repository""" payload = self.dump_json([{ 'name': 'master', 'id': 'c272edcac05b00e15440d6274723b639e3acbd7c', }, { 'name': 'im_a_branch', 'id': '83904e6acb60e7ec0dcaae6c09a579ab44d0cf38', }]) with self.setup_http_test(payload=payload, expected_http_calls=1) as ctx: repository = ctx.create_repository() branches = ctx.service.get_branches(repository) ctx.assertHTTPCall(0, url='https://example.com/repos/myrepo/branches', username=None, password=None, headers={ 'PRIVATE-TOKEN': 'abc123', }) self.assertEqual(branches, [ Branch(id='master', commit='c272edcac05b00e15440d6274723b639e3acbd7c', default=True), Branch(id='im_a_branch', commit='83904e6acb60e7ec0dcaae6c09a579ab44d0cf38'), ])
def get_branches(self): """Returns a list of branches. This assumes the standard layout in the repository.""" results = [] trunk, unused = self.client.list(self.__normalize_path('trunk'), dirent_fields=SVN_DIRENT_CREATED_REV, recurse=False)[0] results.append(Branch('trunk', str(trunk['created_rev'].number), True)) try: branches = self.client.list( self.__normalize_path('branches'), dirent_fields=SVN_DIRENT_CREATED_REV)[1:] for branch, unused in branches: results.append( Branch(branch['path'].split('/')[-1], str(branch['created_rev'].number))) except ClientError: # It's possible there aren't any branches. Ignore errors for this # part. pass return results
def test_get_branches(self): """Testing GitLab get_branches implementation""" branches_api_response = json.dumps([ { 'name': 'master', 'commit': { 'id': 'ed899a2f4b50b4370feeea94676502b42383c746' } }, { 'name': 'branch1', 'commit': { 'id': '6104942438c14ec7bd21c6cd5bd995272b3faff6' } }, { 'name': 'branch2', 'commit': { 'id': '21b3bcabcff2ab3dc3c9caa172f783aad602c0b0' } }, { 'branch-name': 'branch3', 'commit': { 'id': 'd5a3ff139356ce33e37e73add446f16869741b50' } } ]) def _http_get(self, *args, **kwargs): return branches_api_response, None account = self._get_hosting_account(use_url=True) account.data['private_token'] = encrypt_password('abc123') service = account.service repository = Repository(hosting_account=account) repository.extra_data = {'gitlab_project_id': 123456} self.spy_on(service.client.http_get, call_fake=_http_get) branches = service.get_branches(repository) self.assertTrue(service.client.http_get.called) self.assertEqual(len(branches), 3) self.assertEqual( branches, [ Branch(id='master', commit='ed899a2f4b50b4370feeea94676502b42383c746', default=True), Branch(id='branch1', commit='6104942438c14ec7bd21c6cd5bd995272b3faff6', default=False), Branch(id='branch2', commit='21b3bcabcff2ab3dc3c9caa172f783aad602c0b0', default=False) ])
def _test_get_branches(self, api_version): """Common test for fetching branches. Args: api_version (unicode): The API version to test against. """ payload = self.dump_json([{ 'name': 'master', 'commit': { 'id': 'ed899a2f4b50b4370feeea94676502b42383c746' } }, { 'name': 'branch1', 'commit': { 'id': '6104942438c14ec7bd21c6cd5bd995272b3faff6' } }, { 'name': 'branch2', 'commit': { 'id': '21b3bcabcff2ab3dc3c9caa172f783aad602c0b0' } }, { 'branch-name': 'branch3', 'commit': { 'id': 'd5a3ff139356ce33e37e73add446f16869741b50' } }]) with self.setup_http_test(payload=payload, expected_http_calls=1) as ctx: self._set_api_version(ctx.service, api_version) repository = ctx.create_repository() branches = ctx.service.get_branches(repository) ctx.assertHTTPCall( 0, url=('https://example.com/api/v%s/projects/123456/repository/' 'branches' % api_version), username=None, password=None, headers={ 'Accept': 'application/json', 'PRIVATE-TOKEN': 'abc123', }) self.assertEqual(branches, [ Branch(id='master', commit='ed899a2f4b50b4370feeea94676502b42383c746', default=True), Branch(id='branch1', commit='6104942438c14ec7bd21c6cd5bd995272b3faff6', default=False), Branch(id='branch2', commit='21b3bcabcff2ab3dc3c9caa172f783aad602c0b0', default=False) ])
def test_get_branches(self): """Testing SVN (<backend>) get_branches""" branches = self.tool.get_branches() self.assertEqual(len(branches), 3) self.assertEqual(branches[0], Branch(id='trunk', name='trunk', commit='9', default=True)) self.assertEqual(branches[1], Branch(id='branches/branch1', name='branch1', commit='7', default=False)) self.assertEqual(branches[2], Branch(id='top-level-branch', name='top-level-branch', commit='10', default=False))
def test_get_branches(self): """Testing GitHub get_branches implementation""" branches_api_response = simplejson.dumps([ { 'ref': 'refs/heads/master', 'object': { 'sha': '859d4e148ce3ce60bbda6622cdbe5c2c2f8d9817', } }, { 'ref': 'refs/heads/release-1.7.x', 'object': { 'sha': '92463764015ef463b4b6d1a1825fee7aeec8cb15', } }, { 'ref': 'refs/tags/release-1.7.11', 'object': { 'sha': 'f5a35f1d8a8dcefb336a8e3211334f1f50ea7792', } }, ]) def _http_get(self, *args, **kwargs): return branches_api_response, None self.service_class._http_get = _http_get account = self._get_hosting_account() account.data['authorization'] = {'token': 'abc123'} repository = Repository(hosting_account=account) repository.extra_data = { 'repository_plan': 'public', 'github_public_repo_name': 'myrepo', } service = account.service branches = service.get_branches(repository) self.assertEqual(len(branches), 2) self.assertEqual( branches, [ Branch('master', '859d4e148ce3ce60bbda6622cdbe5c2c2f8d9817', True), Branch('release-1.7.x', '92463764015ef463b4b6d1a1825fee7aeec8cb15', False), ])
def branches(self): """Returns a list of branches. This assumes the standard layout in the repository.""" results = [] try: root_dirents = self.client.list( self.normalize_path('/'), dirent_fields=SVN_DIRENT_CREATED_REV, recurse=False)[1:] except ClientError as e: raise SCMError(e) root_entries = SortedDict() for dirent, unused in root_dirents: name = dirent['path'].split('/')[-1] rev = six.text_type(dirent['created_rev'].number) root_entries[name] = rev if 'trunk' in root_entries: # Looks like the standard layout. Adds trunks and any branches results.append( Branch('trunk', root_entries['trunk'], True)) try: branches = self.client.list( self.normalize_path('branches'), dirent_fields=SVN_DIRENT_CREATED_REV)[1:] for branch, unused in branches: results.append(Branch( branch['path'].split('/')[-1], six.text_type(branch['created_rev'].number))) except ClientError: # It's possible there aren't any branches. Ignore errors for # this part. pass else: # If the repository doesn't use the standard layout, just use a # listing of the root directory as the "branches". This probably # corresponds to a list of projects instead of branches, but it # will at least give people a useful result. default = True for name, rev in six.iteritems(root_entries): results.append(Branch(name, rev, default)) default = False return results
def get_branches(self, repository): """Return the branches from Gerrit. Args: repository (reviewboard.scmtools.models.Repository): The repository to fetch branches for. Returns: list of reviewboard.scmtools.core.Branch: The list of branches. """ url = self._build_project_api_url(repository, ('branches',)) rsp = self.client.api_get(url) branches = [] for branch in rsp: ref = branch['ref'] if ref == 'refs/meta/config': continue elif ref.startswith('refs/heads/'): branch_id = ref[len('refs/heads/'):] commit = branch['revision'] else: continue branches.append(Branch( id=branch_id, commit=commit, default=(branch_id == 'master'), )) return branches
def get_branches(self, repository): """Return a list of branches. This will perform an API request to fetch a list of branches. Args: repository (reviewboard.scmtools.models.Repository): The repository to get branches from. Returns: list of reviewboard.scmtools.core.Branch: The branches available. Raises: reviewboard.scmtools.errors.AuthorizationError: There was an issue with the authorization credentials. urllib2.HTTPError: There was an error communicating with the server. """ repo_api_url = ('%s/repository/branches' % self._get_repo_api_url(repository)) refs = self._api_get_list(repository.hosting_account.hosting_url, repo_api_url) results = [] for ref in refs: if 'name' in ref: name = ref['name'] results.append(Branch(id=name, commit=ref['commit']['id'], default=(name == 'master'))) return results
def get_branches(self, repository): repo_api_url = self._get_repo_api_url(repository) refs = self.client.api_get_heads(repo_api_url) results = [] # A lot of repositories are starting to use alternative names for # their mainline branch, and GitHub doesn't have a good way for us to # know which one is which. Until this is better defined, we'll still # prefer "master" when available, then look for "main", and finally # make sure that at least one branch is marked as default. master_ref = None main_ref = None for i, ref in enumerate(refs): name = ref['ref'][len('refs/heads/'):] results.append(Branch(id=name, commit=ref['object']['sha'])) if name == 'master': master_ref = i elif name == 'main': main_ref = i if master_ref is not None: results[master_ref].default = True elif main_ref is not None: results[main_ref].default = True elif len(results) > 0: results[0].default = True return results
def get_branches(self): """Return open/inactive branches from hgweb in JSON. Returns: list of reviewboard.scmtools.core.Branch: A list of the branches. """ results = [] try: url = '%s/json-branches' % self.path_stripped contents = self.get_file_http(url, '', '', 'application/json') except Exception as e: logging.exception('Cannot load branches from hgweb: %s', e) return results if contents: results = [ Branch(id=data['branch'], commit=data['node'], default=(data['branch'] == 'default')) for data in json.loads(contents)['branches'] if data['status'] != 'closed' ] return results
def get_branches(self, repository): """Return the branches for the repository. Args: repository (reviewboard.scmtools.models.Repository): The repository to fetch branches for. Returns: list of reviewboard.scmtools.core.Branch: The branches returned for the repository. Raises: reviewboard.hostingsvcs.errors.HostingServiceError: Error retrieving the branch information. There may be a more specific subclass raised. """ repo_name = self._get_repo_name(repository) tool_name = repository.scmtool_class.name if tool_name == 'Git': default_branch = 'master' elif tool_name == 'Mercurial': default_branch = 'default' else: default_branch = None return [ Branch(id=branch_info['name'], commit=branch_info['id'], default=(branch_info['name'] == default_branch)) for branch_info in self.client.api_get_branches(repo_name) ]
def branches(self): """Returns a list of branches. This assumes the standard layout in the repository.""" results = [] try: root_dirents = \ self.ra.get_dir(B('.'), -1, ra.DIRENT_CREATED_REV)[0] except SubversionException as e: raise SCMError(e) trunk = B('trunk') if trunk in root_dirents: # Looks like the standard layout. Adds trunk and any branches. created_rev = root_dirents[trunk]['created_rev'] results.append(Branch('trunk', six.text_type(created_rev), True)) try: dirents = self.ra.get_dir(B('branches'), -1, ra.DIRENT_CREATED_REV)[0] branches = {} for name, dirent in six.iteritems(dirents): branches[six.text_type(name)] = six.text_type( dirent['created_rev']) for name in sorted(six.iterkeys(branches)): results.append(Branch(name, branches[name])) except SubversionException as e: pass else: # If the repository doesn't use the standard layout, just use a # listing of the root directory as the "branches". This probably # corresponds to a list of projects instead of branches, but it # will at least give people a useful result. branches = {} for name, dirent in six.iteritems(root_dirents): branches[six.text_type(name)] = six.text_type( dirent['created_rev']) default = True for name in sorted(six.iterkeys(branches)): results.append(Branch(name, branches[name], default)) default = False return results
def test_get_branches(self): """Testing Gerrit.get_branches""" payload = self._make_json_rsp([ { 'ref': 'HEAD', 'revision': 'master' }, { 'ref': 'refs/meta/config', 'revision': '7a59a483aeefc8c7d4082f1081c42db817176071' }, { 'ref': 'refs/heads/master', 'revision': '6854734ef5fc8b2b9d291bf42aa59c344abf5a73' }, { 'ref': 'refs/heads/release-2.0.x', 'revision': '7f68a001f8e5b77e7355c11385bfbcd2a6d3c077' }, { 'ref': 'refs/heads/release-2.5.x', 'revision': 'fc8a7ecf288d835ecd9ded086ffaee9412d1da9c' }, ]) with self.setup_http_test(payload=payload, expected_http_calls=1) as ctx: branches = ctx.service.get_branches(ctx.create_repository()) ctx.assertHTTPCall( 0, url='http://gerrit.example.com/a/projects/Project/branches/') self.assertEqual( branches, [ Branch(commit='6854734ef5fc8b2b9d291bf42aa59c344abf5a73', id='master', default=True), Branch(commit='7f68a001f8e5b77e7355c11385bfbcd2a6d3c077', id='release-2.0.x'), Branch(commit='fc8a7ecf288d835ecd9ded086ffaee9412d1da9c', id='release-2.5.x'), ] )
def get_branches(self, repository): """Return all upstream branches in the repository. This will paginate through all the results, 100 entries at a time, returning all branches listed in the repository. Args: repository (reviewboard.scmtools.models.Repository): The repository to retrieve branches from. Returns: list of reviewboard.scmtools.core.Branch: The list of branches found in the repository. """ default_branch_name = self._get_default_branch_name(repository) found_default_branch = False branches = [] branches_url = self._build_repository_api_url( repository, 'refs/branches', query={ 'pagelen': '100', 'fields': 'values.name,values.target.hash,next', }) while branches_url: branches_rsp = self.api_get(branches_url) for branch_info in branches_rsp['values']: try: branch_name = branch_info['name'] is_default = (branch_name == default_branch_name) if is_default: found_default_branch = True branches.append( Branch(id=branch_name, commit=branch_info['target']['hash'], default=is_default)) except KeyError as e: logging.error( 'Missing "%s" key in Bitbucket branch ' 'definition %r for repository %s. Skipping ' 'branch.', e, branch_info, repository.pk) # If there's a "next", it will automatically include any ?fields= # entries we specified above. branches_url = branches_rsp.get('next') if not found_default_branch: branches[0].default = True return branches
def test_get_branches(self): """Testing ReviewBoardGateway get_branches implementation""" branches_api_response = json.dumps([{ 'name': 'master', 'id': 'c272edcac05b00e15440d6274723b639e3acbd7c', }, { 'name': 'im_a_branch', 'id': '83904e6acb60e7ec0dcaae6c09a579ab44d0cf38', }]) def _http_get(self, *args, **kwargs): return branches_api_response, None account = self._get_hosting_account() account.data['private_token'] = encrypt_password('abc123') repository = Repository(hosting_account=account) repository.extra_data = { 'rbgateway_repo_name': 'myrepo', } service = account.service self.spy_on(service.client.http_get, call_fake=_http_get) branches = service.get_branches(repository) self.assertTrue(service.client.http_get.called) self.assertEqual(len(branches), 2) self.assertEqual(branches, [ Branch(id='master', commit='c272edcac05b00e15440d6274723b639e3acbd7c', default=True), Branch(id='im_a_branch', commit='83904e6acb60e7ec0dcaae6c09a579ab44d0cf38', default=False) ])
def get_branches(self, repository): repo_api_url = self._get_repo_api_url(repository) refs = self.client.api_get_heads(repo_api_url) results = [] for ref in refs: name = ref['ref'][len('refs/heads/'):] results.append( Branch(name, ref['object']['sha'], default=(name == 'master'))) return results
def get_branches(self, repository): url = self._build_api_url(repository, 'git/refs/heads') rsp = self._api_get(url) results = [] for ref in rsp: refname = ref['ref'] if not refname.startswith('refs/heads/'): continue name = refname.split('/')[-1] results.append( Branch(name, ref['object']['sha'], default=(name == 'master'))) return results
def get_branches(self, repository): default_branch_name = self._get_default_branch_name(repository) url = self._build_repository_api_url(repository, 'branches/') rsp = self._api_get(url) branches = [] for branch_name, branch in six.iteritems(rsp): branches.append( Branch(id=branch_name, commit=branch['raw_node'], default=(branch_name == default_branch_name))) return branches
def get_branches(self, repository): """Return the branches for the repository. Args: repository (reviewboard.scmtools.models.Repository): The repository to fetch branches for. Returns: list of reviewboard.scmtools.core.Branch: The branches returned from the Review Board Gateway API. Raises: SCMError: The branches could not be retrieved from Review Board Gateway. """ url = ('%s/repos/%s/branches' % (self.account.hosting_url, repository.extra_data['rbgateway_repo_name'])) tool_name = repository.scmtool_class.name if tool_name == 'Git': default_branch = 'master' elif tool_name == 'Mercurial': default_branch = 'default' else: raise SCMError('Review Board Gateway does not support %s', tool_name) try: data, headers = self._api_get(url) branches = json.loads(data) results = [] for branch in branches: results.append(Branch( id=branch['name'], commit=branch['id'], default=(branch['name'] == default_branch) )) return results except Exception as e: logger.exception('Failed to get branches from %s: %s', url, e) raise SCMError(six.text_type(e))
def get_branches(self): """Return open/inactive branches from repository in JSON. Returns: list of reviewboard.scmtools.core.Branch: The list of the branches. """ p = self._run_hg(['branches', '--template', 'json']) if p.wait() != 0: raise SCMError('Cannot load branches: %s' % p.stderr.read()) results = [ Branch(id=data['branch'], commit=data['node'], default=(data['branch'] == 'default')) for data in json.load(p.stdout) if not data['closed'] ] return results
def get_branches(self, repository): """Get a list of branches. This will perform an API request to fetch a list of branches. """ repo_api_url = ('%s/repository/branches?private_token=%s' % (self._get_repo_api_url(repository), self._get_private_token())) refs = self._api_get(repo_api_url)[0] results = [] for ref in refs: if 'name' in ref: name = ref['name'] results.append(Branch(id=name, commit=ref['commit']['id'], default=(name == 'master'))) return results
def get_branches(self, repository): results = [] url = self._build_api_url(self._get_repo_api_url(repository), 'git/refs/heads') try: rsp = self._api_get(url) except Exception as e: logging.warning('Failed to fetch commits from %s: %s', url, e) return results for ref in rsp: refname = ref['ref'] if not refname.startswith('refs/heads/'): continue name = refname.split('/')[-1] results.append( Branch(name, ref['object']['sha'], default=(name == 'master'))) return results
def get_branches(self, repository): url = ('%s/repos/%s/branches' % (self.account.hosting_url, repository.extra_data['rbgateway_repo_name'])) try: data, headers = self._api_get(url) branches = json.loads(data) results = [] for branch in branches: results.append( Branch(id=branch['name'], commit=branch['id'], default=(branch['name'] == 'master'))) return results except Exception as e: logging.warning('Failed to get branches from %s: %s', url, e, exc_info=1) raise SCMError(six.text_type(e))
def get_branches(self): """Return open/inactive branches from hgweb in JSON. Returns: list of reviewboard.scmtools.core.Branch: A list of the branches. """ results = [] try: rsp = self._get_http_json('%s/json-branches' % self.path_stripped) except Exception as e: logging.exception('Cannot load branches from hgweb: %s', e) return results if rsp: results = [ Branch(id=data['branch'], commit=data['node'], default=(data['branch'] == 'default')) for data in rsp['branches'] if data['status'] != 'closed' ] return results
def get_branches(self): return [ Branch(id='trunk', commit='5', default=True), Branch(id='branch1', commit='7', default=False), ]
def test_get_branches_v3(self): """Testing GitLab.get_branches (API v3)""" paths = { '/api/v3/projects/123456/repository/branches': { 'payload': self.dump_json([ { 'name': 'master', 'commit': { 'id': 'ed899a2f4b50b4370feeea94676502b42383c746', }, }, { 'name': 'branch1', 'commit': { 'id': '6104942438c14ec7bd21c6cd5bd995272b3faff6', }, }, { 'name': 'branch2', 'commit': { 'id': '21b3bcabcff2ab3dc3c9caa172f783aad602c0b0', }, }, { 'branch-name': 'branch3', 'commit': { 'id': 'd5a3ff139356ce33e37e73add446f16869741b50', }, }, ]), }, } with self.setup_http_test(self.make_handler_for_paths(paths), expected_http_calls=1) as ctx: self._set_api_version(ctx.service, '3') repository = ctx.create_repository() branches = ctx.service.get_branches(repository) ctx.assertHTTPCall( 0, url=('https://example.com/api/v3/projects/123456/repository/' 'branches'), username=None, password=None, headers={ 'Accept': 'application/json', 'PRIVATE-TOKEN': 'abc123', }) self.assertEqual(branches, [ Branch(id='master', commit='ed899a2f4b50b4370feeea94676502b42383c746', default=True), Branch(id='branch1', commit='6104942438c14ec7bd21c6cd5bd995272b3faff6', default=False), Branch(id='branch2', commit='21b3bcabcff2ab3dc3c9caa172f783aad602c0b0', default=False), ])
def test_get_branches(self): """Testing Bitbucket.get_branches""" branches_api_response_1 = self.dump_json({ 'next': ('https://bitbucket.org/api/2.0/repositories/myuser/' 'myrepo/refs/branches?pagelen=100&page=2&' 'fields=values.name%2Cvalues.target.hash%2Cnext'), 'values': [ { 'name': 'branch1', 'target': { 'hash': '1c44b461cebe5874a857c51a4a13a849a4d1e52d', }, }, { 'name': 'branch2', 'target': { 'hash': '44568f7d33647d286691517e6325fea5c7a21d5e', }, }, ], }) branches_api_response_2 = self.dump_json({ 'values': [ { 'name': 'branch3', 'target': { 'hash': 'e5874a857c51a4a13a849a4d1e52d1c44b461ceb', }, }, { 'name': 'branch4', 'target': { 'hash': 'd286691517e6325fea5c7a21d5e44568f7d33647', }, }, ], }) get_repository_api_response = self.dump_json({ 'mainbranch': { 'name': 'branch3', }, }) paths = { '/api/2.0/repositories/myuser/myrepo/': { 'payload': get_repository_api_response, }, ('/api/2.0/repositories/myuser/myrepo/refs/branches' '?pagelen=100&fields=values.name%2Cvalues.target.hash%2Cnext'): { 'payload': branches_api_response_1, }, ('/api/2.0/repositories/myuser/myrepo/refs/branches' '?pagelen=100&page=2&fields=values.name%2Cvalues.target.hash' '%2Cnext'): { 'payload': branches_api_response_2, }, } with self.setup_http_test(self.make_handler_for_paths(paths), expected_http_calls=3) as ctx: repository = self.create_repository(tool_name='Git') branches = ctx.service.get_branches(repository) ctx.assertHTTPCall( 0, url=('https://bitbucket.org/api/2.0/repositories/myuser/myrepo/' '?fields=mainbranch.name')) ctx.assertHTTPCall( 1, url=('https://bitbucket.org/api/2.0/repositories/myuser/myrepo/' 'refs/branches?pagelen=100&fields=values.name' '%2Cvalues.target.hash%2Cnext')) ctx.assertHTTPCall( 2, url=('https://bitbucket.org/api/2.0/repositories/myuser/myrepo/' 'refs/branches?pagelen=100&page=2&fields=values.name' '%2Cvalues.target.hash%2Cnext')) self.assertEqual(branches, [ Branch(id='branch1', commit='1c44b461cebe5874a857c51a4a13a849a4d1e52d'), Branch(id='branch2', commit='44568f7d33647d286691517e6325fea5c7a21d5e'), Branch(id='branch3', commit='e5874a857c51a4a13a849a4d1e52d1c44b461ceb', default=True), Branch(id='branch4', commit='d286691517e6325fea5c7a21d5e44568f7d33647'), ])