- def testFetch(self) -> None:
- with requests.session() as s:
- paperdoorknob.fetch(f"http://localhost:{self._port}", s, TIMEOUT)
- self.assertEqual(self._server.request_count(), 1)
- paperdoorknob.fetch(f"http://localhost:{self._port}", s, TIMEOUT)
- self.assertEqual(self._server.request_count(), 2)
-
- def testFetchCaching(self) -> None:
- with requests_cache.CachedSession() as s:
- paperdoorknob.fetch(f"http://localhost:{self._port}", s, TIMEOUT)
- self.assertEqual(self._server.request_count(), 1)
- paperdoorknob.fetch(f"http://localhost:{self._port}", s, TIMEOUT)
- self.assertEqual(self._server.request_count(), 1)
-
- def testFetchPersistentCaching(self) -> None:
- with requests_cache.CachedSession() as s:
- paperdoorknob.fetch(f"http://localhost:{self._port}", s, TIMEOUT)
- self.assertEqual(self._server.request_count(), 1)
- with requests_cache.CachedSession() as s:
- paperdoorknob.fetch(f"http://localhost:{self._port}", s, TIMEOUT)
- self.assertEqual(self._server.request_count(), 1)
-
- def testReplies(self) -> None:
- with requests.session() as s:
- replies = paperdoorknob.replies(
- paperdoorknob.clean(
- paperdoorknob.fetch(
- f"http://localhost:{self._port}",
- s,
- TIMEOUT)))
- self.assertEqual([r.text.strip() for r in replies],
- ["This is glowfic", "You sure?", "Pretty sure."])
-
- def testFetchErrors(self) -> None:
- with requests.session() as s:
- with self.assertRaises(requests.HTTPError):
- paperdoorknob.fetch(
- f"http://localhost:{self._port}/not_found", s, TIMEOUT)
- with self.assertRaises(requests.HTTPError):
- paperdoorknob.fetch(
- f"http://localhost:{self._port}/server_error", s, TIMEOUT)