Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playback: Check outgoing traffic if it matches what is recorded in VCR tape + check if test source code changed + remove non-gzip vcr tape compat #8

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cb86605
introduce some exception classes
megies Apr 3, 2017
46e119a
refactor getting next playlist item
megies Apr 3, 2017
80c0eab
vcr playback: add checking of outgoing traffic whether it matches the
megies Apr 3, 2017
4a8f509
VCRSystem: class variable that handles all normalization functions for
megies Apr 3, 2017
e27e0f4
add check of hashed source code, to make sure that test code has not
megies Apr 3, 2017
7a5d8c3
concatenate two consecutive sendalls in vcr playlist if this is how the
megies Apr 3, 2017
2f2863c
refactoring, only rename variables
megies Apr 3, 2017
b7c2b21
remove compatibility for non-gzipped vcr tapes, we need to create new
megies Apr 3, 2017
9ed6c9e
refactoring
megies Apr 4, 2017
f6c71db
omit first line when creating source code hash for vcr tape
megies Apr 6, 2017
a16b8d4
add normalization function for outgoing traffic checks in POST test
megies Apr 7, 2017
1b30cfa
update all test vcr tapes
megies Apr 7, 2017
9252b91
add vcr tape for doctest, see #11
megies Apr 7, 2017
1d920e3
move outgoing traffic normalization helper function used in tests to …
megies Apr 7, 2017
f9df86e
add outgoing traffic normalization function in tests setUp/tearDown
megies Apr 7, 2017
31d6def
some more outgoing traffic check normalizations
megies Apr 7, 2017
f253ae0
try to control order of POST payload and REST URLs in tests
megies Apr 7, 2017
cb63e5f
update some vcr tapes due to last commit
megies Apr 7, 2017
35a8a21
fix normalization of 'boundary=...' patterns in outgoing traffic checks
megies Apr 25, 2017
225461c
SQUASH update one vcr tape
megies Apr 25, 2017
60f9f57
use http header normalization in outgoing traffic checks in all relevant
megies Apr 26, 2017
74bb27d
more detailed error meassage on failing outgoing traffic check
megies Apr 26, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import warnings

from vcr import vcr, VCRSystem
from vcr.utils import catch_stdout, skip_if_py2
from vcr.utils import catch_stdout, skip_if_py2, _normalize_http_header

try:
# Py2
Expand All @@ -27,13 +27,16 @@ def setUp(self):
self.path = os.path.join(os.path.dirname(__file__), 'vcrtapes')
self.temp_test_vcr = os.path.join(self.path, 'test_core.temp_test.vcr')
self.read_test_vcr = os.path.join(self.path, 'test_core.read_test.vcr')
VCRSystem.outgoing_check_normalizations = [
_normalize_http_header]

def tearDown(self):
# cleanup temporary files
try:
os.remove(self.temp_test_vcr)
except OSError:
pass
VCRSystem.reset()

def test_connectivity(self):
# basic network connection test to exclude network issues
Expand Down Expand Up @@ -207,6 +210,8 @@ def setUp(self):
self.path = os.path.join(os.path.dirname(__file__), 'vcrtapes')
self.temp_test_vcr = os.path.join(self.path, 'test_core.temp_test.vcr')
self.read_test_vcr = os.path.join(self.path, 'test_core.read_test.vcr')
VCRSystem.outgoing_check_normalizations = [
_normalize_http_header]

def tearDown(self):
# cleanup temporary files
Expand Down Expand Up @@ -238,6 +243,10 @@ def read_test():

# reset
VCRSystem.reset()
# due to the reset we have to put http header normalizations in place
# again which is done in test case setUp()
VCRSystem.outgoing_check_normalizations = [
_normalize_http_header]
# re-run the test - again no output
with catch_stdout() as out:
read_test()
Expand Down Expand Up @@ -271,6 +280,10 @@ def temp_test():

# reset
VCRSystem.reset()
# due to the reset we have to put http header normalizations in place
# again which is done in test case setUp()
VCRSystem.outgoing_check_normalizations = [
_normalize_http_header]
# get current mtime
mtime = os.path.getmtime(self.temp_test_vcr)
# run it again
Expand Down Expand Up @@ -299,6 +312,10 @@ def read_test():

# reset
VCRSystem.reset()
# due to the reset we have to put http header normalizations in place
# again which is done in test case setUp()
VCRSystem.outgoing_check_normalizations = [
_normalize_http_header]
# re-run the test - again output due to debug mode on decorator level
with catch_stdout() as out:
read_test()
Expand Down Expand Up @@ -328,6 +345,10 @@ def temp_test():

# reset
VCRSystem.reset()
# due to the reset we have to put http header normalizations in place
# again which is done in test case setUp()
VCRSystem.outgoing_check_normalizations = [
_normalize_http_header]
# re-run the test - now record mode without exception
with catch_stdout() as out:
temp_test()
Expand Down
11 changes: 9 additions & 2 deletions tests/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@

