|
11 | 11 |
|
12 | 12 | from baserow.contrib.database.fields.exceptions import FieldDoesNotExist |
13 | 13 | from baserow.contrib.database.fields.handler import FieldHandler |
| 14 | +from baserow.contrib.database.fields.models import SelectOption |
14 | 15 | from baserow.contrib.database.rows.exceptions import RowDoesNotExist |
15 | 16 | from baserow.contrib.database.rows.handler import RowHandler |
16 | 17 | from baserow.contrib.database.views.exceptions import ViewDoesNotExist |
|
19 | 20 | from baserow.core.jobs.handler import JobHandler |
20 | 21 | from baserow.core.storage import get_default_storage |
21 | 22 | from baserow.core.user_files.handler import UserFileHandler |
| 23 | +from baserow_premium.fields.ai_field_output_types import ChoiceAIFieldOutputType |
22 | 24 | from baserow_premium.fields.models import GenerateAIValuesJob |
23 | 25 |
|
24 | 26 |
|
@@ -182,6 +184,48 @@ def test_create_job_with_only_empty_flag_table_mode(premium_data_fixture): |
182 | 184 | assert job.mode == GenerateAIValuesJob.MODES.TABLE |
183 | 185 |
|
184 | 186 |
|
| 187 | +@pytest.mark.django_db |
| 188 | +@pytest.mark.field_ai |
| 189 | +def test_create_job_with_only_empty_choice_output_type(premium_data_fixture): |
| 190 | + """Test job creation with only_empty=True and single select output.""" |
| 191 | + |
| 192 | + premium_data_fixture.register_fake_generate_ai_type() |
| 193 | + user = premium_data_fixture.create_user() |
| 194 | + database = premium_data_fixture.create_database_application(user=user) |
| 195 | + table = premium_data_fixture.create_database_table(database=database) |
| 196 | + field = premium_data_fixture.create_ai_field( |
| 197 | + table=table, ai_prompt="'test'", ai_output_type=ChoiceAIFieldOutputType.type |
| 198 | + ) |
| 199 | + option_1 = SelectOption.objects.create(field=field, value="A", order=1) |
| 200 | + SelectOption.objects.create(field=field, value="B", order=2) |
| 201 | + model = table.get_model() |
| 202 | + |
| 203 | + rows = ( |
| 204 | + RowHandler() |
| 205 | + .create_rows( |
| 206 | + user, table, rows_values=[{f"field_{field.id}": option_1.value}, {}, {}] |
| 207 | + ) |
| 208 | + .created_rows |
| 209 | + ) |
| 210 | + row_ids = [row.id for row in rows] |
| 211 | + |
| 212 | + job = JobHandler().create_and_start_job( |
| 213 | + user, |
| 214 | + "generate_ai_values", |
| 215 | + field_id=field.id, |
| 216 | + row_ids=row_ids, |
| 217 | + only_empty=True, |
| 218 | + sync=True, |
| 219 | + ) |
| 220 | + |
| 221 | + assert job.only_empty is True |
| 222 | + assert job.mode == GenerateAIValuesJob.MODES.ROWS |
| 223 | + |
| 224 | + choice_values = model.objects.all().values_list(f"field_{field.id}", flat=True) |
| 225 | + assert choice_values[0] == option_1.id |
| 226 | + assert all(x is not None for x in choice_values), choice_values |
| 227 | + |
| 228 | + |
185 | 229 | @pytest.mark.django_db |
186 | 230 | @pytest.mark.field_ai |
187 | 231 | def test_create_job_with_nonexistent_field(premium_data_fixture): |
|
0 commit comments