Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def execute(self, context: Context):
raise AirflowException("Job with name %s not found", self.job_name)

context["ti"].xcom_push(key="job_status", value=job.state)
return dict(job)
return job.model_dump(mode="json")


class GenAIGeminiListBatchJobsOperator(GoogleCloudBaseOperator):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
TEST_BATCH_JOB_NAME = "test-name"
TEST_FILE_NAME = "test-file"
TEST_FILE_PATH = "test/path/to/file"
TEST_CREATE_BATCH_JOB_RESPONSE = {
TEST_BATCH_JOB_RESPONSE = {
"src": None,
"dest": "test-batch-job-destination",
"name": "test-name",
Expand Down Expand Up @@ -317,7 +317,7 @@ def test_execute(self, mock_hook):

@mock.patch(GEN_AI_PATH.format("GenAIGeminiAPIHook"))
def test_execute_return_value(self, mock_hook):
expected_return = TEST_CREATE_BATCH_JOB_RESPONSE
expected_return = TEST_BATCH_JOB_RESPONSE

mock_job = mock.MagicMock()
mock_job.model_dump.return_value = expected_return
Expand All @@ -343,7 +343,7 @@ def test_execute_return_value(self, mock_hook):

@mock.patch(GEN_AI_PATH.format("GenAIGeminiAPIHook"))
def test_execute_complete_return_value(self, mock_hook):
expected_return = TEST_CREATE_BATCH_JOB_RESPONSE
expected_return = TEST_BATCH_JOB_RESPONSE

event = {"status": "success", "job_name": "test-name"}

Expand Down Expand Up @@ -391,6 +391,29 @@ def test_execute(self, mock_hook):
job_name=TEST_BATCH_JOB_NAME,
)

@mock.patch(GEN_AI_PATH.format("GenAIGeminiAPIHook"))
def test_execute_return_value(self, mock_hook):
expected_return = TEST_BATCH_JOB_RESPONSE

mock_job = mock.MagicMock()
mock_job.model_dump.return_value = expected_return
mock_hook.return_value.get_batch_job.return_value = mock_job

op = GenAIGeminiGetBatchJobOperator(
task_id=TASK_ID,
project_id=GCP_PROJECT,
location=GCP_LOCATION,
job_name=TEST_BATCH_JOB_NAME,
gcp_conn_id=GCP_CONN_ID,
impersonation_chain=IMPERSONATION_CHAIN,
gemini_api_key=TEST_GEMINI_API_KEY,
)

result = op.execute(context={"ti": mock.MagicMock()})

assert result == expected_return
mock_job.model_dump.assert_called_once_with(mode="json")


class TestGenAIGeminiListBatchJobsOperator:
@mock.patch(GEN_AI_PATH.format("GenAIGeminiAPIHook"))
Expand Down