From c0286dfd9783ff71a6511347f65f389a8cc34db7 Mon Sep 17 00:00:00 2001 From: Diaoul Date: Sat, 11 Jul 2015 23:19:09 +0200 Subject: [PATCH] Add body matcher unit tests --- tests/unit/test_matchers.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/unit/test_matchers.py b/tests/unit/test_matchers.py index f942bd2..d4b32de 100644 --- a/tests/unit/test_matchers.py +++ b/tests/unit/test_matchers.py @@ -35,6 +35,38 @@ def test_uri_matcher(): assert matched +def test_body_matcher(): + # raw + req1 = request.Request('POST', 'http://host.com/', '123', {}) + req2 = request.Request('POST', 'http://another-host.com/', '123', {'Some-Header': 'value'}) + assert matchers.body(req1, req2) + + # application/x-www-form-urlencoded + req1 = request.Request('POST', 'http://host.com/', 'a=1&b=2', {'Content-Type': 'application/x-www-form-urlencoded'}) + req2 = request.Request('POST', 'http://host.com/', 'b=2&a=1', {'Content-Type': 'application/x-www-form-urlencoded'}) + assert matchers.body(req1, req2) + + # application/json + req1 = request.Request('POST', 'http://host.com/', '{"a": 1, "b": 2}', {'Content-Type': 'application/json'}) + req2 = request.Request('POST', 'http://host.com/', '{"b": 2, "a": 1}', {'content-type': 'application/json'}) + assert matchers.body(req1, req2) + + # xmlrpc + req1_body = (b"test" + b"" + b"a1" + b"b2" + b"") + req2_body = (b"test" + b"" + b"b2" + b"a1" + b"") + req1 = request.Request('POST', 'http://host.com/', req1_body, {'User-Agent': 'xmlrpclib', 'Content-Type': 'text/xml'}) + req2 = request.Request('POST', 'http://host.com/', req2_body, {'user-agent': 'somexmlrpc', 'content-type': 'text/xml'}) + assert matchers.body(req1, req2) + + def test_query_matcher(): req1 = request.Request('GET', 'http://host.com/?a=b&c=d', '', {}) req2 = request.Request('GET', 'http://host.com/?c=d&a=b', '', {})