import requests

from vcr import vcr
from vcr import vcr, VCRSystem
from vcr.utils import _normalize_http_header


# monkey patch DocTestCase
def runTest(self): # NOQA
if '+VCR' in self._dt_test.docstring:
return vcr(self._runTest)()
VCRSystem.outgoing_check_normalizations = [
_normalize_http_header]
try:
ret = vcr(self._runTest)()
finally:
VCRSystem.outgoing_check_normalizations = []
return ret
return self._runTest()


Expand Down
16 changes: 12 additions & 4 deletions tests/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import unittest

from vcr import vcr
from vcr import vcr, VCRSystem
from vcr.utils import _normalize_http_header

try:
# Py3
Expand All @@ -15,10 +16,17 @@
from httplib import HTTPConnection, HTTPSConnection


class RequestsTestCase(unittest.TestCase):
class HTTPClientTestCase(unittest.TestCase):
"""
Test suite using requests
"""
def setUp(self):
VCRSystem.outgoing_check_normalizations = [
_normalize_http_header]

def tearDown(self):
VCRSystem.reset()

def test_connectivity(self):
# basic network connection test to exclude network issues
conn = HTTPSConnection("www.python.org")
Expand Down Expand Up @@ -79,8 +87,8 @@ def test_redirect_to_https(self):

@vcr
def test_http_post(self):
params = urlencode({'@number': 12524, '@type': 'issue',
'@action': 'show'})
params = urlencode([('@number', 12524), ('@type', 'issue'),
('@action', 'show')])
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
conn = HTTPConnection("bugs.python.org")
Expand Down
33 changes: 24 additions & 9 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@

import requests

from vcr import vcr
from vcr import vcr, VCRSystem
from vcr.utils import _normalize_http_header


class RequestsTestCase(unittest.TestCase):
"""
Test suite using requests
"""
def setUp(self):
VCRSystem.outgoing_check_normalizations = [
_normalize_http_header]

def tearDown(self):
VCRSystem.reset()

def test_connectivity(self):
# basic network connection test to exclude network issues
r = requests.get('https://www.python.org/')
Expand All @@ -26,20 +34,27 @@ def test_http_get(self):

@vcr
def test_http_post(self):
payload = dict(key1='value1', key2='value2')
# order of body items can be controlled by using a list of tuples as
# opposed to a dictionary
payload = [('key1', 'value1'), ('key2', 'value2')]
r = requests.post('http://httpbin.org/post', data=payload)
out = json.loads(r.text)
self.assertEqual(out['form'], {'key1': 'value1', 'key2': 'value2'})

@vcr
def test_http_post_file(self):
with tempfile.TemporaryFile(mode='wb+') as file:
file.write(b'test123')
file.seek(0)
files = {'file': file}
r = requests.post('http://httpbin.org/post', files=files)
out = json.loads(r.text)
self.assertEqual(out['files']['file'], 'test123')
VCRSystem.outgoing_check_normalizations = [
_normalize_http_header]
try:
with tempfile.TemporaryFile(mode='wb+') as file:
file.write(b'test123')
file.seek(0)
files = {'file': file}
r = requests.post('http://httpbin.org/post', files=files)
out = json.loads(r.text)
self.assertEqual(out['files']['file'], 'test123')
finally:
VCRSystem.outgoing_check_normalizations = []

@vcr
def test_cookies(self):
Expand Down
11 changes: 10 additions & 1 deletion tests/test_xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import unittest

from vcr import vcr
from vcr import vcr, VCRSystem
from vcr.utils import _normalize_http_header


try:
Expand All @@ -18,6 +19,14 @@ class XMLRPCTestCase(unittest.TestCase):
"""
Test suite using xmlrpc
"""
def setUp(self):
VCRSystem.outgoing_check_normalizations = [
_normalize_http_header]

def tearDown(self):
# reset to default settings
VCRSystem.reset()

@vcr
def test_serverproxy(self):
server = ServerProxy("http://betty.userland.com")
Expand Down
Binary file modified tests/vcrtapes/test_core.read_test.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_doctest.some_function_with_doctest.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_http_client.test_http_get.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_http_client.test_http_get_invalid.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_http_client.test_http_post.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_http_client.test_https_get.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_http_client.test_https_head.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_http_client.test_redirect_to_https.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_allow_redirects_false.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_cookie_jar.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_cookies.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_get_fdsn.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_get_obspy_example.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_http_get.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_http_post.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_http_post_file.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_https_get.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_redirect.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_redirect_twice.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_sessions.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_sessions2.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_socket.test_arclink.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_socket.test_seedlink.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_telnetlib.test_arclink.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_telnetlib.test_read_until_only_linesep.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_xmlrpc.test_serverproxy.vcr
Binary file not shown.
2 changes: 1 addition & 1 deletion vcr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

from .core import vcr, VCRSystem
from .core import vcr, VCRSystem, VCRException
Loading