source: trunk/server/common/oursrc/scripts-static-cat/test.py @ 1900

Last change on this file since 1900 was 1900, checked in by cberzan, 11 years ago
static-cat: add support for multiple ranges Also added the skeleton for a unit test. The test does not work yet, but the included test cases are useful.
  • Property svn:executable set to *
File size: 4.2 KB
Line 
1#!/usr/bin/python
2
3from subprocess import Popen, PIPE
4
5
6# Make test.html in this directory available at this url:
7URL = "http://cberzan.scripts.mit.edu/static-cat.cgi/test.html"
8
9
10def test_all():
11    truth =\
12r"""HTTP/1.1 200 OK
13Date: Sun, 12 Jun 2011 02:59:36 GMT
14Server: Apache
15Last-Modified: Sat, 11 Jun 2011 21:55:23 GMT
16ETag: "823818c-2c6-4a576be3968c0"
17Accept-Ranges: bytes
18Content-Length: 710
19Vary: Accept-Encoding
20Content-Type: text/html
21
22Sunt autem quidam e nostris, qui haec subtilius velint tradere et negent satis esse, quid bonum sit aut quid malum, sensu iudicari, sed animo etiam ac ratione intellegi posse et voluptatem ipsam per se esse expetendam et dolorem ipsum per se esse fugiendum. itaque aiunt hanc quasi naturalem atque insitam in animis nostris inesse notionem, ut alterum esse appetendum, alterum aspernandum sentiamus. Alii autem, quibus ego assentior, cum a philosophis compluribus permulta dicantur, cur nec voluptas in bonis sit numeranda nec in malis dolor, non existimant oportere nimium nos causae confidere, sed et argumentandum et accurate disserendum et rationibus conquisitis de voluptate et dolore disputandum putant."""
23    p = Popen(["curl", URL, "-s", "-D", "-"], stdout=PIPE)
24    result = p.communicate()[0]
25    print "TODO finish test..."
26    # LEFT TODO: use mimeheaders or something (http://stackoverflow.com/questions/4685217/parse-raw-http-headers)
27    # to parse headers and make sure they're OK; compare content and make sure it matches byte-for-byte.
28
29
30def test_one_range():
31    truth =\
32r"""HTTP/1.1 206 Partial Content
33Date: Sun, 12 Jun 2011 03:05:41 GMT
34Server: Apache
35Last-Modified: Sat, 11 Jun 2011 21:55:23 GMT
36ETag: "823818c-2c6-4a576be3968c0"
37Accept-Ranges: bytes
38Content-Length: 101
39Vary: Accept-Encoding
40Content-Range: bytes 100-200/710
41Content-Type: text/html
42
43aut quid malum, sensu iudicari, sed animo etiam ac ratione intellegi posse et voluptatem ipsam per se"""
44    p = Popen(["curl", "-r", "100-200", URL, "-s", "-D", "-"], stdout=PIPE)
45    result = p.communicate()[0]
46    print "TODO finish test..."
47    # LEFT TODO: see above
48
49
50def test_overlapping_ranges():
51    truth =\
52r"""HTTP/1.1 206 Partial Content
53Date: Sun, 12 Jun 2011 03:07:02 GMT
54Server: Apache
55Last-Modified: Sat, 11 Jun 2011 21:55:23 GMT
56ETag: "823818c-2c6-4a576be3968c0"
57Accept-Ranges: bytes
58Content-Length: 395
59Vary: Accept-Encoding
60Content-Type: multipart/byteranges; boundary=4a57b18cf808c49ff
61
62
63--4a57b18cf808c49ff
64Content-type: text/html
65Content-range: bytes 100-200/710
66
67aut quid malum, sensu iudicari, sed animo etiam ac ratione intellegi posse et voluptatem ipsam per se
68--4a57b18cf808c49ff
69Content-type: text/html
70Content-range: bytes 150-250/710
71
72 ratione intellegi posse et voluptatem ipsam per se esse expetendam et dolorem ipsum per se esse fugi
73 --4a57b18cf808c49ff--
74"""
75    p = Popen(["curl", "-r", "100-200,150-250", URL, "-s", "-D", "-"], stdout=PIPE)
76    result = p.communicate()[0]
77    print "TODO finish test..."
78    # LEFT TODO: see above, with the additional complication that the separating string varies.
79
80
81def test_nonoverlapping_ranges():
82    truth =\
83r"""HTTP/1.1 206 Partial Content
84Date: Sun, 12 Jun 2011 03:08:19 GMT
85Server: Apache
86Last-Modified: Sat, 11 Jun 2011 21:55:23 GMT
87ETag: "823818c-2c6-4a576be3968c0"
88Accept-Ranges: bytes
89Content-Length: 429
90Vary: Accept-Encoding
91Content-Type: multipart/byteranges; boundary=4a57b1d5f1d8949fd
92
93
94--4a57b1d5f1d8949fd
95Content-type: text/html
96Content-range: bytes 50-100/710
97
98lint tradere et negent satis esse, quid bonum sit a
99--4a57b1d5f1d8949fd
100Content-type: text/html
101Content-range: bytes 150-200/710
102
103 ratione intellegi posse et voluptatem ipsam per se
104 --4a57b1d5f1d8949fd
105 Content-type: text/html
106 Content-range: bytes 250-300/710
107
108 iendum. itaque aiunt hanc quasi naturalem atque ins
109 --4a57b1d5f1d8949fd--
110"""
111    p = Popen(["curl", "-r", "50-100,150-200,250-300", URL, "-s", "-D", "-"], stdout=PIPE)
112    result = p.communicate()[0]
113    print "TODO finish test..."
114    # LEFT TODO: see above, with the additional complication that the separating string varies.
115
116
117if __name__ == "__main__":
118    print "Unfinished tests! Read the source."
119    test_all()
120    test_one_range()
121    test_overlapping_ranges()
122    test_nonoverlapping_ranges()
123    print "Test passed."
Note: See TracBrowser for help on using the repository browser.