|
32 | 32 | from common.utils.auth_service import validate_token
|
33 | 33 | from common.testing.firestore_emulator import firestore_emulator, clean_firestore
|
34 | 34 |
|
35 |
| -with mock.patch( |
36 |
| - "google.cloud.secretmanager.SecretManagerServiceClient"): |
| 35 | +os.environ["FIRESTORE_EMULATOR_HOST"] = "localhost:8080" |
| 36 | +os.environ["PROJECT_ID"] = "fake-project" |
| 37 | +os.environ["OPENAI_API_KEY"] = "fake-key" |
| 38 | +os.environ["COHERE_API_KEY"] = "fake-key" |
| 39 | + |
| 40 | +with mock.patch("google.cloud.secretmanager.SecretManagerServiceClient"): |
37 | 41 | with mock.patch("langchain.chat_models.ChatOpenAI", new=mock.AsyncMock()):
|
38 | 42 | with mock.patch("langchain.llms.Cohere", new=mock.AsyncMock()):
|
39 | 43 | from config import LLM_TYPES
|
40 | 44 |
|
41 | 45 | # assigning url
|
42 | 46 | api_url = f"{API_URL}/chat"
|
43 | 47 |
|
44 |
| -os.environ["FIRESTORE_EMULATOR_HOST"] = "localhost:8080" |
45 |
| -os.environ["GOOGLE_CLOUD_PROJECT"] = "fake-project" |
46 |
| -os.environ["OPENAI_API_KEY"] = "fake-key" |
47 |
| -os.environ["COHERE_API_KEY"] = "fake-key" |
48 |
| - |
49 |
| -with mock.patch( |
50 |
| - "google.cloud.secretmanager.SecretManagerServiceClient"): |
| 48 | +with mock.patch("google.cloud.secretmanager.SecretManagerServiceClient"): |
51 | 49 | from routes.chat import router
|
52 | 50 |
|
53 | 51 | app = FastAPI()
|
@@ -91,12 +89,14 @@ def create_user(client_with_emulator):
|
91 | 89 | user = User.from_dict(user_dict)
|
92 | 90 | user.save()
|
93 | 91 |
|
| 92 | + |
94 | 93 | @pytest.fixture
|
95 | 94 | def create_chat(client_with_emulator):
|
96 | 95 | chat_dict = CHAT_EXAMPLE
|
97 | 96 | chat = UserChat.from_dict(chat_dict)
|
98 | 97 | chat.save()
|
99 | 98 |
|
| 99 | + |
100 | 100 | def test_get_chats(create_user, create_chat, client_with_emulator):
|
101 | 101 | params = {"skip": 0, "limit": "30"}
|
102 | 102 | url = f"{api_url}"
|
@@ -139,7 +139,7 @@ def test_create_chat(create_user, client_with_emulator):
|
139 | 139 | "returned chat data generated text"
|
140 | 140 |
|
141 | 141 | user_chats = UserChat.find_by_user(userid)
|
142 |
| - assert len(user_chats) == 1, "retreieved new user chat" |
| 142 | + assert len(user_chats) == 1, "retrieved new user chat" |
143 | 143 | user_chat = user_chats[0]
|
144 | 144 | assert user_chat.history[0] == \
|
145 | 145 | {CHAT_HUMAN: FAKE_GENERATE_PARAMS["prompt"]}, \
|
@@ -187,7 +187,7 @@ def test_chat_generate(create_chat, client_with_emulator):
|
187 | 187 | url = f"{api_url}/{chatid}/generate"
|
188 | 188 |
|
189 | 189 | with mock.patch("routes.chat.llm_chat",
|
190 |
| - return_value = FAKE_GENERATE_RESPONSE): |
| 190 | + return_value=FAKE_GENERATE_RESPONSE): |
191 | 191 | resp = client_with_emulator.post(url, json=FAKE_GENERATE_PARAMS)
|
192 | 192 |
|
193 | 193 | json_response = resp.json()
|
|
0 commit comments