Ejemplo n.º 1
0
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)
Ejemplo n.º 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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
class PrerenderIOTestToken(TestCase):
    @override_settings(PRERENDER_TOKEN=None)
    def test_get_token_throws_exception_if_missing(self):
        self.assertRaises(ValueError, PrerenderIO)

    @override_settings(PRERENDER_TOKEN="123124341adfsaf")
    def test_get_token(self):
        self.backend = PrerenderIO()
        # Test function
        self.assertEqual(self.backend._get_token(), "123124341adfsaf")
        # Test __init__
        self.assertEqual(self.backend.token, "123124341adfsaf")
Ejemplo n.º 6
0
 def setUp(self):
     self.backend = PrerenderIO()
Ejemplo n.º 7
0
 def test_get_token(self):
     self.backend = PrerenderIO()
     # Test function
     self.assertEqual(self.backend._get_token(), "123124341adfsaf")
     # Test __init__
     self.assertEqual(self.backend.token, "123124341adfsaf")
Ejemplo n.º 8
0
 def test_timeout_setting(self):
     self.backend = PrerenderIO()
     self.assertEqual(self.backend._request_kwargs({}), {'timeout': 5})
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
 def test_timeout_setting(self):
     self.backend = PrerenderIO()
     self.assertEqual(self.backend._request_kwargs({}), {'timeout': 5})