Skip to content

Commit f0513cb

Browse files
committed
Fix to run new automation api tests in ci
1 parent c144aa9 commit f0513cb

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,6 @@ jobs:
9292
POSTGRES_USER: postgres
9393
POSTGRES_PASSWORD: postgres
9494
POSTGRES_DB: postgres
95+
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
9596
run: pytest
9697
timeout-minutes: 10

tests/test_api_automation.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from fastapi.testclient import TestClient
55

66
from khoj.utils import state
7-
from tests.helpers import ChatModelFactory
7+
from tests.helpers import AiModelApiFactory, ChatModelFactory, get_chat_api_key
88

99

1010
@pytest.fixture(autouse=True)
@@ -19,7 +19,9 @@ def setup_scheduler():
1919
def create_test_automation(client: TestClient) -> str:
2020
"""Helper function to create a test automation and return its ID."""
2121
state.anonymous_mode = True
22-
ChatModelFactory(name="gpt-4o-mini", model_type="openai")
22+
ChatModelFactory(
23+
name="gemini-2.0-flash", model_type="google", ai_model_api=AiModelApiFactory(api_key=get_chat_api_key("google"))
24+
)
2325
params = {
2426
"q": "test automation",
2527
"crontime": "0 0 * * *",
@@ -34,7 +36,9 @@ def test_create_automation(client: TestClient):
3436
"""Test that creating an automation works as expected."""
3537
# Arrange
3638
state.anonymous_mode = True
37-
ChatModelFactory(name="gpt-4o-mini", model_type="openai")
39+
ChatModelFactory(
40+
name="gemini-2.0-flash", model_type="google", ai_model_api=AiModelApiFactory(api_key=get_chat_api_key("google"))
41+
)
3842
params = {
3943
"q": "test automation",
4044
"crontime": "0 0 * * *",
@@ -51,6 +55,7 @@ def test_create_automation(client: TestClient):
5155

5256

5357
@pytest.mark.django_db(transaction=True)
58+
@pytest.mark.skipif(get_chat_api_key("google") is None, reason="Requires GEMINI_API_KEY to be set")
5459
def test_get_automations(client: TestClient):
5560
"""Test that getting a list of automations works."""
5661
automation_id = create_test_automation(client)
@@ -67,6 +72,7 @@ def test_get_automations(client: TestClient):
6772

6873

6974
@pytest.mark.django_db(transaction=True)
75+
@pytest.mark.skipif(get_chat_api_key("google") is None, reason="Requires GEMINI_API_KEY to be set")
7076
def test_delete_automation(client: TestClient):
7177
"""Test that deleting an automation works."""
7278
automation_id = create_test_automation(client)
@@ -85,6 +91,7 @@ def test_delete_automation(client: TestClient):
8591

8692

8793
@pytest.mark.django_db(transaction=True)
94+
@pytest.mark.skipif(get_chat_api_key("google") is None, reason="Requires GEMINI_API_KEY to be set")
8895
def test_edit_automation(client: TestClient):
8996
"""Test that editing an automation works."""
9097
automation_id = create_test_automation(client)
@@ -111,6 +118,7 @@ def test_edit_automation(client: TestClient):
111118

112119

113120
@pytest.mark.django_db(transaction=True)
121+
@pytest.mark.skipif(get_chat_api_key("google") is None, reason="Requires GEMINI_API_KEY to be set")
114122
def test_trigger_automation(client: TestClient):
115123
"""Test that triggering an automation works."""
116124
automation_id = create_test_automation(client)

tests/test_online_chat_actors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from datetime import datetime
23

34
import freezegun
@@ -20,7 +21,7 @@
2021

2122
# Initialize variables for tests
2223
api_key = get_chat_api_key()
23-
if api_key is None:
24+
if api_key is None or not os.getenv("KHOJ_TEST_CHAT_PROVIDER"):
2425
pytest.skip(
2526
reason="Set OPENAI_API_KEY, GEMINI_API_KEY or ANTHROPIC_API_KEY environment variable to run tests below.",
2627
allow_module_level=True,

tests/test_online_chat_director.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
# Initialize variables for tests
1212
api_key = get_chat_api_key()
13-
if api_key is None:
13+
if api_key is None or not os.getenv("KHOJ_TEST_CHAT_PROVIDER"):
1414
pytest.skip(
15-
reason="Set OPENAI_API_KEY environment variable to run tests below. Get OpenAI API key from https://platform.openai.com/account/api-keys",
15+
reason="Set OPENAI_API_KEY, GEMINI_API_KEY or ANTHROPIC_API_KEY environment variable to run tests below.",
1616
allow_module_level=True,
1717
)
1818

0 commit comments

Comments
 (0)