import os import unittest from six.moves.urllib.parse import urlparse from scrapy.http import Response, TextResponse, HtmlResponse from scrapy.utils.response import response_httprepr, open_in_browser, get_meta_refresh __doctests__ = ['scrapy.utils.response'] class ResponseUtilsTest(unittest.TestCase): dummy_response = TextResponse(url='http://example.org/', body='dummy_response') def test_response_httprepr(self): r1 = Response("http://www.example.com") self.assertEqual(response_httprepr(r1), 'HTTP/1.1 200 OK\r\n\r\n') r1 = Response("http://www.example.com", status=404, headers={"Content-type": "text/html"}, body="Some body") self.assertEqual(response_httprepr(r1), 'HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\n\r\nSome body') r1 = Response("http://www.example.com", status=6666, headers={"Content-type": "text/html"}, body="Some body") self.assertEqual(response_httprepr(r1), 'HTTP/1.1 6666 \r\nContent-Type: text/html\r\n\r\nSome body') def test_open_in_browser(self): url = "http:///www.example.com/some/page.html" body = "