class PrerenderIOTestMethods(TestCase):
    def setUp(self):
        self.backend = PrerenderIO()

    def test_get_response_for_url_missing_url(self):
        self.assertRaises(TypeError, self.backend.get_response_for_url)
        self.assertRaises(ValueError, self.backend.get_response_for_url, None)

    def test_get_response_for_url_valid(self):
        with HTTMock(mock_prerender_response):
            resp = self.backend.get_response_for_url("http://www.example.com")
            self.assertEqual(MOCK_RESPONSE, resp.content)
            for k, v in MOCK_RESPONSE_HEADERS.items():
                self.assertEqual(resp[k], v)

    def test_update_url_with_url_only(self):
        with HTTMock(mock_prerender_recache_response):
            resp = self.backend.update_url(url="http://www.example.com")
            self.assertEqual(resp, True)

    def test_update_url_with_regex_only(self):
        with HTTMock(mock_prerender_recache_response):
            resp = self.backend.update_url(regex="http://www.example.com/*")
            self.assertEqual(resp, True)

    def test_update_url_missing_url_and_regex(self):
        with HTTMock(mock_prerender_recache_response):
            self.assertRaises(ValueError, self.backend.update_url)
示例#2
0
class PrerenderTimeout(TestCase):
    @override_settings(PRERENDER_TIMEOUT=5)
    def test_timeout_setting(self):
        self.backend = PrerenderIO()
        self.assertEqual(self.backend._request_kwargs({}), {'timeout': 5})

    @override_settings(PRERENDER_TIMEOUT=5)
    def test_timeout_response(self):
        self.backend = PrerenderIO()
        self.backend.session.get = MagicMock(
            side_effect=requests.exceptions.Timeout())
        resp = self.backend.get_response_for_url("http://www.example.com")
        self.assertEqual(resp.status_code, 408)
class PrerenderTimeout(TestCase):

    @override_settings(PRERENDER_TIMEOUT=5)
    def test_timeout_setting(self):
        self.backend = PrerenderIO()
        self.assertEqual(self.backend._request_kwargs({}), {'timeout': 5})

    @override_settings(PRERENDER_TIMEOUT=5)
    def test_timeout_response(self):
        self.backend = PrerenderIO()
        self.backend.session.get = MagicMock(
            side_effect=requests.exceptions.Timeout()
        )
        resp = self.backend.get_response_for_url("http://www.example.com")
        self.assertEqual(resp.status_code, 408)