From e5053cd32269ce9122ab7643e112e21518005b63 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Thu, 22 Oct 2015 12:20:29 +0100 Subject: [PATCH] Define some httpbin fixtures. --- test_requests.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/test_requests.py b/test_requests.py index 7b23e594..456dfe42 100755 --- a/test_requests.py +++ b/test_requests.py @@ -48,18 +48,31 @@ else: return s.decode('unicode-escape') +@pytest.fixture +def httpbin(httpbin): + # Issue #1483: Make sure the URL always has a trailing slash + httpbin_url = httpbin.url.rstrip('/') + '/' + + def inner(*suffix): + return urljoin(httpbin_url, '/'.join(suffix)) + + return inner + + +@pytest.fixture +def httpsbin_url(httpbin_secure): + # Issue #1483: Make sure the URL always has a trailing slash + httpbin_url = httpbin_secure.url.rstrip('/') + '/' + + def inner(*suffix): + return urljoin(httpbin_url, '/'.join(suffix)) + + return inner + + # Requests to this URL should always fail with a connection timeout (nothing # listening on that port) TARPIT = "http://10.255.255.1" -HTTPBIN = os.environ.get('HTTPBIN_URL', 'http://httpbin.org/') -# Issue #1483: Make sure the URL always has a trailing slash -HTTPBIN = HTTPBIN.rstrip('/') + '/' - - -def httpbin(*suffix): - """Returns url for HTTPBIN resource.""" - return urljoin(HTTPBIN, '/'.join(suffix)) - class RequestsTestCase(unittest.TestCase):