MCPcopy
hub / github.com/cherrypy/cherrypy / _test_iterator

Method _test_iterator

cherrypy/test/test_iterator.py:109–196  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

107 'Test fails intermittently. See #1419'
108
109 def _test_iterator(self):
110 if cherrypy.server.protocol_version != 'HTTP/1.1':
111 return self.skip()
112
113 self.PROTOCOL = 'HTTP/1.1'
114
115 # Check the counts of all the classes, they should be zero.
116 closables = ['OurClosableIterator', 'OurGenerator']
117 unclosables = ['OurUnclosableIterator', 'OurNotClosableIterator']
118 all_classes = closables + unclosables
119
120 import random
121 random.shuffle(all_classes)
122
123 for clsname in all_classes:
124 self.getPage('/count/' + clsname)
125 self.assertStatus(200)
126 self.assertBody('0')
127
128 # We should also be able to read the entire content body
129 # successfully, though we don't need to, we just want to
130 # check the header.
131 for clsname in all_classes:
132 itr_conn = self.get_conn()
133 itr_conn.putrequest('GET', '/getall/' + clsname)
134 itr_conn.endheaders()
135 response = itr_conn.getresponse()
136 self.assertEqual(response.status, 200)
137 headers = response.getheaders()
138 for header_name, header_value in headers:
139 if header_name.lower() == 'content-length':
140 expected = str(1024 * 16 * 256)
141 assert header_value == expected, header_value
142 break
143 else:
144 raise AssertionError('No Content-Length header found')
145
146 # As the response should be fully consumed by CherryPy
147 # before sending back, the count should still be at zero
148 # by the time the response has been sent.
149 self.getPage('/count/' + clsname)
150 self.assertStatus(200)
151 self.assertBody('0')
152
153 itr_conn.close()
154
155 # Now we do the same check with streaming - some classes will
156 # be automatically closed, while others cannot.
157 stream_counts = {}
158 for clsname in all_classes:
159 itr_conn = self.get_conn()
160 itr_conn.putrequest('GET', '/stream/' + clsname)
161 itr_conn.endheaders()
162 response = itr_conn.getresponse()
163 self.assertEqual(response.status, 200)
164 response.fp.read(65536)
165
166 # Let's check the count - this should always be one.

Callers 1

test_iteratorMethod · 0.95

Calls 4

skipMethod · 0.80
getPageMethod · 0.80
closeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected