Skip to content

Commit f88c565

Browse files
committed
Return generators instead of dicts in services request_create
1 parent ba43ef6 commit f88c565

File tree

7 files changed

+55
-57
lines changed

7 files changed

+55
-57
lines changed

git_repo/services/ext/bitbucket.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,14 @@ def request_create(self, onto_user, onto_repo, from_branch, onto_branch, title=N
294294
client=self.bb.client
295295
)
296296

297-
return {
298-
'local': from_branch,
299-
'remote': onto_branch,
300-
'ref': request.id,
301-
'project': '/'.join([onto_user, onto_repo]),
302-
'url': request.links['html']['href']
303-
}
297+
yield '{}'
298+
yield ['Successfully created request of `{local}` onto `{project}:{remote}, with id `{ref}'.format(
299+
local=from_branch,
300+
project='/'.join([onto_user, onto_repo]),
301+
remote=onto_branch,
302+
ref=request.id
303+
)]
304+
yield ['available at {}'.format(request.links['html']['href'])]
304305

305306
except HTTPError as err:
306307
status_code = hasattr(err, 'code') and err.code or err.response.status_code

git_repo/services/ext/github.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,14 @@ def request_create(self, onto_user, onto_repo, from_branch, onto_branch, title=N
277277
base=onto_branch,
278278
body=description)
279279

280-
return {
281-
'local': from_branch,
282-
'project': '/'.join([onto_user, onto_repo]),
283-
'remote': onto_branch,
284-
'ref': request.number,
285-
'url': request.html_url
286-
}
280+
yield '{}'
281+
yield ['Successfully created request of `{local}` onto `{project}:{remote}, with id `{ref}'.format(
282+
local=from_branch,
283+
project='/'.join([onto_user, onto_repo]),
284+
remote=onto_branch,
285+
ref=request.number
286+
)]
287+
yield ['available at {}'.format(request.html_url)]
287288

288289
except github3.models.GitHubError as err:
289290
if err.code == 422:

git_repo/services/ext/gitlab.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,14 @@ def request_create(self, onto_user, onto_repo, from_branch, onto_branch, title=N
313313
}
314314
)
315315

316-
return {
317-
'local': from_branch,
318-
'project': '/'.join([onto_user, onto_repo]),
319-
'remote': onto_branch,
320-
'url': request.web_url,
321-
'ref': request.iid
322-
}
316+
yield '{}'
317+
yield ['Successfully created request of `{local}` onto `{project}:{remote}, with id `{ref}'.format(
318+
local=from_branch,
319+
project='/'.join([onto_user, onto_repo]),
320+
remote=onto_branch,
321+
ref=request.iid
322+
)]
323+
yield ['available at {}'.format(request.web_url)]
323324

324325
except GitlabGetError as err:
325326
raise ResourceNotFoundError(err) from err

tests/helpers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,8 @@ def action_request_create(self,
716716
source_branch='pr-test',
717717
target_branch='master',
718718
create_repository='test_create_requests',
719-
auto_slug=False):
719+
auto_slug=False,
720+
expected_result=[]):
720721
'''
721722
Here we are testing the subcommand 'request create'.
722723
@@ -800,16 +801,18 @@ def edit_stub(repository, branch):
800801
self.service.connect()
801802
def test_edit(repository, from_branch):
802803
return "PR title", "PR body"
803-
request = self.service.request_create(
804+
output = list(self.service.request_create(
804805
onto_user=namespace,
805806
onto_repo=repository,
806807
from_branch=source_branch,
807808
onto_branch=target_branch,
808809
title=title,
809810
description=description,
810811
auto_slug=auto_slug,
811-
edit=test_edit)
812-
return request
812+
edit=test_edit))
813+
814+
for i, line in enumerate(expected_result):
815+
assert output[i] == line
813816

814817
def action_request_create_by_push(self, namespace, repository, branch, remote_ref):
815818
local_slug = self.service.format_path(namespace=namespace, repository=repository, rw=True)

tests/integration/test_bitbucket.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,12 @@ def test_32_request_create__good(self):
322322
target_branch='master',
323323
source_branch='pr-test',
324324
title='PR test',
325-
description='PR description')
326-
assert r == {
327-
'local': 'pr-test',
328-
'ref': 1,
329-
'remote': 'master',
330-
'project': '{}/test_create_requests'.format(self.local_namespace),
331-
'url': 'https://bitbucket.org/{}/test_create_requests/pull-requests/1'.format(self.local_namespace),
332-
}
325+
description='PR description',
326+
expected_result=[
327+
'{}',
328+
['Successfully created request of `pr-test` onto `_namespace_bitbucket_/test_create_requests:master, with id `1'],
329+
['available at https://bitbucket.org/_namespace_bitbucket_/test_create_requests/pull-requests/1']
330+
])
333331

334332
def test_32_request_create__bad_branch(self):
335333
with pytest.raises(ResourceNotFoundError):
@@ -357,14 +355,12 @@ def test_32_request_create__guess_branch(self):
357355
target_branch=None,
358356
source_branch=None,
359357
title='PR test',
360-
description='PR description')
361-
assert r == {
362-
'local': 'pr-test',
363-
'ref': 1,
364-
'remote': 'master',
365-
'project': '{}/test_create_requests'.format(self.local_namespace),
366-
'url': 'https://bitbucket.org/{}/test_create_requests/pull-requests/1'.format(self.local_namespace),
367-
}
358+
description='PR description',
359+
expected_result=[
360+
'{}',
361+
['Successfully created request of `pr-test` onto `_namespace_bitbucket_/test_create_requests:master, with id `1'],
362+
['available at https://bitbucket.org/_namespace_bitbucket_/test_create_requests/pull-requests/1']
363+
])
368364

369365
def test_33_open(self):
370366
self.action_open(namespace='guyzmo',

tests/integration/test_github.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,12 @@ def test_32_request_create(self):
342342
source_branch='pr-test',
343343
target_branch='master',
344344
title='PR test',
345-
description='PR description')
346-
assert r == {
347-
'local': 'pr-test',
348-
'ref': 1,
349-
'remote': 'master',
350-
'project': '{}/test_create_requests'.format(self.namespace),
351-
'url': 'https://github.com/{}/test_create_requests/pull/1'.format(self.namespace),
352-
}
345+
description='PR description',
346+
expected_result=[
347+
'{}',
348+
['Successfully created request of `pr-test` onto `_namespace_github_/test_create_requests:master, with id `1'],
349+
['available at https://github.com/_namespace_github_/test_create_requests/pull/1']
350+
])
353351

354352
def test_32_request_create__bad_branch(self):
355353
with pytest.raises(ResourceError):

tests/integration/test_gitlab.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,12 @@ def test_20_request_create(self):
265265
source_branch='pr-test',
266266
target_branch='master',
267267
title='PR test',
268-
description='PR description')
269-
assert r == {
270-
'local': 'pr-test',
271-
'project': '{}/test_create_requests'.format(self.local_namespace),
272-
'ref': 1,
273-
'remote': 'master',
274-
'url': 'https://gitlab.com/{}/test_create_requests/merge_requests/1'.format(self.local_namespace)
275-
}
268+
description='PR description',
269+
expected_result=[
270+
'{}',
271+
['Successfully created request of `pr-test` onto `_namespace_gitlab_/test_create_requests:master, with id `1'],
272+
['available at https://gitlab.com/_namespace_gitlab_/test_create_requests/merge_requests/1']
273+
])
276274

277275
def test_20_request_create__bad_branch(self):
278276
with pytest.raises(ResourceNotFoundError):

0 commit comments

Comments
 (0)