class PrerenderHostedTestMethods(TestCase):

    @override_settings(
        PRERENDER_RECACHE_URL="http://example.com/recache",
        PRERENDER_URL="http://example.com"
    )
    def setUp(self):
        self.backend = PrerenderHosted()

    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_get_response_for_giant_response(self):
        with HTTMock(mock_prerender_giant_response):
            resp = self.backend.get_response_for_url("http://www.example.com")
            self.assertEqual(MOCK_GIANT_RESPONSE, resp.content)

    def test_update_url_with_url(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_missing_url(self):
        with HTTMock(mock_prerender_recache_response):
            self.assertRaises(ValueError, self.backend.update_url)
示例#2
0
class PrerenderHostedTestMethods(TestCase):

    @override_settings(
        PRERENDER_RECACHE_URL="http://example.com/recache",
        PRERENDER_URL="http://example.com"
    )
    def setUp(self):
        self.backend = PrerenderHosted()

    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_get_response_for_giant_response(self):
        with HTTMock(mock_prerender_giant_response):
            resp = self.backend.get_response_for_url("http://www.example.com")
            self.assertEqual(MOCK_GIANT_RESPONSE, resp.content)

    def test_update_url_with_url(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_missing_url(self):
        with HTTMock(mock_prerender_recache_response):
            self.assertRaises(ValueError, self.backend.update_url)
示例#3
0
 def setUp(self):
     self.backend = PrerenderHosted()
示例#4
0
 def test_no_exception_if_both_are_provided(self):
     self.backend = PrerenderHosted()