From 600213e01025186c81a1653a18d04b6a20db0789 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 29 Jan 2026 11:34:28 +0000 Subject: [PATCH] Initial commit: Add http-convert project --- tests/test_web.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/test_web.py diff --git a/tests/test_web.py b/tests/test_web.py new file mode 100644 index 0000000..b34f211 --- /dev/null +++ b/tests/test_web.py @@ -0,0 +1,71 @@ +import pytest +from fastapi.testclient import TestClient +from src.http_convert.web import app + + +@pytest.fixture +def client(): + return TestClient(app) + + +class TestWebAPI: + def test_root(self, client): + response = client.get("/") + assert response.status_code == 200 + assert "HTTP Convert" in response.text + + def test_convert_endpoint(self, client): + response = client.post("/api/convert", json={ + "method": "GET", + "url": "https://api.example.com/users", + "headers": {"Accept": "application/json"}, + "format": "curl" + }) + assert response.status_code == 200 + assert "curl" in response.json()["result"] + + def test_convert_with_body(self, client): + response = client.post("/api/convert", json={ + "method": "POST", + "url": "https://api.example.com/users", + "headers": {"Content-Type": "application/json"}, + "body": '{"name": "John"}', + "format": "fetch" + }) + assert response.status_code == 200 + assert "fetch" in response.json()["result"] + + def test_parse_endpoint(self, client): + response = client.post("/api/parse", json={ + "input": "curl 'https://api.example.com/users'", + "format": "curl" + }) + assert response.status_code == 200 + data = response.json() + assert data["method"] == "GET" + assert data["url"] == "https://api.example.com/users" + + def test_parse_invalid_input(self, client): + response = client.post("/api/parse", json={ + "input": "not a valid curl command", + "format": "curl" + }) + assert response.status_code == 400 + + def test_get_formats(self, client): + response = client.get("/api/formats") + assert response.status_code == 200 + data = response.json() + assert "curl" in data["formats"] + assert "httpie" in data["formats"] + assert "fetch" in data["formats"] + assert "axios" in data["formats"] + + def test_convert_all_formats(self, client): + for fmt in ["curl", "httpie", "fetch", "axios"]: + response = client.post("/api/convert", json={ + "method": "GET", + "url": "https://api.example.com", + "format": fmt + }) + assert response.status_code == 200, f"Failed for format: {fmt}"