mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Added query to Request with matcher and test
This commit is contained in:
@@ -35,8 +35,21 @@ def test_url_matcher():
|
||||
assert matched
|
||||
|
||||
|
||||
def test_query_matcher():
|
||||
req1 = request.Request('GET', 'http://host.com:80/?a=b&c=d', '', {})
|
||||
req2 = request.Request('GET', 'http://host.com:80/?c=d&a=b', '', {})
|
||||
assert matchers.query(req1, req2)
|
||||
|
||||
req1 = request.Request('GET', 'http://host.com:80/?a=b&a=b&c=d', '', {})
|
||||
req2 = request.Request('GET', 'http://host.com:80/?a=b&c=d&a=b', '', {})
|
||||
req3 = request.Request('GET', 'http://host.com:80/?c=d&a=b&a=b', '', {})
|
||||
assert matchers.query(req1, req2)
|
||||
assert matchers.query(req1, req3)
|
||||
|
||||
|
||||
def test_metchers():
|
||||
assert_matcher('method')
|
||||
assert_matcher('host')
|
||||
assert_matcher('port')
|
||||
assert_matcher('path')
|
||||
assert_matcher('query')
|
||||
|
||||
@@ -21,6 +21,10 @@ def path(r1, r2):
|
||||
return r1.path == r2.path
|
||||
|
||||
|
||||
def query(r1, r2):
|
||||
return r1.query == r2.query
|
||||
|
||||
|
||||
def body(r1, r2):
|
||||
return r1.body == r2.body
|
||||
|
||||
|
||||
@@ -27,6 +27,11 @@ class Request(object):
|
||||
def path(self):
|
||||
return urlparse(self.uri).path
|
||||
|
||||
@property
|
||||
def query(self):
|
||||
q = urlparse(self.uri).query
|
||||
return sorted(parse_qsl(q))
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return self.uri
|
||||
|
||||
Reference in New Issue
Block a user