Skip to content

Commit 866bedf

Browse files
committed
🚧 Updates tests for request create; 📼 Refreshes BM
1 parent 13a6442 commit 866bedf

8 files changed

+86
-31
lines changed

tests/helpers.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def request_create(self, *args, **kwarg):
154154
raise Exception('bad branch to request!')
155155
local = args[2] or 'pr-test'
156156
remote = args[3] or 'base-test'
157-
return {'local': local, 'remote': remote, 'ref': 42}
157+
return {'local': local, 'remote': remote, 'project': '/'.join(args[:2]), 'ref': 42}
158158

159159
@classmethod
160160
def get_auth_token(cls, login, password, prompt=None):
@@ -632,6 +632,8 @@ def action_request_fetch(self, namespace, repository, request, pull=False, fail=
632632
self.set_mock_popen_commands([
633633
('git remote add all {}'.format(local_slug), b'', b'', 0),
634634
('git remote add {} {}'.format(self.service.name, local_slug), b'', b'', 0),
635+
('git remote get-url --all all', local_slug.encode('utf-8'), b'', 0),
636+
('git remote get-url --all {}'.format(self.service.name), local_slug.encode('utf-8'), b'', 0),
635637
('git version', b'git version 2.8.0', b'', 0),
636638
('git pull --progress -v {} master'.format(self.service.name), b'', '\n'.join([
637639
'POST git-upload-pack (140 bytes)',
@@ -683,7 +685,7 @@ def action_request_fetch(self, namespace, repository, request, pull=False, fail=
683685
' * [new branch] master -> {1}/{0}'.format(request, local_branch)]).encode('utf-8'),
684686
0)
685687
])
686-
self.service.request_fetch(repository, namespace, request)
688+
self.service.request_fetch(namespace, repository, request)
687689

688690
def action_request_create(self,
689691
namespace, repository, branch,
@@ -740,6 +742,12 @@ def prepare_project_for_test():
740742
self.repository.git.add('second_file')
741743
self.repository.git.commit(message='Second commit')
742744
self.repository.git.push(service, create_branch)
745+
else:
746+
import git
747+
self.service._extracts_ref = lambda *a: git.Reference(
748+
self.service.repository,
749+
'{}/{}'.format(namespace, repository),
750+
check_path=False)
743751
existing_remotes = [r.name for r in self.repository.remotes]
744752
if 'all' in existing_remotes:
745753
r_all = self.repository.remote('all')

tests/integration/cassettes/test_gitlab_test_20_request_create.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"User-Agent": "python-requests/2.10.0"
5858
},
5959
"method": "GET",
60-
"uri": "https://gitlab.com/api/v3/projects/guyzmo%2Ftest_create_requests"
60+
"uri": "https://gitlab.com/api/v3/projects/<GITLAB_NAMESPACE>%2Ftest_create_requests"
6161
},
6262
"response": {
6363
"body": {
@@ -79,7 +79,7 @@
7979
"code": 200,
8080
"message": "OK"
8181
},
82-
"url": "https://gitlab.com/api/v3/projects/guyzmo%2Ftest_create_requests"
82+
"url": "https://gitlab.com/api/v3/projects/<GITLAB_NAMESPACE>%2Ftest_create_requests"
8383
}
8484
},
8585
{

tests/integration/cassettes/test_gitlab_test_20_request_create__bad_branch.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,45 @@
124124
},
125125
"url": "https://gitlab.com/api/v3/projects/2078713/merge_requests"
126126
}
127+
},
128+
{
129+
"recorded_at": "2017-05-02T09:48:23",
130+
"request": {
131+
"body": {
132+
"encoding": "utf-8",
133+
"string": ""
134+
},
135+
"headers": {
136+
"Accept": "*/*",
137+
"Accept-Encoding": "identity",
138+
"Connection": "keep-alive",
139+
"PRIVATE-TOKEN": "<PRIVATE_KEY_GITLAB>",
140+
"User-Agent": "python-requests/2.13.0"
141+
},
142+
"method": "GET",
143+
"uri": "https://gitlab.com/api/v3/projects/<GITLAB_NAMESPACE>%2Ftest_create_requests"
144+
},
145+
"response": {
146+
"body": {
147+
"encoding": null,
148+
"string": "{\"message\":\"404 Project Not Found\"}"
149+
},
150+
"headers": {
151+
"Cache-Control": "no-cache",
152+
"Content-Length": "35",
153+
"Content-Type": "application/json",
154+
"Date": "Tue, 02 May 2017 09:48:22 GMT",
155+
"Server": "nginx",
156+
"Vary": "Origin",
157+
"X-Request-Id": "3327ef70-1805-4972-9614-bac723eb240e",
158+
"X-Runtime": "0.070080"
159+
},
160+
"status": {
161+
"code": 404,
162+
"message": "Not Found"
163+
},
164+
"url": "https://gitlab.com/api/v3/projects/<GITLAB_NAMESPACE>%2Ftest_create_requests"
165+
}
127166
}
128167
],
129168
"recorded_with": "betamax/0.5.1"

