Skip to content

Commit a258b0c

Browse files
committed
🚒 Fixes repository mockup to always point to singleton
1 parent 67bc125 commit a258b0c

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

tests/helpers.py

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -74,34 +74,34 @@ def __init__(self, *args, **kwarg):
7474
self._did_request_fetch = None
7575

7676
def pull(self, *args, **kwarg):
77-
self._did_pull = (args, kwarg)
77+
self.__class__._current._did_pull = (args, kwarg)
7878

7979
def clone(self, *args, **kwarg):
80-
self._did_clone = (args, kwarg)
80+
self.__class__._current._did_clone = (args, kwarg)
8181

8282
def add(self, repo, user=None, *args, **kwarg):
83-
self._did_add = ((user, repo)+args, kwarg)
83+
self.__class__._current._did_add = ((user, repo)+args, kwarg)
8484
class FakeRemote:
8585
name = 'foobar'
8686
return FakeRemote, user, repo
8787

8888
def open(self, *args, **kwarg):
89-
self._did_open = (args, kwarg)
89+
self.__class__._current._did_open = (args, kwarg)
9090

9191
def connect(self):
92-
self._did_connect = True
92+
self.__class__._current._did_connect = True
9393

9494
def delete(self, *args, **kwarg):
95-
self._did_delete = (tuple(reversed(args)), kwarg)
95+
self.__class__._current._did_delete = (tuple(reversed(args)), kwarg)
9696

9797
def create(self, *args, **kwarg):
98-
self._did_create = (args, kwarg)
98+
self.__class__._current._did_create = (args, kwarg)
9999

100100
def fork(self, *args, **kwarg):
101-
self._did_fork = (args, kwarg)
101+
self.__class__._current._did_fork = (args, kwarg)
102102

103103
def gist_list(self, *args, **kwarg):
104-
self._did_gist_list = (args, kwarg)
104+
self.__class__._current._did_gist_list = (args, kwarg)
105105
if len(args) == 0 or not args[0]:
106106
yield '{} {}'
107107
yield 'title', 'url'
@@ -119,7 +119,7 @@ def gist_list(self, *args, **kwarg):
119119
yield 'lang3', 'size3', 'name3'
120120

121121
def gist_fetch(self, *args, **kwarg):
122-
self._did_gist_fetch = (args, kwarg)
122+
self.__class__._current._did_gist_fetch = (args, kwarg)
123123
if args[0] == 'bad':
124124
raise Exception('bad gist!')
125125
elif args[1] == 'bad':
@@ -128,50 +128,56 @@ def gist_fetch(self, *args, **kwarg):
128128
return "content of a gist"
129129

130130
def gist_clone(self, *args, **kwarg):
131-
self._did_gist_clone = (args, kwarg)
131+
self.__class__._current._did_gist_clone = (args, kwarg)
132132
if args[0] == 'bad':
133133
raise Exception('bad gist!')
134134

135135
def gist_create(self, *args, **kwarg):
136-
self._did_gist_create = (args, kwarg)
136+
self.__class__._current._did_gist_create = (args, kwarg)
137137
if 'exists' in args[0]:
138138
raise Exception('gist exists!')
139139
return 'https://gists/42'
140140

141141
def gist_delete(self, *args, **kwarg):
142-
self._did_gist_delete = (args, kwarg)
142+
self.__class__._current._did_gist_delete = (args, kwarg)
143143
if args[0] == 'bad':
144144
raise Exception('bad gist!')
145145

146146
def request_list(self, *args, **kwarg):
147-
self._did_request_list = (args, kwarg)
147+
self.__class__._current._did_request_list = (args, kwarg)
148148
yield '{} {} {}'
149149
yield ('id', 'description', 'URL')
150150
yield ('1', 'desc1', 'http://request/1')
151151
yield ('2', 'desc2', 'http://request/2')
152152
yield ('3', 'desc3', 'http://request/3')
153153

154154
def request_fetch(self, *args, **kwarg):
155-
self._did_request_fetch = (args, kwarg)
155+
self.__class__._current._did_request_fetch = (args, kwarg)
156156
if args[-1] == 'bad':
157157
raise Exception('bad request for merge!')
158158
return "pr/42"
159159

160160
def request_create(self, *args, **kwarg):
161-
self._did_request_create = (args, kwarg)
161+
self.__class__._current._did_request_create = (args, kwarg)
162162
if args[2] == 'bad' or args[3] == 'bad':
163163
raise Exception('bad branch to request!')
164164
local = args[2] or 'pr-test'
165165
remote = args[3] or 'base-test'
166-
return {'local': local, 'remote': remote, 'project': '/'.join(args[:2]), 'ref': 42}
166+
# return
167+
yield '{}'
168+
yield ['Successfully created request of `{local}` onto `{project}:{remote}, with id `{ref}'.format(
169+
**{'local': local, 'remote': remote, 'project': '/'.join(args[:2]), 'ref': 42}
170+
)]
171+
yield ['available at {}'.format('https://...')]
172+
167173

168174
@classmethod
169175
def get_auth_token(cls, login, password, prompt=None):
170176
return '{}:{}'.format(login, password)
171177

172178
@property
173179
def user(self):
174-
self._did_user = True
180+
self.__class__._current._did_user = True
175181
return 'foobar'
176182

