File size: 1,588 Bytes
fa81843
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pytest
from fastapi.testclient import TestClient
from inferroute.main import app

client = TestClient(app)

def test_plugin_summarize_mock():
    # Test text summarization in mock mode
    response = client.post(
        "/v1/plugins/summarize",
        data={"text": "This is a long test text that we want to summarize using our smart router.", "max_length": 150},
        headers={"Authorization": "Bearer sk-inferroute-demo"}
    )
    assert response.status_code == 200
    data = response.json()
    assert data["success"] is True
    assert data["plugin"] == "summarize"
    assert "summary" in data

def test_plugin_translate_mock():
    # Test translation in mock mode
    response = client.post(
        "/v1/plugins/translate",
        data={"text": "Hello world", "target_lang": "Chinese"},
        headers={"Authorization": "Bearer sk-inferroute-demo"}
    )
    assert response.status_code == 200
    data = response.json()
    assert data["success"] is True
    assert data["plugin"] == "translate"
    assert "translated_text" in data

def test_plugin_ocr_mock():
    # Test OCR plugin with a mock file upload
    import io
    file_data = b"fake-image-bytes"
    response = client.post(
        "/v1/plugins/ocr",
        files={"image": ("test.png", io.BytesIO(file_data), "image/png")},
        data={"language": "auto"},
        headers={"Authorization": "Bearer sk-inferroute-demo"}
    )
    assert response.status_code == 200
    data = response.json()
    assert data["success"] is True
    assert data["plugin"] == "ocr"
    assert "extracted_text" in data