Kotta commited on
Commit ·
7bca2ed
1
Parent(s): 28af5bc
feature(#9): updated pytest cases with configuration setup.
Browse files
Brain/tests/conftest.py
CHANGED
|
@@ -2,10 +2,6 @@ import pytest
|
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.testclient import TestClient
|
| 4 |
|
| 5 |
-
from Brain.src.firebase.firebase import initialize_app
|
| 6 |
-
|
| 7 |
-
initialize_app()
|
| 8 |
-
|
| 9 |
|
| 10 |
@pytest.fixture(scope="module")
|
| 11 |
def test_client():
|
|
|
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.testclient import TestClient
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
@pytest.fixture(scope="module")
|
| 7 |
def test_client():
|
Brain/tests/functional/test_recipes.py
CHANGED
|
@@ -1,41 +1,63 @@
|
|
| 1 |
import re
|
| 2 |
|
|
|
|
| 3 |
from Brain.src.firebase.firebase import initialize_app
|
|
|
|
| 4 |
from Brain.src.rising_plugin.risingplugin import getCompletion, getTextFromImage
|
| 5 |
-
from Brain.src.firebase.cloudmessage import send_message
|
| 6 |
-
from Brain.src.firebase.cloudmessage import get_tokens
|
| 7 |
from Brain.src.rising_plugin.image_embedding import query_image_text
|
| 8 |
|
| 9 |
TEST_IAMGE_NAME = "0ddffe51-3763-48d9-ab74-2086de529217"
|
| 10 |
TEST_UUID = "TEST_UUID"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
def test_langchain():
|
| 14 |
error = "Error happened while analyzing your prompt. Please ask me again"
|
| 15 |
-
result = getCompletion(
|
|
|
|
|
|
|
| 16 |
print(result)
|
| 17 |
assert result != error
|
| 18 |
|
| 19 |
|
| 20 |
def test_image2text():
|
| 21 |
error = "Error happened while analyzing your prompt. Please ask me again"
|
| 22 |
-
result = getTextFromImage(TEST_IAMGE_NAME)
|
| 23 |
print(result)
|
| 24 |
assert result != error
|
| 25 |
|
| 26 |
|
| 27 |
def test_firebase_cloud_message():
|
| 28 |
-
|
|
|
|
| 29 |
notification = {"title": "alert", "content": "test"}
|
| 30 |
|
| 31 |
pattern = r"send to \d+ devices, with \d+ successed, with \d+ failed."
|
| 32 |
|
| 33 |
-
state, value = send_message(notification, token_list)
|
| 34 |
assert re.match(pattern, value)
|
| 35 |
|
| 36 |
|
| 37 |
def test_query_image_text():
|
| 38 |
error = "Error happened in querying image & text"
|
| 39 |
-
result = query_image_text(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
print(result)
|
| 41 |
assert result != error
|
|
|
|
| 1 |
import re
|
| 2 |
|
| 3 |
+
from Brain.src.firebase.cloudmessage import CloudMessage
|
| 4 |
from Brain.src.firebase.firebase import initialize_app
|
| 5 |
+
from Brain.src.model.req_model import ReqModel
|
| 6 |
from Brain.src.rising_plugin.risingplugin import getCompletion, getTextFromImage
|
|
|
|
|
|
|
| 7 |
from Brain.src.rising_plugin.image_embedding import query_image_text
|
| 8 |
|
| 9 |
TEST_IAMGE_NAME = "0ddffe51-3763-48d9-ab74-2086de529217"
|
| 10 |
TEST_UUID = "TEST_UUID"
|
| 11 |
+
test_setting = ReqModel(
|
| 12 |
+
data={
|
| 13 |
+
"token": "test-token",
|
| 14 |
+
"uuid": TEST_UUID,
|
| 15 |
+
"openai_key": "",
|
| 16 |
+
"pinecone_key": "",
|
| 17 |
+
"pinecone_env": "",
|
| 18 |
+
"firebase_key": "",
|
| 19 |
+
"settings": {"temperature": 0.6},
|
| 20 |
+
}
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
firebase_app = initialize_app(test_setting)
|
| 24 |
|
| 25 |
|
| 26 |
def test_langchain():
|
| 27 |
error = "Error happened while analyzing your prompt. Please ask me again"
|
| 28 |
+
result = getCompletion(
|
| 29 |
+
query="open three.js website", setting=test_setting, firebase_app=firebase_app
|
| 30 |
+
)
|
| 31 |
print(result)
|
| 32 |
assert result != error
|
| 33 |
|
| 34 |
|
| 35 |
def test_image2text():
|
| 36 |
error = "Error happened while analyzing your prompt. Please ask me again"
|
| 37 |
+
result = getTextFromImage(filename=TEST_IAMGE_NAME, firebase_app=firebase_app)
|
| 38 |
print(result)
|
| 39 |
assert result != error
|
| 40 |
|
| 41 |
|
| 42 |
def test_firebase_cloud_message():
|
| 43 |
+
cloud_message = CloudMessage(firebase_app=firebase_app)
|
| 44 |
+
token_list = cloud_message.get_tokens()
|
| 45 |
notification = {"title": "alert", "content": "test"}
|
| 46 |
|
| 47 |
pattern = r"send to \d+ devices, with \d+ successed, with \d+ failed."
|
| 48 |
|
| 49 |
+
state, value = cloud_message.send_message(notification, token_list)
|
| 50 |
assert re.match(pattern, value)
|
| 51 |
|
| 52 |
|
| 53 |
def test_query_image_text():
|
| 54 |
error = "Error happened in querying image & text"
|
| 55 |
+
result = query_image_text(
|
| 56 |
+
image_content=getTextFromImage(
|
| 57 |
+
filename=TEST_IAMGE_NAME, firebase_app=firebase_app
|
| 58 |
+
),
|
| 59 |
+
message="",
|
| 60 |
+
setting=test_setting,
|
| 61 |
+
)
|
| 62 |
print(result)
|
| 63 |
assert result != error
|