{ pkgs ? import <nixpkgs> { }, lint ? false }:
-pkgs.python3Packages.callPackage
-({ lib, buildPythonPackage, autopep8, mypy, pylint, requests, types-requests }:
+pkgs.python3Packages.callPackage ({ lib, buildPythonPackage, autopep8, mypy
+ , pylint, requests, requests-cache, types-requests }:
buildPythonPackage rec {
pname = "paperdoorknob";
version = "0.0.1";
src = lib.cleanSource ./.;
- propagatedBuildInputs = [ requests ];
+ propagatedBuildInputs = [ requests requests-cache ];
nativeCheckInputs = [ mypy types-requests ]
++ lib.optionals lint [ autopep8 pylint ];
doCheck = true;
from argparse import ArgumentParser
import requests
+import requests_cache
def command_line_parser() -> ArgumentParser:
def main() -> None:
args = command_line_parser().parse_args()
- with requests.session() as session:
+ with requests_cache.CachedSession() as session:
fetch(args.url, session, args.timeout)
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer
import requests
+import requests_cache
import paperdoorknob
TIMEOUT = 8
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 testFetchErrors(self) -> None:
with requests.session() as s:
with self.assertRaises(requests.HTTPError):