Skip to content

Commit

Permalink
add the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sunank200 committed Apr 15, 2024
1 parent 8db41f8 commit fa17f5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/providers/google/cloud/hooks/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,25 @@ async def test_get_job_output_assert_once_with(self, mock_job_instance):
resp = await hook.get_job_output(job_id=JOB_ID, project_id=PROJECT_ID)
assert resp == response

@pytest.mark.asyncio
@mock.patch("google.auth.default")
@mock.patch("airflow.providers.google.cloud.hooks.bigquery.Job")
async def test_cancel_job_success(self, mock_job, mock_auth_default):
mock_credentials = mock.MagicMock(spec=google.auth.compute_engine.Credentials)
mock_credentials.token = "ACCESS_TOKEN"
mock_auth_default.return_value = (mock_credentials, PROJECT_ID)
job_id = "test_job_id"
project_id = "test_project"
location = "US"

mock_job_instance = AsyncMock()
mock_job_instance.cancel.return_value = None
mock_job.return_value = mock_job_instance

await self.hook.cancel_job(job_id=job_id, project_id=project_id, location=location)

mock_job_instance.cancel.assert_called_once()

@pytest.mark.asyncio
@mock.patch("airflow.providers.google.cloud.hooks.bigquery.ClientSession")
@mock.patch("airflow.providers.google.cloud.hooks.bigquery.BigQueryAsyncHook.get_job_instance")
Expand Down
1 change: 1 addition & 0 deletions tests/providers/google/cloud/triggers/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def test_serialization(self, insert_job_trigger):
classpath, kwargs = insert_job_trigger.serialize()
assert classpath == "airflow.providers.google.cloud.triggers.bigquery.BigQueryInsertJobTrigger"
assert kwargs == {
"cancel_on_kill": True,
"conn_id": TEST_CONN_ID,
"job_id": TEST_JOB_ID,
"project_id": TEST_GCP_PROJECT_ID,
Expand Down

0 comments on commit fa17f5b

Please sign in to comment.