]> git.scottworley.com Git - paperdoorknob/blobdiff - paperdoorknob_test.py
fetch: Honor Cache-Control headers
[paperdoorknob] / paperdoorknob_test.py
index 88897f4cd64937639ff723a5ae3432ab27caedbe..cb70ac56dd214d26988a86e915aea762cb74008b 100644 (file)
@@ -9,6 +9,7 @@ import unittest
 import threading
 from http.server import BaseHTTPRequestHandler, HTTPServer
 import requests
+import requests_cache
 import paperdoorknob
 
 TIMEOUT = 8
@@ -65,6 +66,21 @@ class TestFetch(unittest.TestCase):
             paperdoorknob.fetch(f"http://localhost:{self._port()}", s, TIMEOUT)
             self.assertEqual(self._request_counter, 2)
 
+    def testFetchCaching(self) -> None:
+        with requests_cache.CachedSession() as s:
+            paperdoorknob.fetch(f"http://localhost:{self._port()}", s, TIMEOUT)
+            self.assertEqual(self._request_counter, 1)
+            paperdoorknob.fetch(f"http://localhost:{self._port()}", s, TIMEOUT)
+            self.assertEqual(self._request_counter, 1)
+
+    def testFetchPersistentCaching(self) -> None:
+        with requests_cache.CachedSession() as s:
+            paperdoorknob.fetch(f"http://localhost:{self._port()}", s, TIMEOUT)
+            self.assertEqual(self._request_counter, 1)
+        with requests_cache.CachedSession() as s:
+            paperdoorknob.fetch(f"http://localhost:{self._port()}", s, TIMEOUT)
+            self.assertEqual(self._request_counter, 1)
+
     def testFetchErrors(self) -> None:
         with requests.session() as s:
             with self.assertRaises(requests.HTTPError):