Felipe97/llama-cpp-compiled
01.2k
1import pytest2from utils import *3import threading4from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer5 6server = ServerPreset.tinyllama2()7 8 9@pytest.fixture(autouse=True)10def create_server():11 global server12 server = ServerPreset.tinyllama2()13 14 15def test_mcp_no_proxy():16 global server17 server.ui_mcp_proxy = False18 server.start()19 20 res = server.make_request("GET", "/cors-proxy")21 assert res.status_code == 40322 23 24def test_mcp_proxy():25 global server26 server.ui_mcp_proxy = True27 server.start()28 29 url = f"http://{server.server_host}:{server.server_port}/cors-proxy?url=http://example.com"30 res = requests.get(url)31 assert res.status_code == 20032 assert "Example Domain" in res.text33 34 35def test_mcp_proxy_custom_port():36 global server37 server.ui_mcp_proxy = True38 server.start()39 40 # try getting the server's models API via the proxy41 res = server.make_request("GET", f"/cors-proxy?url=http://{server.server_host}:{server.server_port}/models")42 assert res.status_code == 20043 assert "data" in res.body44 45 46def test_mcp_proxy_no_content():47 # note: see issue #2659848 class NoContentHandler(BaseHTTPRequestHandler):49 def do_POST(self):50 self.send_response(204)51 self.end_headers()52 53 def log_message(self, format, *args):54 pass55 56 target = ThreadingHTTPServer(("127.0.0.1", 0), NoContentHandler)57 target_thread = threading.Thread(target=target.serve_forever, daemon=True)58 target_thread.start()59 60 try:61 global server62 server.ui_mcp_proxy = True63 server.start()64 65 res = server.make_request("POST", f"/cors-proxy?url=http://127.0.0.1:{target.server_port}/", data={})66 assert res.status_code == 20467 assert res.body in (None, b"", "")68 finally:69 target.shutdown()70 target.server_close()71 72 