+# paperdoorknob: Print glowfic
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3.
+
+
+import unittest
+import threading
+from http.server import BaseHTTPRequestHandler, HTTPServer
+import paperdoorknob
+
+TEST_PORT = 8080
+TIMEOUT = 8
+
+
+class FakeGlowficHTTPRequestHandler(BaseHTTPRequestHandler):
+
+ def do_GET(self) -> None:
+ body = b'<html><body>This is glowfic</body></html>'
+ self.send_response(200)
+ self.send_header("Content-type", "text/html")
+ self.send_header("Content-Length", str(len(body)))
+ self.end_headers()
+ self.wfile.write(body)
+
+
+class TestFetch(unittest.TestCase):
+ def setUp(self) -> None:
+ web_server = HTTPServer(('', TEST_PORT), FakeGlowficHTTPRequestHandler)
+ threading.Thread(target=web_server.serve_forever).start()
+ self._stop_server = web_server.shutdown
+
+ def tearDown(self) -> None:
+ self._stop_server()
+
+ def testFetch(self) -> None:
+ paperdoorknob.fetch(f"http://localhost:{TEST_PORT}", TIMEOUT)
+
+
+if __name__ == '__main__':
+ unittest.main()