##// END OF EJS Templates
phabricator: add support for using the vcr library to mock interactions...
Augie Fackler -
r39686:d8f07b16 default
parent child Browse files
Show More
@@ -106,6 +106,37 b' colortable = {'
106 b'phabricator.node': b'',
106 b'phabricator.node': b'',
107 }
107 }
108
108
109 _VCR_FLAGS = [
110 (b'', b'test-vcr', b'',
111 _(b'Path to a vcr file. If nonexistent, will record a new vcr transcript'
112 b', otherwise will mock all http requests using the specified vcr file.'
113 b' (ADVANCED)'
114 )),
115 ]
116
117 def vcrcommand(name, flags, spec):
118 fullflags = flags + _VCR_FLAGS
119 def decorate(fn):
120 def inner(*args, **kwargs):
121 cassette = kwargs.pop(r'test_vcr', None)
122 if cassette:
123 import hgdemandimport
124 with hgdemandimport.deactivated():
125 import vcr as vcrmod
126 import vcr.stubs as stubs
127 vcr = vcrmod.VCR(
128 serializer=r'json',
129 custom_patches=[
130 (urlmod, 'httpconnection', stubs.VCRHTTPConnection),
131 (urlmod, 'httpsconnection', stubs.VCRHTTPSConnection),
132 ])
133 with vcr.use_cassette(cassette):
134 return fn(*args, **kwargs)
135 return fn(*args, **kwargs)
136 inner.__name__ = fn.__name__
137 return command(name, fullflags, spec)(inner)
138 return decorate
139
109 def urlencodenested(params):
140 def urlencodenested(params):
110 """like urlencode, but works with nested parameters.
141 """like urlencode, but works with nested parameters.
111
142
@@ -215,7 +246,7 b' def callconduit(repo, name, params):'
215 raise error.Abort(msg)
246 raise error.Abort(msg)
216 return parsed[r'result']
247 return parsed[r'result']
217
248
218 @command(b'debugcallconduit', [], _(b'METHOD'))
249 @vcrcommand(b'debugcallconduit', [], _(b'METHOD'))
219 def debugcallconduit(ui, repo, name):
250 def debugcallconduit(ui, repo, name):
220 """call Conduit API
251 """call Conduit API
221
252
@@ -452,7 +483,7 b' def userphids(repo, names):'
452 % b' '.join(sorted(unresolved)))
483 % b' '.join(sorted(unresolved)))
453 return [entry[r'phid'] for entry in data]
484 return [entry[r'phid'] for entry in data]
454
485
455 @command(b'phabsend',
486 @vcrcommand(b'phabsend',
456 [(b'r', b'rev', [], _(b'revisions to send'), _(b'REV')),
487 [(b'r', b'rev', [], _(b'revisions to send'), _(b'REV')),
457 (b'', b'amend', True, _(b'update commit messages')),
488 (b'', b'amend', True, _(b'update commit messages')),
458 (b'', b'reviewer', [], _(b'specify reviewers')),
489 (b'', b'reviewer', [], _(b'specify reviewers')),
@@ -909,7 +940,7 b' def readpatch(repo, drevs, write):'
909 content = b'%s%s\n%s' % (header, desc, body)
940 content = b'%s%s\n%s' % (header, desc, body)
910 write(encoding.unitolocal(content))
941 write(encoding.unitolocal(content))
911
942
912 @command(b'phabread',
943 @vcrcommand(b'phabread',
913 [(b'', b'stack', False, _(b'read dependencies'))],
944 [(b'', b'stack', False, _(b'read dependencies'))],
914 _(b'DREVSPEC [OPTIONS]'))
945 _(b'DREVSPEC [OPTIONS]'))
915 def phabread(ui, repo, spec, **opts):
946 def phabread(ui, repo, spec, **opts):
@@ -936,7 +967,7 b' def phabread(ui, repo, spec, **opts):'
936 drevs = querydrev(repo, spec)
967 drevs = querydrev(repo, spec)
937 readpatch(repo, drevs, ui.write)
968 readpatch(repo, drevs, ui.write)
938
969
939 @command(b'phabupdate',
970 @vcrcommand(b'phabupdate',
940 [(b'', b'accept', False, _(b'accept revisions')),
971 [(b'', b'accept', False, _(b'accept revisions')),
941 (b'', b'reject', False, _(b'reject revisions')),
972 (b'', b'reject', False, _(b'reject revisions')),
942 (b'', b'abandon', False, _(b'abandon revisions')),
973 (b'', b'abandon', False, _(b'abandon revisions')),
General Comments 0
You need to be logged in to leave comments. Login now