PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/tests/web/test_conn.py

https://bitbucket.org/prologic/circuits/
Python | 29 lines | 20 code | 8 blank | 1 comment | 2 complexity | 5b08a46e305ff93f2ae6b8082cda4557 MD5 | raw file
 1#!/usr/bin/env python
 2
 3try:
 4    from httplib import HTTPConnection
 5except ImportError:
 6    from http.client import HTTPConnection  # NOQA
 7
 8from circuits.web import Controller
 9
10
11class Root(Controller):
12    def index(self):
13        return "Hello World!"
14
15
16def test(webapp):
17    connection = HTTPConnection(webapp.server.host, webapp.server.port)
18    connection.auto_open = False
19    connection.connect()
20
21    for i in range(2):
22        connection.request("GET", "/")
23        response = connection.getresponse()
24        assert response.status == 200
25        assert response.reason == "OK"
26        s = response.read()
27        assert s == b"Hello World!"
28
29    connection.close()