summaryrefslogtreecommitdiffhomepage
path: root/test/test_settings.py
diff options
context:
space:
mode:
authorAndrei Belov <defan@nginx.com>2019-05-30 17:44:29 +0300
committerAndrei Belov <defan@nginx.com>2019-05-30 17:44:29 +0300
commit4921df052be8437d912f3c60faa9a667890e4498 (patch)
tree3678c551f148a0d177721597de978c090237f205 /test/test_settings.py
parent3b7a7ff2aa5840d4238584410ee1ebc6860fb9c5 (diff)
parent7da320a93af07765e79c929287704936c431f3cd (diff)
downloadunit-4921df052be8437d912f3c60faa9a667890e4498.tar.gz
unit-4921df052be8437d912f3c60faa9a667890e4498.tar.bz2
Merged with the default branch.1.9.0-1
Diffstat (limited to 'test/test_settings.py')
-rw-r--r--test/test_settings.py152
1 files changed, 103 insertions, 49 deletions
diff --git a/test/test_settings.py b/test/test_settings.py
index 13bfad49..98063440 100644
--- a/test/test_settings.py
+++ b/test/test_settings.py
@@ -1,47 +1,72 @@
import time
import socket
import unittest
-import unit
+from unit.applications.lang.python import TestApplicationPython
-class TestUnitSettings(unit.TestUnitApplicationPython):
- def setUpClass():
- unit.TestUnit().check_modules('python')
+class TestSettings(TestApplicationPython):
+ prerequisites = ['python']
def test_settings_header_read_timeout(self):
self.load('empty')
- self.conf({'http': { 'header_read_timeout': 2 }}, 'settings')
+ self.conf({'http': {'header_read_timeout': 2}}, 'settings')
- (resp, sock) = self.http(b"""GET / HTTP/1.1
-""", start=True, read_timeout=1, raw=True)
+ (resp, sock) = self.http(
+ b"""GET / HTTP/1.1
+""",
+ start=True,
+ read_timeout=1,
+ raw=True,
+ )
time.sleep(3)
- resp = self.http(b"""Host: localhost
+ resp = self.http(
+ b"""Host: localhost
Connection: close
-""", sock=sock, raw=True)
+""",
+ sock=sock,
+ raw=True,
+ )
self.assertEqual(resp['status'], 408, 'status header read timeout')
def test_settings_header_read_timeout_update(self):
self.load('empty')
- self.conf({'http': { 'header_read_timeout': 4 }}, 'settings')
+ self.conf({'http': {'header_read_timeout': 4}}, 'settings')
- (resp, sock) = self.http(b"""GET / HTTP/1.1
-""", start=True, read_timeout=1, raw=True, no_recv=True)
+ (resp, sock) = self.http(
+ b"""GET / HTTP/1.1
+""",
+ start=True,
+ raw=True,
+ no_recv=True,
+ )
time.sleep(2)
- (resp, sock) = self.http(b"""Host: localhost
-""", start=True, sock=sock, read_timeout=1, raw=True, no_recv=True)
+ (resp, sock) = self.http(
+ b"""Host: localhost
+""",
+ start=True,
+ sock=sock,
+ raw=True,
+ no_recv=True,
+ )
time.sleep(2)
- (resp, sock) = self.http(b"""X-Blah: blah
-""", start=True, sock=sock, read_timeout=1, raw=True)
+ (resp, sock) = self.http(
+ b"""X-Blah: blah
+""",
+ start=True,
+ sock=sock,
+ read_timeout=1,
+ raw=True,
+ )
if len(resp) != 0:
sock.close()
@@ -49,24 +74,35 @@ Connection: close
else:
time.sleep(2)
- resp = self.http(b"""Connection: close
+ resp = self.http(
+ b"""Connection: close
-""", sock=sock, raw=True)
+""",
+ sock=sock,
+ raw=True,
+ )
- self.assertEqual(resp['status'], 408,
- 'status header read timeout update')
+ self.assertEqual(
+ resp['status'], 408, 'status header read timeout update'
+ )
def test_settings_body_read_timeout(self):
self.load('empty')
- self.conf({'http': { 'body_read_timeout': 2 }}, 'settings')
+ self.conf({'http': {'body_read_timeout': 2}}, 'settings')
- (resp, sock) = self.http(b"""POST / HTTP/1.1
+ (resp, sock) = self.http(
+ b"""POST / HTTP/1.1
Host: localhost
Content-Length: 10
Connection: close
-""", start=True, raw_resp=True, read_timeout=1, raw=True)
+""",
+ start=True,
+ raw_resp=True,
+ read_timeout=1,
+ raw=True,
+ )
time.sleep(3)
@@ -77,37 +113,46 @@ Connection: close
def test_settings_body_read_timeout_update(self):
self.load('empty')
- self.conf({'http': { 'body_read_timeout': 4 }}, 'settings')
+ self.conf({'http': {'body_read_timeout': 4}}, 'settings')
- (resp, sock) = self.http(b"""POST / HTTP/1.1
+ (resp, sock) = self.http(
+ b"""POST / HTTP/1.1
Host: localhost
Content-Length: 10
Connection: close
-""", start=True, read_timeout=1, raw=True)
+""",
+ start=True,
+ read_timeout=1,
+ raw=True,
+ )
time.sleep(2)
- (resp, sock) = self.http(b"""012""", start=True, sock=sock,
- read_timeout=1, raw=True)
+ (resp, sock) = self.http(
+ b"""012""", start=True, sock=sock, read_timeout=1, raw=True
+ )
time.sleep(2)
- (resp, sock) = self.http(b"""345""", start=True, sock=sock,
- read_timeout=1, raw=True)
+ (resp, sock) = self.http(
+ b"""345""", start=True, sock=sock, read_timeout=1, raw=True
+ )
time.sleep(2)
resp = self.http(b"""6789""", sock=sock, raw=True)
- self.assertEqual(resp['status'], 200, 'status body read timeout update')
+ self.assertEqual(
+ resp['status'], 200, 'status body read timeout update'
+ )
def test_settings_send_timeout(self):
self.load('mirror')
data_len = 1048576
- self.conf({'http': { 'send_timeout': 1 }}, 'settings')
+ self.conf({'http': {'send_timeout': 1}}, 'settings')
addr = self.testdir + '/sock'
@@ -122,7 +167,9 @@ Content-Type: text/html
Content-Length: %d
Connection: close
-""" % data_len + ('X' * data_len)
+""" % data_len + (
+ 'X' * data_len
+ )
sock.sendall(req.encode())
@@ -140,35 +187,42 @@ Connection: close
def test_settings_idle_timeout(self):
self.load('empty')
- self.conf({'http': { 'idle_timeout': 2 }}, 'settings')
+ self.assertEqual(self.get()['status'], 200, 'init')
- (resp, sock) = self.get(headers={
- 'Host': 'localhost',
- 'Connection': 'keep-alive'
- }, start=True, read_timeout=1)
+ self.conf({'http': {'idle_timeout': 2}}, 'settings')
+
+ (resp, sock) = self.get(
+ headers={'Host': 'localhost', 'Connection': 'keep-alive'},
+ start=True,
+ read_timeout=1,
+ )
time.sleep(3)
- resp = self.get(headers={
- 'Host': 'localhost',
- 'Connection': 'close'
- }, sock=sock)
+ resp = self.get(
+ headers={'Host': 'localhost', 'Connection': 'close'}, sock=sock
+ )
self.assertEqual(resp['status'], 408, 'status idle timeout')
def test_settings_max_body_size(self):
self.load('empty')
- self.conf({'http': { 'max_body_size': 5 }}, 'settings')
+ self.conf({'http': {'max_body_size': 5}}, 'settings')
self.assertEqual(self.post(body='01234')['status'], 200, 'status size')
- self.assertEqual(self.post(body='012345')['status'], 413,
- 'status size max')
+ self.assertEqual(
+ self.post(body='012345')['status'], 413, 'status size max'
+ )
- @unittest.expectedFailure
+ @unittest.skip('not yet')
def test_settings_negative_value(self):
- self.assertIn('error', self.conf({'http': { 'max_body_size': -1 }},
- 'settings'), 'settings negative value')
+ self.assertIn(
+ 'error',
+ self.conf({'http': {'max_body_size': -1}}, 'settings'),
+ 'settings negative value',
+ )
+
if __name__ == '__main__':
- TestUnitSettings.main()
+ TestSettings.main()