|
3 | 3 | from six.moves.urllib.parse import urlparse
|
4 | 4 |
|
5 | 5 | from scrapy.http import Response, TextResponse, HtmlResponse
|
6 |
| -from scrapy.utils.response import response_httprepr, open_in_browser, get_meta_refresh |
| 6 | +from scrapy.utils.response import (response_httprepr, open_in_browser, |
| 7 | + get_meta_refresh, get_base_url, response_status_message) |
7 | 8 |
|
8 | 9 | __doctests__ = ['scrapy.utils.response']
|
9 | 10 |
|
@@ -61,5 +62,23 @@ def test_get_meta_refresh(self):
|
61 | 62 | self.assertEqual(get_meta_refresh(r2), (None, None))
|
62 | 63 | self.assertEqual(get_meta_refresh(r3), (None, None))
|
63 | 64 |
|
| 65 | + def test_get_base_url(self): |
| 66 | + resp = HtmlResponse("http://www.example.com", body=b""" |
| 67 | + <html> |
| 68 | + <head><base href="http://www.example.com/img/" target="_blank"></head> |
| 69 | + <body>blahablsdfsal&</body> |
| 70 | + </html>""") |
| 71 | + self.assertEqual(get_base_url(resp), "http://www.example.com/img/") |
| 72 | + |
| 73 | + resp2 = HtmlResponse("http://www.example.com", body=b""" |
| 74 | + <html><body>blahablsdfsal&</body></html>""") |
| 75 | + self.assertEqual(get_base_url(resp2), "http://www.example.com") |
| 76 | + |
| 77 | + def test_response_status_message(self): |
| 78 | + self.assertEqual(response_status_message(200), '200 OK') |
| 79 | + self.assertEqual(response_status_message(404), '404 Not Found') |
| 80 | + self.assertEqual(response_status_message(573), "573 Unknown Status") |
| 81 | + |
| 82 | + |
64 | 83 | if __name__ == "__main__":
|
65 | 84 | unittest.main()
|
0 commit comments