Commit 9b9a9ab1 authored by Denis Bilenko's avatar Denis Bilenko

remove some unnecessary tests

parent 6049ae43
...@@ -222,27 +222,19 @@ class TestCase(greentest.TestCase): ...@@ -222,27 +222,19 @@ class TestCase(greentest.TestCase):
return socket.create_connection(('127.0.0.1', self.port)) return socket.create_connection(('127.0.0.1', self.port))
class TestHttpdBasic(TestCase): class CommonTests(TestCase):
@staticmethod def test_basic(self):
def application(env, start_response): fd = self.connect().makefile(bufsize=1)
path = env['PATH_INFO'] fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
if path == '/': read_http(fd, body='hello world')
start_response('200 OK', [('Content-Type', 'text/plain')]) fd.write('GET /notexist HTTP/1.1\r\nHost: localhost\r\n\r\n')
return ["hello world"] read_http(fd, code=404, reason='Not Found', body='not found')
else: fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
start_response('404 Not Found', [('Content-Type', 'text/plain')]) read_http(fd, body='hello world')
return ["not found"] fd.close()
def test_001_server(self):
sock = self.connect()
sock.sendall('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
result = sock.makefile().read()
sock.close()
self.assert_(result.startswith('HTTP/1.1 200 OK\r\n'), result)
self.assert_(result.endswith('hello world'), result)
def SKIP_test_002_pipeline(self): def XXXtest_pipeline(self):
fd = self.connect().makefile(bufsize=1) fd = self.connect().makefile(bufsize=1)
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n' + 'GET /notexist HTTP/1.1\r\nHost: localhost\r\n\r\n') fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n' + 'GET /notexist HTTP/1.1\r\nHost: localhost\r\n\r\n')
read_http(fd, body='hello world') read_http(fd, body='hello world')
...@@ -254,16 +246,7 @@ class TestHttpdBasic(TestCase): ...@@ -254,16 +246,7 @@ class TestHttpdBasic(TestCase):
finally: finally:
timeout.cancel() timeout.cancel()
def test_003_passing_non_int_to_read(self): def test_connection_close(self):
# This should go in greenio_test
fd = self.connect().makefile(bufsize=1)
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
cancel = gevent.Timeout.start_new(1, RuntimeError)
self.assertRaises(TypeError, fd.read, "This shouldn't work")
cancel.cancel()
fd.close()
def test_004_connection_close(self):
fd = self.connect().makefile(bufsize=1) fd = self.connect().makefile(bufsize=1)
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n') fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
read_http(fd) read_http(fd)
...@@ -290,39 +273,53 @@ class TestHttpdBasic(TestCase): ...@@ -290,39 +273,53 @@ class TestHttpdBasic(TestCase):
self.assertEqual(status, '414') self.assertEqual(status, '414')
fd.close() fd.close()
def test_008_correctresponse(self):
class TestNoChunks(CommonTests):
# when returning a list of strings a shortcut is employed by the server:
# it calculates the content-length and joins all the chunks before sending
validator = None
@staticmethod
def application(env, start_response):
path = env['PATH_INFO']
if path == '/':
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['hello ', 'world']
else:
start_response('404 Not Found', [('Content-Type', 'text/plain')])
return ['not ', 'found']
def test(self):
fd = self.connect().makefile(bufsize=1) fd = self.connect().makefile(bufsize=1)
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n') fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
read_http(fd) response = read_http(fd, body='hello world')
fd.write('GET /notexist HTTP/1.1\r\nHost: localhost\r\n\r\n') assert response.chunks is None, response.chunks
read_http(fd, code=404, reason='Not Found') response.assertHeader('Content-Length', '11')
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
read_http(fd)
fd.close()
fd.write('GET /not-found HTTP/1.1\r\nHost: localhost\r\n\r\n')
response = read_http(fd, code=404, reason='Not Found', body='not found')
assert response.chunks is None, response.chunks
response.assertHeader('Content-Length', '9')
class TestExplicitContentLength(TestHttpdBasic):
class TestExplicitContentLength(TestNoChunks):
# when returning a list of strings a shortcut is empoyed by the server - it caculates the content-length
@staticmethod @staticmethod
def application(env, start_response): def application(env, start_response):
path = env['PATH_INFO'] path = env['PATH_INFO']
if path == '/': if path == '/':
msg = 'hello world' start_response('200 OK', [('Content-Type', 'text/plain'), ('Content-Length', '11')])
start_response('200 OK', return ['hello ', 'world']
[('Content-Type', 'text/plain'),
('Content-Length', str(len(msg)))])
else: else:
msg = 'not found' start_response('404 Not Found', [('Content-Type', 'text/plain'), ('Content-Length', '9')])
start_response('404 Not Found', return ['not ', 'found']
[('Content-Type', 'text/plain'),
('Content-Length', str(len(msg)))])
return [msg]
class TestYield(TestHttpdBasic): class TestYield(CommonTests):
@staticmethod @staticmethod
def hello_world_yield(env, start_response): def application(env, start_response):
path = env['PATH_INFO'] path = env['PATH_INFO']
if path == '/': if path == '/':
start_response('200 OK', [('Content-Type', 'text/plain')]) start_response('200 OK', [('Content-Type', 'text/plain')])
...@@ -617,6 +614,7 @@ class HTTPRequest(urllib2.Request): ...@@ -617,6 +614,7 @@ class HTTPRequest(urllib2.Request):
def get_method(self): def get_method(self):
return self.method return self.method
del CommonTests
if __name__ == '__main__': if __name__ == '__main__':
greentest.main() greentest.main()
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