D4600: phabricator: add support for using the vcr library to mock interactions
durin42 (Augie Fackler)
phabricator at mercurial-scm.org
Sat Sep 15 07:31:33 UTC 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGd8f07b16abfc: phabricator: add support for using the vcr library to mock interactions (authored by durin42, committed by ).
CHANGED PRIOR TO COMMIT
https://phab.mercurial-scm.org/D4600?vs=11077&id=11089#toc
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D4600?vs=11077&id=11089
REVISION DETAIL
https://phab.mercurial-scm.org/D4600
AFFECTED FILES
contrib/phabricator.py
CHANGE DETAILS
diff --git a/contrib/phabricator.py b/contrib/phabricator.py
--- a/contrib/phabricator.py
+++ b/contrib/phabricator.py
@@ -106,6 +106,37 @@
b'phabricator.node': b'',
}
+_VCR_FLAGS = [
+ (b'', b'test-vcr', b'',
+ _(b'Path to a vcr file. If nonexistent, will record a new vcr transcript'
+ b', otherwise will mock all http requests using the specified vcr file.'
+ b' (ADVANCED)'
+ )),
+]
+
+def vcrcommand(name, flags, spec):
+ fullflags = flags + _VCR_FLAGS
+ def decorate(fn):
+ def inner(*args, **kwargs):
+ cassette = kwargs.pop(r'test_vcr', None)
+ if cassette:
+ import hgdemandimport
+ with hgdemandimport.deactivated():
+ import vcr as vcrmod
+ import vcr.stubs as stubs
+ vcr = vcrmod.VCR(
+ serializer=r'json',
+ custom_patches=[
+ (urlmod, 'httpconnection', stubs.VCRHTTPConnection),
+ (urlmod, 'httpsconnection', stubs.VCRHTTPSConnection),
+ ])
+ with vcr.use_cassette(cassette):
+ return fn(*args, **kwargs)
+ return fn(*args, **kwargs)
+ inner.__name__ = fn.__name__
+ return command(name, fullflags, spec)(inner)
+ return decorate
+
def urlencodenested(params):
"""like urlencode, but works with nested parameters.
@@ -215,7 +246,7 @@
raise error.Abort(msg)
return parsed[r'result']
- at command(b'debugcallconduit', [], _(b'METHOD'))
+ at vcrcommand(b'debugcallconduit', [], _(b'METHOD'))
def debugcallconduit(ui, repo, name):
"""call Conduit API
@@ -452,7 +483,7 @@
% b' '.join(sorted(unresolved)))
return [entry[r'phid'] for entry in data]
- at command(b'phabsend',
+ at vcrcommand(b'phabsend',
[(b'r', b'rev', [], _(b'revisions to send'), _(b'REV')),
(b'', b'amend', True, _(b'update commit messages')),
(b'', b'reviewer', [], _(b'specify reviewers')),
@@ -909,7 +940,7 @@
content = b'%s%s\n%s' % (header, desc, body)
write(encoding.unitolocal(content))
- at command(b'phabread',
+ at vcrcommand(b'phabread',
[(b'', b'stack', False, _(b'read dependencies'))],
_(b'DREVSPEC [OPTIONS]'))
def phabread(ui, repo, spec, **opts):
@@ -936,7 +967,7 @@
drevs = querydrev(repo, spec)
readpatch(repo, drevs, ui.write)
- at command(b'phabupdate',
+ at vcrcommand(b'phabupdate',
[(b'', b'accept', False, _(b'accept revisions')),
(b'', b'reject', False, _(b'reject revisions')),
(b'', b'abandon', False, _(b'abandon revisions')),
To: durin42, #hg-reviewers
Cc: yuja, mercurial-devel
More information about the Mercurial-devel
mailing list