mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Add test for proxies
This commit is contained in:
committed by
Samuel Fekete
parent
43f4eb8156
commit
236dc1f4f2
42
tests/integration/test_proxy.py
Normal file
42
tests/integration/test_proxy.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
'''Test using a proxy.'''
|
||||||
|
|
||||||
|
# External imports
|
||||||
|
import multiprocessing
|
||||||
|
import SocketServer
|
||||||
|
import SimpleHTTPServer
|
||||||
|
import pytest
|
||||||
|
requests = pytest.importorskip("requests")
|
||||||
|
|
||||||
|
from six.moves.urllib.request import urlopen
|
||||||
|
|
||||||
|
# Internal imports
|
||||||
|
import vcr
|
||||||
|
|
||||||
|
|
||||||
|
class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
|
'''
|
||||||
|
Simple proxy server.
|
||||||
|
|
||||||
|
(from: http://effbot.org/librarybook/simplehttpserver.htm).
|
||||||
|
'''
|
||||||
|
def do_GET(self):
|
||||||
|
self.copyfile(urlopen(self.path), self.wfile)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.yield_fixture(scope='session')
|
||||||
|
def proxy_server(httpbin):
|
||||||
|
httpd = SocketServer.ForkingTCPServer(('', 0), Proxy)
|
||||||
|
proxy_process = multiprocessing.Process(
|
||||||
|
target=httpd.serve_forever,
|
||||||
|
)
|
||||||
|
proxy_process.start()
|
||||||
|
yield 'http://{}:{}'.format(*httpd.server_address)
|
||||||
|
proxy_process.terminate()
|
||||||
|
|
||||||
|
|
||||||
|
def test_use_proxy(tmpdir, httpbin, proxy_server):
|
||||||
|
'''Ensure that it works with a proxy.'''
|
||||||
|
with vcr.use_cassette(str(tmpdir.join('proxy.yaml'))) as cass:
|
||||||
|
requests.get(httpbin.url, proxies={'http': proxy_server})
|
||||||
|
requests.get(httpbin.url, proxies={'http': proxy_server})
|
||||||
Reference in New Issue
Block a user