From 4267828a3e45751902ee9ef3ba9cfd971ea15223 Mon Sep 17 00:00:00 2001 From: Max Shytikov Date: Mon, 7 Apr 2014 01:56:55 +0200 Subject: [PATCH] Added 'scheme' to Request with matcher and test --- tests/unit/test_matchers.py | 3 ++- vcr/matchers.py | 4 ++++ vcr/request.py | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_matchers.py b/tests/unit/test_matchers.py index e3c85fb..30ab5ff 100644 --- a/tests/unit/test_matchers.py +++ b/tests/unit/test_matchers.py @@ -8,7 +8,7 @@ from vcr import request REQUESTS = { 'base': request.Request('GET', 'http://host.com:80/p?a=b', '', {}), 'method': request.Request('POST', 'http://host.com:80/p?a=b', '', {}), - 'protocol': request.Request('GET', 'https://host.com:80/p?a=b', '', {}), + 'scheme': request.Request('GET', 'https://host.com:80/p?a=b', '', {}), 'host': request.Request('GET', 'http://another-host.com:80/p?a=b', '', {}), 'port': request.Request('GET', 'http://host.com:90/p?a=b', '', {}), 'path': request.Request('GET', 'http://host.com:80/x?a=b', '', {}), @@ -49,6 +49,7 @@ def test_query_matcher(): def test_metchers(): assert_matcher('method') + assert_matcher('scheme') assert_matcher('host') assert_matcher('port') assert_matcher('path') diff --git a/vcr/matchers.py b/vcr/matchers.py index 4dde6a0..1918652 100644 --- a/vcr/matchers.py +++ b/vcr/matchers.py @@ -13,6 +13,10 @@ def host(r1, r2): return r1.host == r2.host +def scheme(r1, r2): + return r1.scheme == r2.scheme + + def port(r1, r2): return r1.port == r2.port diff --git a/vcr/request.py b/vcr/request.py index ca6faee..9e76352 100644 --- a/vcr/request.py +++ b/vcr/request.py @@ -15,6 +15,10 @@ class Request(object): tmp[key] = value self.headers = frozenset(tmp.iteritems()) + @property + def scheme(self): + return urlparse(self.uri).scheme + @property def host(self): return urlparse(self.uri).hostname