def test_exists_hit_w_alternate_client(self): PATH = "/projects/%s/jobs/%s" % (self.PROJECT, self.JOB_ID) conn1 = _make_connection() client1 = _make_client(project=self.PROJECT, connection=conn1) conn2 = _make_connection({}) client2 = _make_client(project=self.PROJECT, connection=conn2) job = self._make_one(self.JOB_ID, [self.SOURCE1], self.TABLE_REF, client1) with mock.patch( "google.cloud.bigquery.opentelemetry_tracing._get_final_span_attributes" ) as final_attributes: self.assertTrue(job.exists(client=client2)) final_attributes.assert_called_with( {"path": "/projects/{}/jobs/{}".format(self.PROJECT, self.JOB_ID)}, client2, job, ) conn1.api_request.assert_not_called() conn2.api_request.assert_called_once_with( method="GET", path=PATH, query_params={"fields": "id"}, timeout=None)
def test_exists_defaults_miss(self): from google.cloud.exceptions import NotFound from google.cloud.bigquery.retry import DEFAULT_RETRY job = self._set_properties_job() job._properties["jobReference"]["location"] = self.LOCATION call_api = job._client._call_api = mock.Mock() call_api.side_effect = NotFound("testing") self.assertFalse(job.exists()) call_api.assert_called_once_with( DEFAULT_RETRY, span_name="BigQuery.job.exists", span_attributes={ "path": "/projects/{}/jobs/{}".format(self.PROJECT, self.JOB_ID) }, job_ref=job, method="GET", path="/projects/{}/jobs/{}".format(self.PROJECT, self.JOB_ID), query_params={ "fields": "id", "location": self.LOCATION }, timeout=None, )
def test_exists_explicit_hit(self): from google.cloud.bigquery.retry import DEFAULT_RETRY other_project = "other-project-234" resource = { "jobReference": { "jobId": self.JOB_ID, "projectId": self.PROJECT, "location": None, }, "configuration": { "test": True }, } job = self._set_properties_job() client = _make_client(project=other_project) call_api = client._call_api = mock.Mock() call_api.return_value = resource retry = DEFAULT_RETRY.with_deadline(1) self.assertTrue(job.exists(client=client, retry=retry)) call_api.assert_called_once_with( retry, span_name="BigQuery.job.exists", span_attributes={ "path": "/projects/{}/jobs/{}".format(self.PROJECT, self.JOB_ID) }, job_ref=job, method="GET", path="/projects/{}/jobs/{}".format(self.PROJECT, self.JOB_ID), query_params={"fields": "id"}, timeout=None, )
def test_exists_w_timeout(self): from google.cloud.bigquery.retry import DEFAULT_RETRY PATH = "/projects/{}/jobs/{}".format(self.PROJECT, self.JOB_ID) job = self._set_properties_job() call_api = job._client._call_api = mock.Mock() job.exists(timeout=7.5) call_api.assert_called_once_with( DEFAULT_RETRY, span_name="BigQuery.job.exists", span_attributes={"path": PATH}, job_ref=job, method="GET", path=PATH, query_params={"fields": "id"}, timeout=7.5, )
def test_exists_miss_w_bound_client(self): PATH = "/projects/%s/jobs/%s" % (self.PROJECT, self.JOB_ID) conn = _make_connection() client = _make_client(project=self.PROJECT, connection=conn) job = self._make_one(self.JOB_ID, self.TABLE_REF, [self.DESTINATION_URI], client) with mock.patch( "google.cloud.bigquery.opentelemetry_tracing._get_final_span_attributes" ) as final_attributes: self.assertFalse(job.exists()) final_attributes.assert_called_with({"path": PATH}, client, job) conn.api_request.assert_called_once_with(method="GET", path=PATH, query_params={"fields": "id"}, timeout=None)