6
6
from codex import AuthenticationError
7
7
from codex .types .project_create_params import Config
8
8
from codex .types .projects .access_key_retrieve_project_id_response import AccessKeyRetrieveProjectIDResponse
9
+ from codex .types .projects .entry import Entry as SDKEntry
9
10
10
11
from cleanlab_codex .project import MissingProjectError , Project
11
- from cleanlab_codex .types .entry import Entry , EntryCreate
12
+ from cleanlab_codex .types .entry import EntryCreate
12
13
13
14
FAKE_PROJECT_ID = str (uuid .uuid4 ())
14
15
FAKE_USER_ID = "Test User"
@@ -138,11 +139,12 @@ def test_query_read_only(mock_client_from_access_key: MagicMock) -> None:
138
139
FAKE_PROJECT_ID , question = "What is the capital of France?"
139
140
)
140
141
mock_client_from_access_key .projects .entries .add_question .assert_not_called ()
141
- assert res == (None , None )
142
+ assert res [0 ] is None
143
+ assert res [1 ] is None
142
144
143
145
144
146
def test_query_question_found_fallback_answer (mock_client_from_access_key : MagicMock ) -> None :
145
- unanswered_entry = Entry (
147
+ unanswered_entry = SDKEntry (
146
148
id = str (uuid .uuid4 ()),
147
149
created_at = datetime .now (tz = timezone .utc ),
148
150
question = "What is the capital of France?" ,
@@ -151,22 +153,32 @@ def test_query_question_found_fallback_answer(mock_client_from_access_key: Magic
151
153
mock_client_from_access_key .projects .entries .query .return_value = unanswered_entry
152
154
project = Project (mock_client_from_access_key , FAKE_PROJECT_ID )
153
155
res = project .query ("What is the capital of France?" )
154
- assert res == (None , unanswered_entry )
156
+ assert res [0 ] is None
157
+ assert res [1 ] is not None
158
+ assert res [1 ].model_dump () == unanswered_entry .model_dump ()
155
159
156
160
157
161
def test_query_question_not_found_fallback_answer (mock_client_from_access_key : MagicMock ) -> None :
158
162
mock_client_from_access_key .projects .entries .query .return_value = None
159
- mock_client_from_access_key .projects .entries .add_question .return_value = MagicMock (spec = Entry )
163
+ mock_entry = SDKEntry (
164
+ id = "fake-id" ,
165
+ created_at = datetime .now (tz = timezone .utc ),
166
+ question = "What is the capital of France?" ,
167
+ answer = None ,
168
+ )
169
+ mock_client_from_access_key .projects .entries .add_question .return_value = mock_entry
160
170
161
171
project = Project (mock_client_from_access_key , FAKE_PROJECT_ID )
162
172
res = project .query ("What is the capital of France?" , fallback_answer = "Paris" )
163
173
assert res [0 ] == "Paris"
174
+ assert res [1 ] is not None
175
+ assert res [1 ].model_dump () == mock_entry .model_dump ()
164
176
165
177
166
178
def test_query_add_question_when_not_found (mock_client_from_access_key : MagicMock ) -> None :
167
179
"""Test that query adds question when not found and not read_only"""
168
180
mock_client_from_access_key .projects .entries .query .return_value = None
169
- new_entry = Entry (
181
+ new_entry = SDKEntry (
170
182
id = str (uuid .uuid4 ()),
171
183
created_at = datetime .now (tz = timezone .utc ),
172
184
question = "What is the capital of France?" ,
@@ -180,11 +192,13 @@ def test_query_add_question_when_not_found(mock_client_from_access_key: MagicMoc
180
192
mock_client_from_access_key .projects .entries .add_question .assert_called_once_with (
181
193
FAKE_PROJECT_ID , question = "What is the capital of France?"
182
194
)
183
- assert res == (None , new_entry )
195
+ assert res [0 ] is None
196
+ assert res [1 ] is not None
197
+ assert res [1 ].model_dump () == new_entry .model_dump ()
184
198
185
199
186
200
def test_query_answer_found (mock_client_from_access_key : MagicMock ) -> None :
187
- answered_entry = Entry (
201
+ answered_entry = SDKEntry (
188
202
id = str (uuid .uuid4 ()),
189
203
created_at = datetime .now (tz = timezone .utc ),
190
204
question = "What is the capital of France?" ,
@@ -193,7 +207,9 @@ def test_query_answer_found(mock_client_from_access_key: MagicMock) -> None:
193
207
mock_client_from_access_key .projects .entries .query .return_value = answered_entry
194
208
project = Project (mock_client_from_access_key , FAKE_PROJECT_ID )
195
209
res = project .query ("What is the capital of France?" )
196
- assert res == ("Paris" , answered_entry )
210
+ assert res [0 ] == answered_entry .answer
211
+ assert res [1 ] is not None
212
+ assert res [1 ].model_dump () == answered_entry .model_dump ()
197
213
198
214
199
215
def test_add_entries_empty_list (mock_client_from_access_key : MagicMock ) -> None :
0 commit comments