aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_server.py
blob: 50f1afe868cc64c303ac01e01002dce7f011fb1a (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
import urllib, urllib2
import tutils

class uSanity(tutils.ProxTest):
    def test_http(self):
        """
            Just check that the HTTP server is running.
        """
        f = urllib.urlopen("http://127.0.0.1:%s"%tutils.HTTP_PORT, proxies={})
        assert f.read()

    def test_https(self):
        """
            Just check that the HTTPS server is running.
        """
        f = urllib.urlopen("https://127.0.0.1:%s"%tutils.HTTPS_PORT, proxies={})
        assert f.read()


class uProxy(tutils.ProxTest):
    HOST = "127.0.0.1"
    def _get(self, host=HOST):
        proxy_support = urllib2.ProxyHandler(
                            {"http" : "http://127.0.0.1:%s"%tutils.PROXL_PORT}
                        )
        opener = urllib2.build_opener(proxy_support)
        r = urllib2.Request("http://%s:%s"%(host, tutils.HTTP_PORT))
        return opener.open(r)

    def _sget(self, host=HOST):
        proxy_support = urllib2.ProxyHandler(
                            {"https" : "https://127.0.0.1:%s"%tutils.PROXL_PORT}
                        )
        opener = urllib2.build_opener(proxy_support)
        r = urllib2.Request("https://%s:%s"%(host, tutils.HTTPS_PORT))
        return opener.open(r)

    def test_http(self):
        f = self._get()
        assert f.code == 200
        assert f.read()
        f.close()

        l = self.log()
        assert l[0].address
        assert "host" in l[1].headers
        assert l[2].code == 200

    def test_https(self):
        f = self._sget()
        assert f.code == 200
        assert f.read()
        f.close()

        l = self.log()
        assert l[0].address
        assert "host" in l[1].headers
        assert l[2].code == 200

    # Disable these two for now: they take a long time.
    def _test_http_nonexistent(self):
        f = self._get("nonexistent")
        assert f.code == 200
        assert "Error" in f.read()

    def _test_https_nonexistent(self):
        f = self._sget("nonexistent")
        assert f.code == 200
        assert "Error" in f.read()


tests = [
    tutils.TestServers(), [
        uSanity(),
        uProxy(),
    ]
]