diff --git a/recipes/req/recipe.yaml b/recipes/req/recipe.yaml index 44a44a3b..cbdbda1b 100644 --- a/recipes/req/recipe.yaml +++ b/recipes/req/recipe.yaml @@ -1,5 +1,5 @@ context: - version: "0.1.0" + version: "0.2.0" mojo_version: "==1.1.0" package: @@ -8,7 +8,7 @@ package: source: - git: https://github.com/mojoto/req.mojo.git - rev: c46152a5d77adf17b85ebb40fe90106a0522e0ee # v0.1.0 + rev: 40d245911d3e681dfb7e837d4a097d0f2ce58af9 # 0.2.0 preparation source; no release tag - git: https://github.com/ehsanmok/json.git rev: 0bae1f3815d249efa6cb0a3483eb6658700635e5 # v0.4.1 target_directory: vendor/json @@ -56,15 +56,20 @@ tests: interpreter: bash content: | set -euo pipefail - mojo build --Werror test.mojo -o test-req + mojo build --Werror tests/package.mojo -o test-req python test.py files: recipe: - - test.mojo - test.py + source: + - tests/package.mojo + - tests/conftest.py + - tests/transports/http2_server.py requirements: run: - python >=3.12 + - h2 >=4.3,<5 + - openssl about: homepage: https://github.com/mojoto/req.mojo @@ -77,8 +82,9 @@ about: - vendor/json/NOTICE summary: A synchronous HTTP client for Mojo. description: | - Send HTTP/1.1 requests with JSON, forms, authentication, cookies, - connection reuse, streaming, timeouts, and TLS verification. + Send HTTP/1.1 and opt-in HTTP/2 requests with JSON, multipart and file + uploads, HTTP/HTTPS proxies, connection pool limits, hooks, injectable + transports, response iterators, and verified TLS. Includes the native shared library and the CPU source modules from ehsanmok/json 0.4.1. The native transport loads automatically from the active environment; consumers need no extra linker flags. diff --git a/recipes/req/test.mojo b/recipes/req/test.mojo deleted file mode 100644 index adca1414..00000000 --- a/recipes/req/test.mojo +++ /dev/null @@ -1,25 +0,0 @@ -import req -from std.os import getenv -from std.testing import assert_equal, assert_true - - -def main() raises: - var url = getenv("REQ_PACKAGE_TEST_URL") - var response = req.get(url) - response.raise_for_status() - assert_equal(response.status_code, 200) - assert_equal(response.json()["value"].int_value(), 42) - assert_true(response.text().byte_length() > 0) - - var client = req.Client(base_url=url + "/", timeout=req.Timeout(5.0)) - var first = client.get("first") - first.raise_for_status() - assert_equal(first.json()["value"].int_value(), 42) - var payload = req.JSONValue.object() - payload.set("name", req.JSONValue("Mojo")) - var posted = client.post("post", json=payload) - posted.raise_for_status() - assert_equal(posted.json()["name"].string_value(), "Mojo") - client.close() - - print("Req installed-package HTTP and JSON tests passed") diff --git a/recipes/req/test.py b/recipes/req/test.py index ce9238cc..2bf75aed 100644 --- a/recipes/req/test.py +++ b/recipes/req/test.py @@ -1,43 +1,24 @@ +"""Exercise the installed package using the source release smoke test.""" + import os +from pathlib import Path import subprocess -import threading -from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer - - -class Handler(BaseHTTPRequestHandler): - protocol_version = "HTTP/1.1" - - def respond(self, body): - self.send_response(200) - self.send_header("Content-Type", "application/json") - self.send_header("Content-Length", str(len(body))) - self.end_headers() - self.wfile.write(body) - - def do_GET(self): - self.respond(b'{"value":42}') - - def do_POST(self): - self.respond(self.rfile.read(int(self.headers["Content-Length"]))) - - def log_message(self, *_): - pass - - -with ThreadingHTTPServer(("127.0.0.1", 0), Handler) as server: - worker = threading.Thread(target=server.serve_forever, daemon=True) - worker.start() - try: - for command in [["mojo", "run", "--Werror", "test.mojo"], ["./test-req"]]: - subprocess.run( - command, - env={ - **os.environ, - "REQ_PACKAGE_TEST_URL": f"http://127.0.0.1:{server.server_port}", - }, - check=True, - timeout=120, - ) - finally: - server.shutdown() - worker.join() +import sys + +sys.path.insert(0, str(Path("tests").resolve())) +from conftest import Fixtures # noqa: E402 + + +with Fixtures() as fixtures: + env = dict(os.environ, **fixtures.environment) + for name in ( + "REQ_NATIVE_LIB", + "REQ_EXPECT_LOAD_ERROR", + "REQ_EXPECT_HTTP2_UNAVAILABLE", + ): + env.pop(name, None) + for command in [ + ["mojo", "run", "--Werror", "tests/package.mojo"], + ["./test-req"], + ]: + subprocess.run(command, env=env, check=True, timeout=120)