Commit ca51288f authored by Denis Bilenko's avatar Denis Bilenko

test__httpd.py: update not to use a specific port

parent 684f07cc
...@@ -32,13 +32,11 @@ import urllib2 ...@@ -32,13 +32,11 @@ import urllib2
import BaseHTTPServer import BaseHTTPServer
from gevent import spawn, kill from gevent import spawn, kill
port = 18341
def start_http_server(): def start_http_server():
server_address = ('', port) server_address = ('', 0)
BaseHTTPServer.BaseHTTPRequestHandler.protocol_version = "HTTP/1.0" BaseHTTPServer.BaseHTTPRequestHandler.protocol_version = "HTTP/1.0"
httpd = BaseHTTPServer.HTTPServer(server_address, BaseHTTPServer.BaseHTTPRequestHandler) httpd = BaseHTTPServer.HTTPServer(server_address, BaseHTTPServer.BaseHTTPRequestHandler)
sa = httpd.socket.getsockname() #sa = httpd.socket.getsockname()[1]
#print "Serving HTTP on", sa[0], "port", sa[1], "..." #print "Serving HTTP on", sa[0], "port", sa[1], "..."
httpd.request_count = 0 httpd.request_count = 0
def serve(): def serve():
...@@ -49,21 +47,21 @@ def start_http_server(): ...@@ -49,21 +47,21 @@ def start_http_server():
class TestGreenness(greentest.TestCase): class TestGreenness(greentest.TestCase):
def setUp(self): def setUp(self):
self.gthread, self.server = start_http_server() self.gthread, self.httpd = start_http_server()
#print 'Spawned the server'
def tearDown(self): def tearDown(self):
self.server.server_close() self.httpd.server_close()
kill(self.gthread) kill(self.gthread)
def test_urllib2(self): def test_urllib2(self):
self.assertEqual(self.server.request_count, 0) self.assertEqual(self.httpd.request_count, 0)
port = self.httpd.socket.getsockname()[1]
try: try:
urllib2.urlopen('http://127.0.0.1:%s' % port) urllib2.urlopen('http://127.0.0.1:%s' % port)
assert False, 'should not get there' assert False, 'should not get there'
except urllib2.HTTPError, ex: except urllib2.HTTPError, ex:
assert ex.code == 501, `ex` assert ex.code == 501, `ex`
self.assertEqual(self.server.request_count, 1) self.assertEqual(self.httpd.request_count, 1)
if __name__ == '__main__': if __name__ == '__main__':
test_support.run_unittest(TestGreenness) test_support.run_unittest(TestGreenness)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment