4
4
from fastapi .testclient import TestClient
5
5
6
6
from khoj .utils import state
7
- from tests .helpers import ChatModelFactory
7
+ from tests .helpers import AiModelApiFactory , ChatModelFactory , get_chat_api_key
8
8
9
9
10
10
@pytest .fixture (autouse = True )
@@ -19,7 +19,9 @@ def setup_scheduler():
19
19
def create_test_automation (client : TestClient ) -> str :
20
20
"""Helper function to create a test automation and return its ID."""
21
21
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
+ )
23
25
params = {
24
26
"q" : "test automation" ,
25
27
"crontime" : "0 0 * * *" ,
@@ -34,7 +36,9 @@ def test_create_automation(client: TestClient):
34
36
"""Test that creating an automation works as expected."""
35
37
# Arrange
36
38
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
+ )
38
42
params = {
39
43
"q" : "test automation" ,
40
44
"crontime" : "0 0 * * *" ,
@@ -51,6 +55,7 @@ def test_create_automation(client: TestClient):
51
55
52
56
53
57
@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" )
54
59
def test_get_automations (client : TestClient ):
55
60
"""Test that getting a list of automations works."""
56
61
automation_id = create_test_automation (client )
@@ -67,6 +72,7 @@ def test_get_automations(client: TestClient):
67
72
68
73
69
74
@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" )
70
76
def test_delete_automation (client : TestClient ):
71
77
"""Test that deleting an automation works."""
72
78
automation_id = create_test_automation (client )
@@ -85,6 +91,7 @@ def test_delete_automation(client: TestClient):
85
91
86
92
87
93
@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" )
88
95
def test_edit_automation (client : TestClient ):
89
96
"""Test that editing an automation works."""
90
97
automation_id = create_test_automation (client )
@@ -111,6 +118,7 @@ def test_edit_automation(client: TestClient):
111
118
112
119
113
120
@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" )
114
122
def test_trigger_automation (client : TestClient ):
115
123
"""Test that triggering an automation works."""
116
124
automation_id = create_test_automation (client )
0 commit comments