def test_server_method_request(self, method, http_server): """Test making HTTP requests to the server directly using requests.""" text = str(uuid.uuid4()) res = http.HTTPResponse(content=[text]) http_server.queue_response(res) method_request = getattr(requests, method) url = "http://{}:{}/".format(http_server.host, http_server.port) r = method_request(url) assert requests.codes.ok == r.status_code assert "text/plain" == r.headers["content-type"] assert text == r.text.strip("\n")
def test_client_method_request(self, method, http_server, http_client): """Test making HTTP requests from client to server objects.""" method_request = getattr(http_client, method) method_request("random/text") text = str(uuid.uuid4()) res = http.HTTPResponse(content=[text]) http_server.queue_response(res) r = http_client.receive() assert requests.codes.ok == r.status_code assert "text/plain" == r.headers["content-type"] assert text == r.text.strip("\n")
def test_wait_for_response(self, http_server, http_client): """Test waiting for a response from the server.""" # Send HTTP request http_client.get("random/text") # Send response wait = 0.2 time.sleep(wait) text = str(uuid.uuid4()) res = http.HTTPResponse(content=[text]) http_server.respond(res) # Receive response r = http_client.receive() # Verify response assert requests.codes.ok == r.status_code assert "text/plain" == r.headers["Content-type"] assert text == r.text