File: test_http_client.py

package info (click to toggle)
python-wsgi-intercept 1.1.2-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 276 kB
  • sloc: python: 1,074; makefile: 205
file content (64 lines) | stat: -rw-r--r-- 2,136 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import py.test
from wsgi_intercept import http_client_intercept, WSGIAppError
from test import wsgi_app
from test.install import installer_class
try:
    import http.client as http_lib
except ImportError:
    import httplib as http_lib

HOST = 'some_hopefully_nonexistant_domain'

InstalledApp = installer_class(http_client_intercept)


def test_http():
    with InstalledApp(wsgi_app.simple_app, host=HOST, port=80) as app:
        http_client = http_lib.HTTPConnection(HOST)
        http_client.request('GET', '/')
        content = http_client.getresponse().read()
        http_client.close()
        assert content == b'WSGI intercept successful!\n'
        assert app.success()


def test_https():
    with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app:
        http_client = http_lib.HTTPSConnection(HOST)
        http_client.request('GET', '/')
        content = http_client.getresponse().read()
        http_client.close()
        assert content == b'WSGI intercept successful!\n'
        assert app.success()


def test_other():
    with InstalledApp(wsgi_app.simple_app, host=HOST, port=8080) as app:
        http_client = http_lib.HTTPConnection(HOST + ':8080')
        http_client.request('GET', '/')
        content = http_client.getresponse().read()
        http_client.close()
        assert content == b'WSGI intercept successful!\n'
        assert app.success()


def test_proxy_handling():
    """Proxy variable no impact."""
    with InstalledApp(wsgi_app.simple_app, host=HOST, port=80,
                      proxy='some.host:1234') as app:
        http_client = http_lib.HTTPConnection(HOST)
        http_client.request('GET', '/')
        content = http_client.getresponse().read()
        http_client.close()
        assert content == b'WSGI intercept successful!\n'
        assert app.success()


def test_app_error():
    with InstalledApp(wsgi_app.raises_app, host=HOST, port=80):
        http_client = http_lib.HTTPConnection(HOST)
        with py.test.raises(WSGIAppError):
            http_client.request('GET', '/')
            http_client.getresponse().read()
        http_client.close()