Mercurial > public > mercurial-scm > hg
comparison hgext/phabricator.py @ 42268:af13e2088f77
phabricator: add custom vcr matcher to match request bodies
Currently when the phabricator extension's conduit output changes the tests
don't notice since the default vcr matcher only matches on 'method' and 'uri',
not the body.
Add a custom matcher that checks the same params are in the body (ignoring
ordering).
vcr's in-built body matcher can't be used since it fails under py3 with a
"UnicodeEncodeError" on the "? in commit message" tests.
The DREV ids have decreased since the recordings were generated against a
different phabricator instance to avoid spamming mercurial-devel.
Differential Revision: https://phab.mercurial-scm.org/D6347
author | Ian Moody <moz-ian@perix.co.uk> |
---|---|
date | Sun, 05 May 2019 17:04:48 +0100 |
parents | 231334c1ee96 |
children | 29528c4235a1 |
comparison
equal
deleted
inserted
replaced
42267:838f3a094b4f | 42268:af13e2088f77 |
---|---|
125 )), | 125 )), |
126 ] | 126 ] |
127 | 127 |
128 def vcrcommand(name, flags, spec, helpcategory=None): | 128 def vcrcommand(name, flags, spec, helpcategory=None): |
129 fullflags = flags + _VCR_FLAGS | 129 fullflags = flags + _VCR_FLAGS |
130 def hgmatcher(r1, r2): | |
131 if r1.uri != r2.uri or r1.method != r2.method: | |
132 return False | |
133 r1params = r1.body.split(b'&') | |
134 r2params = r2.body.split(b'&') | |
135 return set(r1params) == set(r2params) | |
136 | |
130 def decorate(fn): | 137 def decorate(fn): |
131 def inner(*args, **kwargs): | 138 def inner(*args, **kwargs): |
132 cassette = pycompat.fsdecode(kwargs.pop(r'test_vcr', None)) | 139 cassette = pycompat.fsdecode(kwargs.pop(r'test_vcr', None)) |
133 if cassette: | 140 if cassette: |
134 import hgdemandimport | 141 import hgdemandimport |
141 (urlmod, r'httpconnection', | 148 (urlmod, r'httpconnection', |
142 stubs.VCRHTTPConnection), | 149 stubs.VCRHTTPConnection), |
143 (urlmod, r'httpsconnection', | 150 (urlmod, r'httpsconnection', |
144 stubs.VCRHTTPSConnection), | 151 stubs.VCRHTTPSConnection), |
145 ]) | 152 ]) |
146 with vcr.use_cassette(cassette): | 153 vcr.register_matcher(r'hgmatcher', hgmatcher) |
154 with vcr.use_cassette(cassette, match_on=[r'hgmatcher']): | |
147 return fn(*args, **kwargs) | 155 return fn(*args, **kwargs) |
148 return fn(*args, **kwargs) | 156 return fn(*args, **kwargs) |
149 inner.__name__ = fn.__name__ | 157 inner.__name__ = fn.__name__ |
150 inner.__doc__ = fn.__doc__ | 158 inner.__doc__ = fn.__doc__ |
151 return command(name, fullflags, spec, helpcategory=helpcategory)(inner) | 159 return command(name, fullflags, spec, helpcategory=helpcategory)(inner) |