from http.server import BaseHTTPRequestHandler, HTTPServer
import paperdoorknob
-TEST_PORT = 8080
TIMEOUT = 8
class TestFetch(unittest.TestCase):
def setUp(self) -> None:
- web_server = HTTPServer(('', TEST_PORT), FakeGlowficHTTPRequestHandler)
+ web_server = HTTPServer(('', 0), FakeGlowficHTTPRequestHandler)
+ self._port = web_server.socket.getsockname()[1]
threading.Thread(target=web_server.serve_forever).start()
self._stop_server = web_server.shutdown
self._stop_server()
def testFetch(self) -> None:
- paperdoorknob.fetch(f"http://localhost:{TEST_PORT}", TIMEOUT)
+ paperdoorknob.fetch(f"http://localhost:{self._port}", TIMEOUT)
if __name__ == '__main__':