File size: 1,200 Bytes
809d184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os, sys
sys.path.append("../")
from main import app

from fastapi.testclient import TestClient

from settings import datadir

client = TestClient(app)

def test_read_root():
    response = client.get("/ping/")
    assert response.status_code == 200
    assert int(response.json()['answer']) < 100
    
def test_list_files():
    response = client.get("/list_files/")
    files = os.listdir(datadir)
    assert response.status_code == 200
    assert len(response.json()['files']) == len(files)
    for f in response.json()['files']:
        assert f in files
        
def test_vector_search():
    question_data = {"question": "Does ATT have postpaid phone customers?"}
    response = client.post("/ask/", json=question_data)
    assert response.status_code == 200
    assert len(response.json()['answer']) > 0 # we assume vector store works if it returns something
    assert any(['postpaid' in a.lower() for a in response.json()['answer']])
    

def test_ragit():
    question_data = {"question": "Does ATT have postpaid phone customers?"}
    response = client.post("/ragit/", json=question_data)
    assert response.status_code == 200
    assert 'yes' in response.json()['answer'].lower()