{ pkgs ? import <nixpkgs> { }, lint ? false }:
pkgs.python3Packages.callPackage ({ lib, buildPythonPackage, autopep8, mypy
- , pylint, requests, requests-cache, types-requests, xdg-base-dirs }:
+ , pylint, beautifulsoup4, requests, requests-cache, types-beautifulsoup4
+ , types-requests, xdg-base-dirs }:
buildPythonPackage rec {
pname = "paperdoorknob";
version = "0.0.1";
src = lib.cleanSource ./.;
- propagatedBuildInputs = [ requests requests-cache xdg-base-dirs ];
- nativeCheckInputs = [ mypy types-requests ]
+ propagatedBuildInputs =
+ [ beautifulsoup4 requests requests-cache xdg-base-dirs ];
+ nativeCheckInputs = [ mypy types-beautifulsoup4 types-requests ]
++ lib.optionals lint [ autopep8 pylint ];
doCheck = true;
checkPhase = "./test.sh";
from argparse import ArgumentParser
import os.path
+from bs4 import BeautifulSoup
import requests
import requests_cache
from xdg_base_dirs import xdg_cache_home
return parser
-def fetch(url: str, session: requests.Session, timeout: int) -> None:
+def fetch(url: str, session: requests.Session, timeout: int) -> BeautifulSoup:
with session.get(url, timeout=timeout) as r:
r.raise_for_status()
+ return BeautifulSoup(r.text, 'html.parser')
def main() -> None:
paperdoorknob.fetch(f"http://localhost:{self._port()}", s, TIMEOUT)
self.assertEqual(self._request_counter, 1)
+ def testFetchConents(self) -> None:
+ with requests.session() as s:
+ doc = paperdoorknob.fetch(
+ f"http://localhost:{self._port()}", s, TIMEOUT)
+ body = doc.body
+ assert body
+ self.assertEqual(body.text, "This is glowfic")
+
def testFetchErrors(self) -> None:
with requests.session() as s:
with self.assertRaises(requests.HTTPError):