diff --git a/tests/integration/test_requests.py b/tests/integration/test_requests.py index 148607f..02900d9 100644 --- a/tests/integration/test_requests.py +++ b/tests/integration/test_requests.py @@ -282,3 +282,17 @@ def test_filter_post_params(tmpdir, httpbin_both): requests.post(url, data={'key': 'value'}) with vcr.use_cassette(cass_loc, filter_post_data_parameters=['key']) as cass: assert b'key=value' not in cass.requests[0].body + + +def test_post_unicode_match_on_body(tmpdir, httpbin_both): + '''Ensure that matching on POST body that contains Unicode characters works.''' + data = {'key1': 'value1', '●‿●': '٩(●̮̮̃•̃)۶'} + url = httpbin_both + '/post' + + with vcr.use_cassette(str(tmpdir.join('requests.yaml')), additional_matchers=('body',)): + req1 = requests.post(url, data).content + + with vcr.use_cassette(str(tmpdir.join('requests.yaml')), additional_matchers=('body',)): + req2 = requests.post(url, data).content + + assert req1 == req2 diff --git a/tests/integration/test_wild.py b/tests/integration/test_wild.py index ee1eafa..33f1edb 100644 --- a/tests/integration/test_wild.py +++ b/tests/integration/test_wild.py @@ -81,16 +81,23 @@ def test_amazon_doctype(tmpdir): assert 'html' in r.text +def start_rpc_server(q): + httpd = xmlrpc_server.SimpleXMLRPCServer(('127.0.0.1', 0)) + httpd.register_function(pow) + q.put('http://{}:{}'.format(*httpd.server_address)) + httpd.serve_forever() + + @pytest.yield_fixture(scope='session') def rpc_server(): - httpd = xmlrpc_server.SimpleXMLRPCServer(('', 0)) - httpd.register_function(pow) + q = multiprocessing.Queue() proxy_process = multiprocessing.Process( - target=httpd.serve_forever, + target=start_rpc_server, + args=(q,) ) try: proxy_process.start() - yield 'http://{}:{}'.format(*httpd.server_address) + yield q.get() finally: proxy_process.terminate() diff --git a/tests/unit/test_vcr.py b/tests/unit/test_vcr.py index 5a6bb6e..f473db3 100644 --- a/tests/unit/test_vcr.py +++ b/tests/unit/test_vcr.py @@ -147,7 +147,7 @@ def test_vcr_path_transformer(): # and it should still work with cassette_library_dir vcr = VCR(cassette_library_dir='/foo') with vcr.use_cassette('test') as cassette: - assert cassette._path == '/foo/test' + assert os.path.abspath(cassette._path) == os.path.abspath('/foo/test') @pytest.fixture diff --git a/vcr/matchers.py b/vcr/matchers.py index 1714018..8a04f7c 100644 --- a/vcr/matchers.py +++ b/vcr/matchers.py @@ -68,9 +68,12 @@ def _transform_json(body): _xml_header_checker = _header_checker('text/xml') _xmlrpc_header_checker = _header_checker('xmlrpc', header='User-Agent') _checker_transformer_pairs = ( - (_header_checker('application/x-www-form-urlencoded'), urllib.parse.parse_qs), - (_header_checker('application/json'), _transform_json), - (lambda request: _xml_header_checker(request) and _xmlrpc_header_checker(request), xmlrpc_client.loads), + (_header_checker('application/x-www-form-urlencoded'), + lambda body: urllib.parse.parse_qs(body.decode('ascii'))), + (_header_checker('application/json'), + _transform_json), + (lambda request: _xml_header_checker(request) and _xmlrpc_header_checker(request), + xmlrpc_client.loads), )