tests/integration/cassettes/test_gitlab_test_20_request_create__bad_repo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"User-Agent": "python-requests/2.10.0"
5858
},
5959
"method": "GET",
60-
"uri": "https://gitlab.com/api/v3/projects/guyzmo%2Fdoes_not_exists"
60+
"uri": "https://gitlab.com/api/v3/projects/<GITLAB_NAMESPACE>%2Fdoes_not_exists"
6161
},
6262
"response": {
6363
"body": {

tests/integration/cassettes/test_gitlab_test_20_request_create__blank_branch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"User-Agent": "python-requests/2.10.0"
5858
},
5959
"method": "GET",
60-
"uri": "https://gitlab.com/api/v3/projects/guyzmo%2Ftest_create_requests"
60+
"uri": "https://gitlab.com/api/v3/projects/<GITLAB_NAMESPACE>%2Ftest_create_requests"
6161
},
6262
"response": {
6363
"body": {
@@ -79,7 +79,7 @@
7979
"code": 200,
8080
"message": "OK"
8181
},
82-
"url": "https://gitlab.com/api/v3/projects/guyzmo%2Ftest_create_requests"
82+
"url": "https://gitlab.com/api/v3/projects/<GITLAB_NAMESPACE>%2Ftest_create_requests"
8383
}
8484
},
8585
{

tests/integration/test_github.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ def test_32_request_create(self):
318318
assert r == {
319319
'local': 'pr-test',
320320
'ref': 1,
321-
'remote': 'PR test',
321+
'remote': 'pr-test',
322+
'project': '_namespace_github_/test_create_requests',
322323
'url': 'https://github.com/{}/test_create_requests/pull/1'.format(self.namespace),
323324
}
324325

tests/integration/test_gitlab.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
class Test_Gitlab(GitRepoTestCase):
2222
log = log
23+
namespace = os.environ['GITLAB_NAMESPACE']
2324

2425
@property
2526
def local_namespace(self):
@@ -238,43 +239,48 @@ def test_18_request_list(self):
238239
])
239240

