Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
usefulalgorithm committed Nov 7, 2024
1 parent 5dc2b54 commit d6a48b2
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import datetime
from unittest.mock import MagicMock, patch

import pytz
from google.cloud import bigquery

from metaphor.bigquery.job_change_event import JobChangeEvent
from metaphor.bigquery.utils import BigQueryResource
Expand Down Expand Up @@ -69,3 +71,32 @@ def test_parse_log(test_root_dir):
output_rows=1,
),
]


@patch("google.cloud.bigquery.Client")
def test_fetch_job_query(mock_client: MagicMock):
query = "SELECT * FROM my-project.dataset.table"
mock_client.get_job = lambda job_id, project: bigquery.QueryJob(
job_id=job_id,
query=query,
client=mock_client,
)
assert (
JobChangeEvent._fetch_job_query(mock_client, "projects/my-project/jobs/1234")
== query
)


@patch("google.cloud.bigquery.Client")
def test_fetch_job_query_fail(mock_client: MagicMock):
def fail_get_job(job_id, project):
raise ValueError

mock_client.get_job = fail_get_job
assert not JobChangeEvent._fetch_job_query(
mock_client, "projects/my-project/jobs/1234"
)


def test_fetch_not_a_job():
assert not JobChangeEvent._fetch_job_query(MagicMock(), "projects/my-project/jobs")

0 comments on commit d6a48b2

Please sign in to comment.