177183
def get_repository(self, *args, **kwarg):
@@ -181,6 +187,7 @@ def get_repository(self, *args, **kwarg):
181187
class GitRepoMainTestCase(TestGitPopenMockupMixin):
182188
def setup_method(self, method):
183189
self.log.info('GitRepoMainTestCase.setup_method({})'.format(method))
190+
RepositoryService._current = RepositoryMockup(c={})
184191
self.tempdir = TemporaryDirectory()
185192
RepositoryService.service_map = {
186193
'github': RepositoryMockup,
@@ -197,7 +204,6 @@ def setup_method(self, method):
197204

198205
def teardown_method(self, method):
199206
self.log.info('GitRepoMainTestCase.teardown_method({})'.format(method))
200-
RepositoryService._current = RepositoryMockup(c={})
201207
self.tempdir.cleanup()
202208

203209
def setup_args(self, d, args={}):
@@ -215,7 +221,6 @@ def setup_args(self, d, args={}):
215221
'<branch>': None,
216222
'<target>': self.target,
217223
'<target_repo>': None,
218-
'<user>/<repo>': '',
219224
'add': False,
220225
'clone': False,
221226
'create': False,
@@ -237,7 +242,7 @@ def setup_args(self, d, args={}):
237242
'<request>': None,
238243
'<local_branch>': None,
239244
'<remote_branch>': None,
240-
'<user>/<repo>': None,
245+
'<namespace>/<repo>': None,
241246
}
242247
cli_args.update(d)
243248
cli_args.update(args)
@@ -252,15 +257,15 @@ def main_add(self, repo, rc=0, args={}):
252257
Repo.init(os.path.join(self.tempdir.name, create_repo))
253258
assert rc == main(self.setup_args({
254259
'add': True,
255-
'<user>/<repo>': repo,
260+
'<namespace>/<repo>': repo,
256261
'--path': self.tempdir.name
257262
}, args)), "Non {} result for add".format(rc)
258263
return RepositoryService._current._did_add
259264

260265
def main_clone(self, repo, rc=0, args={}):
261266
assert rc == main(self.setup_args({
262267
'clone': True,
263-
'<user>/<repo>': repo,
268+
'<namespace>/<repo>': repo,
264269
'--path': self.tempdir.name
265270
}, args)), "Non {} result for clone".format(rc)
266271
return RepositoryService._current._did_clone
@@ -272,7 +277,7 @@ def main_create(self, repo=None, rc=0, args={}):
272277
Repo.init(repo_path)
273278
assert rc == main(self.setup_args({
274279
'create': True,
275-
'<user>/<repo>': repo,
280+
'<namespace>/<repo>': repo,
276281
'--path': self.tempdir.name
277282
}, args)), "Non {} result for create".format(rc)
278283
return RepositoryService._current._did_create
@@ -284,15 +289,15 @@ def main_delete(self, repo=None, rc=0, args={}):
284289
Repo.init(repo_path)
285290
assert rc == main(self.setup_args({
286291
'delete': True,
287-
'<user>/<repo>': repo,
292+
'<namespace>/<repo>': repo,
288293
'--path': self.tempdir.name,
289294
}, args)), "Non {} result for delete".format(rc)
290295
return RepositoryService._current._did_delete
291296

292297
def main_fork(self, repo=None, rc=0, args={}):
293298
assert rc == main(self.setup_args({
294299
'fork': True,
295-
'<user>/<repo>': repo,
300+
'<namespace>/<repo>': repo,
296301
'--path': self.tempdir.name
297302
}, args)), "Non {} result for fork".format(rc)
298303
return RepositoryService._current._did_fork
@@ -344,7 +349,7 @@ def main_request_list(self, repo=None, rc=0, args={}):
344349
assert rc == main(self.setup_args({
345350
'request': True,
346351
'list': True,
347-
'<user>/<repo>': repo,
352+
'<namespace>/<repo>': repo,
348353
'--clone': True,
349354
'--path': self.tempdir.name
350355
}, args)), "Non {} result for request list".format(rc)
@@ -354,7 +359,7 @@ def main_request_fetch(self, repo=None, rc=0, args={}):
354359
assert rc == main(self.setup_args({
355360
'request': True,
356361
'fetch': True,
357-
'<user>/<repo>': repo,
362+
'<namespace>/<repo>': repo,
358363
'--clone': True,
359364
'--path': self.tempdir.name
360365
}, args)), "Non {} result for request fetch".format(rc)
@@ -364,15 +369,15 @@ def main_request_create(self, repo=None, rc=0, args={}):
364369
assert rc == main(self.setup_args({
365370
'request': True,
366371
'create': True,
367-
'<user>/<repo>': repo,
372+
'<namespace>/<repo>': repo,
368373
'--path': self.tempdir.name
369374
}, args)), "Non {} result for request create".format(rc)
370375
return RepositoryService._current._did_request_create
371376

372377
def main_open(self, repo=None, rc=0, args={}):
373378
assert rc == main(self.setup_args({
374379
'open': True,
375-
'<user>/<repo>': repo,
380+
'<namespace>/<repo>': repo,
376381
'--path': self.tempdir.name
377382
}, args)), "Non {} result for open".format(rc)
378383
return RepositoryService._current._did_open
@@ -388,7 +393,7 @@ def main_config(self, target, rc=0, args={}):
388393

389394
def main_noop(self, repo, rc=1, args={}):
390395
assert rc == main(self.setup_args({
391-
'<user>/<repo>': repo,
396+
'<namespace>/<repo>': repo,
392397
'--path': self.tempdir.name
393398
}, args)), "Non {} result for no-action".format(rc)
394399

0 commit comments

Comments
 (0)