| 181 | file.remove_p() |
| 182 | |
| 183 | def test_static(self): |
| 184 | self.getPage('/static/index.html') |
| 185 | self.assertStatus('200 OK') |
| 186 | self.assertHeader('Content-Type', 'text/html') |
| 187 | self.assertBody('Hello, world\r\n') |
| 188 | |
| 189 | # Using a staticdir.root value in a subdir... |
| 190 | self.getPage('/docroot/index.html') |
| 191 | self.assertStatus('200 OK') |
| 192 | self.assertHeader('Content-Type', 'text/html') |
| 193 | self.assertBody('Hello, world\r\n') |
| 194 | |
| 195 | # Check a filename with spaces in it |
| 196 | self.getPage('/static/has%20space.html') |
| 197 | self.assertStatus('200 OK') |
| 198 | self.assertHeader('Content-Type', 'text/html') |
| 199 | self.assertBody('Hello, world\r\n') |
| 200 | |
| 201 | self.getPage('/style.css') |
| 202 | self.assertStatus('200 OK') |
| 203 | self.assertHeader('Content-Type', 'text/css') |
| 204 | # Note: The body should be exactly 'Dummy stylesheet\n', but |
| 205 | # unfortunately some tools such as WinZip sometimes turn \n |
| 206 | # into \r\n on Windows when extracting the CherryPy tarball so |
| 207 | # we just check the content |
| 208 | self.assertMatchesBody('^Dummy stylesheet') |
| 209 | |
| 210 | # Check a filename with utf-8 characters in it |
| 211 | ascii_fn = 'has_utf-8_character_.html' |
| 212 | url_quote_fn = 'has_utf-8_character_%E2%98%83.html' # %E2%98%83 == ☃ |
| 213 | expected_content_disposition = ( |
| 214 | 'attachment; filename="{!s}"; filename*=UTF-8\'\'{!s}'. |
| 215 | format(ascii_fn, url_quote_fn) |
| 216 | ) |
| 217 | |
| 218 | self.getPage('/serve_file_utf8_filename') |
| 219 | self.assertStatus('200 OK') |
| 220 | self.assertHeader('Content-Disposition', expected_content_disposition) |
| 221 | |
| 222 | self.getPage('/serve_fileobj_utf8_filename') |
| 223 | self.assertStatus('200 OK') |
| 224 | self.assertHeader('Content-Disposition', expected_content_disposition) |
| 225 | |
| 226 | @pytest.mark.skipif(platform.system() != 'Windows', reason='Windows only') |
| 227 | def test_static_longpath(self): |