240241
def test_19_request_fetch(self):
241-
self.action_request_fetch(namespace='guyzmo',
242+
self.action_request_fetch(namespace=self.local_namespace,
242243
repository='git-repo',
243244
request='4',
244245
remote_branch='merge_requests',
245246
local_branch='requests/gitlab')
246247

247248
def test_19_request_fetch__bad_request(self):
248249
with pytest.raises(ResourceNotFoundError):
249-
self.action_request_fetch(namespace='git-repo-test',
250+
self.action_request_fetch(namespace=self.local_namespace,
250251
repository='git-repo',
251252
request='42',
252253
remote_branch='merge_requests',
253254
local_branch='requests/gitlab',
254255
fail=True)
255256

256257
def test_20_request_create(self):
257-
r = self.action_request_create(namespace='guyzmo',
258+
r = self.action_request_create(namespace=self.local_namespace,
258259
repository='test_create_requests',
259260
branch='pr-test',
260261
title='PR test',
261262
description='PR description',
262263
service='gitlab')
263-
assert r == {'local': 'pr-test', 'ref': 1, 'remote': 'PR test'}
264-
265-
# TODO lookup why this is not raising the expected error !
266-
# def test_20_request_create__bad_branch(self):
267-
# with pytest.raises(ResourceError):
268-
# self.action_request_create(namespace='guyzmo',
269-
# repository='test_create_requests',
270-
# branch='this_is_not_a_branch',
271-
# title='PR test',
272-
# description='PR description',
273-
# service='gitlab')
264+
assert r == {
265+
'local': 'pr-test',
266+
'project': '_namespace_gitlab_/test_create_requests',
267+
'ref': 1,
268+
'remote': 'pr-test',
269+
'url': 'https://gitlab.com/_namespace_gitlab_/test_create_requests/merge_requests/1'
270+
}
271+
272+
def test_20_request_create__bad_branch(self):
273+
with pytest.raises(ResourceNotFoundError):
274+
self.action_request_create(namespace=self.local_namespace,
275+
repository='test_create_requests',
276+
branch='this_is_not_a_branch',
277+
title='PR test',
278+
description='PR description',
279+
service='gitlab')
274280

275281
def test_20_request_create__bad_repo(self):
276282
with pytest.raises(ResourceNotFoundError):
277-
r = self.action_request_create(namespace='guyzmo',
283+
r = self.action_request_create(namespace=self.local_namespace,
278284
repository='does_not_exists',
279285
branch='pr-test',
280286
title='PR test',
@@ -283,14 +289,14 @@ def test_20_request_create__bad_repo(self):
283289

284290
def test_20_request_create__blank_branch(self):
285291
with pytest.raises(ResourceError):
286-
r = self.action_request_create(namespace='guyzmo',
292+
r = self.action_request_create(namespace=self.local_namespace,
287293
repository='test_create_requests',
288294
branch=None,
289295
title='PR test',
290296
description='PR description',
291297
service='gitlab')
292298

293299
def test_31_open(self):
294-
self.action_open(namespace='guyzmo',
300+
self.action_open(namespace=self.local_namespace,
295301
repository='git-repo')
296302

tests/integration/test_main.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
import logging
4+
import pytest
45

56
#################################################################################
67
# Enable logging
@@ -409,7 +410,7 @@ def test_request_create(self, capsys, caplog):
409410
})
410411
out, err = capsys.readouterr()
411412
seen_args = seen_args[:-1] # remove the passed edition function
412-
assert ('guyzmo', 'test', 'pr-test', 'base-test', 'This is a test', 'This is a test', True) == seen_args
413+
assert ('guyzmo', 'test', 'pr-test', 'base-test', 'This is a test', 'This is a test', False) == seen_args
413414
assert {} == extra_args
414415
assert out == ''
415416
assert 'Successfully created request of `pr-test` onto `guyzmo/test:base-test`, with id `42`!' in caplog.text
@@ -425,7 +426,7 @@ def test_request_create__no_description(self, capsys, caplog):
425426
})
426427
out, err = capsys.readouterr()
427428
seen_args = seen_args[:-1] # remove the passed edition function
428-
assert ('guyzmo', 'test', 'pr-test', 'base-test', 'This is a test', None, True) == seen_args
429+
assert ('guyzmo', 'test', 'pr-test', 'base-test', 'This is a test', None, False) == seen_args
429430
assert {} == extra_args
430431
assert out == ''
431432
assert 'Successfully created request of `pr-test` onto `guyzmo/test:base-test`, with id `42`!' in caplog.text
@@ -442,7 +443,7 @@ def test_request_create__bad_local_branch(self, capsys, caplog):
442443
})
443444
out, err = capsys.readouterr()
444445
seen_args = seen_args[:-1] # remove the passed edition function
445-
assert ('guyzmo', 'test', 'bad', 'base-test', 'This is a test', 'This is a test', True) == seen_args
446+
assert ('guyzmo', 'test', 'bad', 'base-test', 'This is a test', 'This is a test', False) == seen_args
446447
assert {} == extra_args
447448
assert out == ''
448449
assert 'Fatal error: bad branch to request!' in caplog.text
@@ -459,7 +460,7 @@ def test_request_create__bad_remote_branch(self, capsys, caplog):
459460
})
460461
out, err = capsys.readouterr()
461462
seen_args = seen_args[:-1] # remove the passed edition function
462-
assert ('guyzmo', 'test', 'pr-test', 'bad', 'This is a test', 'This is a test', True) == seen_args
463+
assert ('guyzmo', 'test', 'pr-test', 'bad', 'This is a test', 'This is a test', False) == seen_args
463464
assert {} == extra_args
464465
assert out == ''
465466
assert 'Fatal error: bad branch to request!' in caplog.text
@@ -475,7 +476,7 @@ def test_request_create__no_local_branch(self, capsys, caplog):
475476
})
476477
out, err = capsys.readouterr()
477478
seen_args = seen_args[:-1] # remove the passed edition function
478-
assert ('guyzmo', 'test', None, 'base-test', 'This is a test', 'This is a test', True) == seen_args
479+
assert ('guyzmo', 'test', None, 'base-test', 'This is a test', 'This is a test', False) == seen_args
479480
assert {} == extra_args
480481
assert out == ''
481482
assert 'Successfully created request of `pr-test` onto `guyzmo/test:base-test`, with id `42`!' in caplog.text
@@ -491,7 +492,7 @@ def test_request_create__no_remote_branch(self, capsys, caplog):
491492
})
492493
out, err = capsys.readouterr()
493494
seen_args = seen_args[:-1] # remove the passed edition function
494-
assert ('guyzmo', 'test', 'pr-test', None, 'This is a test', 'This is a test', True) == seen_args
495+
assert ('guyzmo', 'test', 'pr-test', None, 'This is a test', 'This is a test', False) == seen_args
495496
assert {} == extra_args
496497
assert out == ''
497498
assert 'Successfully created request of `pr-test` onto `guyzmo/test:base-test`, with id `42`!' in caplog.text

0 commit comments

Comments
 (0)