From 19363fd4b5c9748dc9ce523a51f9cb81b369ee02 Mon Sep 17 00:00:00 2001 From: Iurii Rudyk Date: Mon, 15 Apr 2024 15:29:02 +0300 Subject: [PATCH] issue-4952 fix --- .../sample_http_test_integration.py | 39 ++++--------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/functions/helloworld/sample_http_test_integration.py b/functions/helloworld/sample_http_test_integration.py index 6e25bfa6820..8139d74a871 100644 --- a/functions/helloworld/sample_http_test_integration.py +++ b/functions/helloworld/sample_http_test_integration.py @@ -14,42 +14,19 @@ # [START functions_http_integration_test] import os -import subprocess import uuid -import requests -from requests.packages.urllib3.util.retry import Retry +from functions_framework import create_app def test_args(): name = str(uuid.uuid4()) - port = os.getenv( - "PORT", 8080 - ) # Each functions framework instance needs a unique port - - process = subprocess.Popen( - ["functions-framework", "--target", "hello_http", "--port", str(port)], - cwd=os.path.dirname(__file__), - stdout=subprocess.PIPE, - ) - - # Send HTTP request simulating Pub/Sub message - # (GCF translates Pub/Sub messages to HTTP requests internally) - BASE_URL = f"http://localhost:{port}" - - retry_policy = Retry(total=6, backoff_factor=1) - retry_adapter = requests.adapters.HTTPAdapter(max_retries=retry_policy) - - session = requests.Session() - session.mount(BASE_URL, retry_adapter) - - name = str(uuid.uuid4()) - res = session.post(BASE_URL, json={"name": name}) - assert res.text == f"Hello {name}!" - - # Stop the functions framework process - process.kill() - process.wait() - + target = "hello_http" + source = os.path.join(os.path.dirname(__file__), "main.py") + client = create_app(target, source).test_client() + resp = client.post("/my_path", json={"name": name}) + assert resp.status_code == 200 + expected_response = f"Hello {name}!" + assert resp.data.decode("utf-8") == expected_response # [END functions_http_integration_test]