Mercurial > hg-stable
diff hgext/phabricator.py @ 42295: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 |
line wrap: on
line diff
--- a/hgext/phabricator.py Thu May 09 18:37:37 2019 -0400 +++ b/hgext/phabricator.py Sun May 05 17:04:48 2019 +0100 @@ -127,6 +127,13 @@ def vcrcommand(name, flags, spec, helpcategory=None): fullflags = flags + _VCR_FLAGS + def hgmatcher(r1, r2): + if r1.uri != r2.uri or r1.method != r2.method: + return False + r1params = r1.body.split(b'&') + r2params = r2.body.split(b'&') + return set(r1params) == set(r2params) + def decorate(fn): def inner(*args, **kwargs): cassette = pycompat.fsdecode(kwargs.pop(r'test_vcr', None)) @@ -143,7 +150,8 @@ (urlmod, r'httpsconnection', stubs.VCRHTTPSConnection), ]) - with vcr.use_cassette(cassette): + vcr.register_matcher(r'hgmatcher', hgmatcher) + with vcr.use_cassette(cassette, match_on=[r'hgmatcher']): return fn(*args, **kwargs) return fn(*args, **kwargs) inner.__name__ = fn.__name__