test_php_application.py (894:c79252edf26f) test_php_application.py (970:2f4376c8f358)
1import unittest
2import unit
3import re
4
5class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
6
7 def setUpClass():
8 unit.TestUnit().check_modules('php')

--- 5 unchanged lines hidden (view full) ---

14 def test_php_application_variables(self):
15 self.load('variables')
16
17 body = 'Test body string.'
18
19 resp = self.post(headers={
20 'Host': 'localhost',
21 'Content-Type': 'text/html',
1import unittest
2import unit
3import re
4
5class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
6
7 def setUpClass():
8 unit.TestUnit().check_modules('php')

--- 5 unchanged lines hidden (view full) ---

14 def test_php_application_variables(self):
15 self.load('variables')
16
17 body = 'Test body string.'
18
19 resp = self.post(headers={
20 'Host': 'localhost',
21 'Content-Type': 'text/html',
22 'Custom-Header': 'blah'
22 'Custom-Header': 'blah',
23 'Connection': 'close'
23 }, body=body)
24
25 self.assertEqual(resp['status'], 200, 'status')
26 headers = resp['headers']
27 header_server = headers.pop('Server')
28 self.assertRegex(header_server, r'Unit/[\d\.]+', 'server header')
29 self.assertEqual(headers.pop('Server-Software'), header_server,
30 'server software header')
31
32 date = headers.pop('Date')
33 self.assertEqual(date[-4:], ' GMT', 'date header timezone')
34 self.assertLess(abs(self.date_to_sec_epoch(date) - self.sec_epoch()), 5,
35 'date header')
36
37 if 'X-Powered-By' in headers:
38 headers.pop('X-Powered-By')
39
40 headers.pop('Content-type')
41 self.assertDictEqual(headers, {
24 }, body=body)
25
26 self.assertEqual(resp['status'], 200, 'status')
27 headers = resp['headers']
28 header_server = headers.pop('Server')
29 self.assertRegex(header_server, r'Unit/[\d\.]+', 'server header')
30 self.assertEqual(headers.pop('Server-Software'), header_server,
31 'server software header')
32
33 date = headers.pop('Date')
34 self.assertEqual(date[-4:], ' GMT', 'date header timezone')
35 self.assertLess(abs(self.date_to_sec_epoch(date) - self.sec_epoch()), 5,
36 'date header')
37
38 if 'X-Powered-By' in headers:
39 headers.pop('X-Powered-By')
40
41 headers.pop('Content-type')
42 self.assertDictEqual(headers, {
43 'Connection': 'close',
42 'Content-Length': str(len(body)),
43 'Request-Method': 'POST',
44 'Request-Uri': '/',
45 'Http-Host': 'localhost',
46 'Server-Protocol': 'HTTP/1.1',
47 'Custom-Header': 'blah'
48 }, 'headers')
49 self.assertEqual(resp['body'], body, 'body')

--- 41 unchanged lines hidden (view full) ---

91 self.assertEqual(resp['status'], 404, '404 status')
92 self.assertRegex(resp['body'], r'<title>404 Not Found</title>',
93 '404 body')
94
95 def test_php_application_keepalive_body(self):
96 self.load('mirror')
97
98 (resp, sock) = self.post(headers={
44 'Content-Length': str(len(body)),
45 'Request-Method': 'POST',
46 'Request-Uri': '/',
47 'Http-Host': 'localhost',
48 'Server-Protocol': 'HTTP/1.1',
49 'Custom-Header': 'blah'
50 }, 'headers')
51 self.assertEqual(resp['body'], body, 'body')

--- 41 unchanged lines hidden (view full) ---

93 self.assertEqual(resp['status'], 404, '404 status')
94 self.assertRegex(resp['body'], r'<title>404 Not Found</title>',
95 '404 body')
96
97 def test_php_application_keepalive_body(self):
98 self.load('mirror')
99
100 (resp, sock) = self.post(headers={
101 'Host': 'localhost',
99 'Connection': 'keep-alive',
102 'Connection': 'keep-alive',
100 'Content-Type': 'text/html',
101 'Host': 'localhost'
103 'Content-Type': 'text/html'
102 }, start=True, body='0123456789' * 500)
103
104 self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')
105
106 resp = self.post(headers={
104 }, start=True, body='0123456789' * 500)
105
106 self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')
107
108 resp = self.post(headers={
109 'Host': 'localhost',
107 'Connection': 'close',
110 'Connection': 'close',
108 'Content-Type': 'text/html',
109 'Host': 'localhost'
111 'Content-Type': 'text/html'
110 }, sock=sock, body='0123456789')
111
112 self.assertEqual(resp['body'], '0123456789', 'keep-alive 2')
113
114 def test_php_application_conditional(self):
115 self.load('conditional')
116
117 self.assertRegex(self.get()['body'], r'True', 'conditional true')

--- 228 unchanged lines hidden ---
112 }, sock=sock, body='0123456789')
113
114 self.assertEqual(resp['body'], '0123456789', 'keep-alive 2')
115
116 def test_php_application_conditional(self):
117 self.load('conditional')
118
119 self.assertRegex(self.get()['body'], r'True', 'conditional true')

--- 228 unchanged lines hidden ---