From 00b7c13dbdd38acd02f1e65e62a39a0e782451e5 Mon Sep 17 00:00:00 2001 From: Alexander Myasoedov Date: Tue, 17 Dec 2024 15:05:19 +0200 Subject: [PATCH] fix(tests): --- agentic_security/routes/test_probe.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/agentic_security/routes/test_probe.py b/agentic_security/routes/test_probe.py index 8c5fea6..8a3644b 100644 --- a/agentic_security/routes/test_probe.py +++ b/agentic_security/routes/test_probe.py @@ -1,5 +1,7 @@ +import base64 import io +import httpx import pytest from fastapi.testclient import TestClient @@ -184,7 +186,7 @@ def test_self_probe_image_endpoint(): {"type": "text", "text": "What is in this image?"}, { "type": "image_url", - "image_url": {"url": "data:image/jpeg;base64,mockbase64data"}, + "image_url": {"url": encode_image_base64_by_url()}, }, ], } @@ -207,3 +209,10 @@ def test_self_probe_image_endpoint(): assert "choices" in data assert len(data["choices"]) == 1 assert "message" in data["choices"][0] + + +def encode_image_base64_by_url(url: str = "https://github.com/fluidicon.png") -> str: + """Encode image data to base64 from a URL""" + response = httpx.get(url) + encoded_content = base64.b64encode(response.content).decode("utf-8") + return "data:image/jpeg;base64," + encoded_content