test_static.py (1247:9bb7f9cfe39c) test_static.py (1368:b08ca65c6cda)
1import os
2import socket
3import unittest
4from unit.applications.proto import TestApplicationProto
5
6
7class TestStatic(TestApplicationProto):
8 prerequisites = {}

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

34 }
35 )
36
37 def test_static_index(self):
38 self.assertEqual(
39 self.get(url='/index.html')['body'], '0123456789', 'index'
40 )
41 self.assertEqual(self.get(url='/')['body'], '0123456789', 'index 2')
1import os
2import socket
3import unittest
4from unit.applications.proto import TestApplicationProto
5
6
7class TestStatic(TestApplicationProto):
8 prerequisites = {}

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

34 }
35 )
36
37 def test_static_index(self):
38 self.assertEqual(
39 self.get(url='/index.html')['body'], '0123456789', 'index'
40 )
41 self.assertEqual(self.get(url='/')['body'], '0123456789', 'index 2')
42 self.assertEqual(self.get(url='//')['body'], '0123456789', 'index 3')
43 self.assertEqual(self.get(url='/.')['body'], '0123456789', 'index 4')
44 self.assertEqual(self.get(url='/./')['body'], '0123456789', 'index 5')
42 self.assertEqual(
43 self.get(url='/?blah')['body'], '0123456789', 'index vars'
44 )
45 self.assertEqual(
46 self.get(url='/#blah')['body'], '0123456789', 'index anchor'
47 )
48 self.assertEqual(
49 self.get(url='/dir/')['status'], 404, 'index not found'

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

194
195 self.assertEqual(self.get(url='/dir')['status'], 301, 'dir')
196 self.assertEqual(self.get(url='/dir/file')['status'], 200, 'file')
197 self.assertEqual(self.get(url='/link')['status'], 301, 'symlink dir')
198 self.assertEqual(
199 self.get(url='/link/file')['status'], 200, 'symlink file'
200 )
201
45 self.assertEqual(
46 self.get(url='/?blah')['body'], '0123456789', 'index vars'
47 )
48 self.assertEqual(
49 self.get(url='/#blah')['body'], '0123456789', 'index anchor'
50 )
51 self.assertEqual(
52 self.get(url='/dir/')['status'], 404, 'index not found'

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

197
198 self.assertEqual(self.get(url='/dir')['status'], 301, 'dir')
199 self.assertEqual(self.get(url='/dir/file')['status'], 200, 'file')
200 self.assertEqual(self.get(url='/link')['status'], 301, 'symlink dir')
201 self.assertEqual(
202 self.get(url='/link/file')['status'], 200, 'symlink file'
203 )
204
202 def test_static_head(self):
203 resp = self.head(url='/')
204 self.assertEqual(resp['status'], 200, 'status')
205 self.assertEqual(resp['body'], '', 'empty body')
205 def test_static_method(self):
206 resp = self.head()
207 self.assertEqual(resp['status'], 200, 'HEAD status')
208 self.assertEqual(resp['body'], '', 'HEAD empty body')
206
209
210 self.assertEqual(self.delete()['status'], 405, 'DELETE')
211 self.assertEqual(self.post()['status'], 405, 'POST')
212 self.assertEqual(self.put()['status'], 405, 'PUT')
213
214 def test_static_path(self):
215 self.assertEqual(
216 self.get(url='/dir/../dir/file')['status'], 200, 'relative'
217 )
218
219 self.assertEqual(self.get(url='./')['status'], 400, 'path invalid')
220 self.assertEqual(self.get(url='../')['status'], 400, 'path invalid 2')
221 self.assertEqual(self.get(url='/..')['status'], 400, 'path invalid 3')
222 self.assertEqual(
223 self.get(url='../assets/')['status'], 400, 'path invalid 4'
224 )
225 self.assertEqual(
226 self.get(url='/../assets/')['status'], 400, 'path invalid 5'
227 )
228
207 def test_static_two_clients(self):
208 _, sock = self.get(url='/', start=True, no_recv=True)
209 _, sock2 = self.get(url='/', start=True, no_recv=True)
210
211 self.assertEqual(sock.recv(1), b'H', 'client 1')
212 self.assertEqual(sock2.recv(1), b'H', 'client 2')
213 self.assertEqual(sock.recv(1), b'T', 'client 1 again')
214 self.assertEqual(sock2.recv(1), b'T', 'client 2 again')

--- 192 unchanged lines hidden ---
229 def test_static_two_clients(self):
230 _, sock = self.get(url='/', start=True, no_recv=True)
231 _, sock2 = self.get(url='/', start=True, no_recv=True)
232
233 self.assertEqual(sock.recv(1), b'H', 'client 1')
234 self.assertEqual(sock2.recv(1), b'H', 'client 2')
235 self.assertEqual(sock.recv(1), b'T', 'client 1 again')
236 self.assertEqual(sock2.recv(1), b'T', 'client 2 again')

--- 192 unchanged lines hidden ---