54
54
TABLE_REFERENCE = TableReference .from_api_repr (TABLE_REFERENCE_REPR )
55
55
56
56
57
- class _BigQueryBaseTestClass ( unittest . TestCase ) :
58
- def setUp (self ) -> None :
57
+ class _BigQueryBaseTestClass :
58
+ def setup_method (self ) -> None :
59
59
class MockedBigQueryHook (BigQueryHook ):
60
60
def _get_credentials_and_project_id (self ):
61
61
return CREDENTIALS , PROJECT_ID
@@ -898,9 +898,10 @@ def test_run_query_with_arg(self, mock_insert):
898
898
_ , kwargs = mock_insert .call_args
899
899
assert kwargs ["configuration" ]['labels' ] == {'label1' : 'test1' , 'label2' : 'test2' }
900
900
901
+ @pytest .mark .parametrize ('nowait' , [True , False ])
901
902
@mock .patch ("airflow.providers.google.cloud.hooks.bigquery.QueryJob" )
902
903
@mock .patch ("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_client" )
903
- def test_insert_job (self , mock_client , mock_query_job ):
904
+ def test_insert_job (self , mock_client , mock_query_job , nowait ):
904
905
job_conf = {
905
906
"query" : {
906
907
"query" : "SELECT * FROM test" ,
@@ -910,10 +911,7 @@ def test_insert_job(self, mock_client, mock_query_job):
910
911
mock_query_job ._JOB_TYPE = "query"
911
912
912
913
self .hook .insert_job (
913
- configuration = job_conf ,
914
- job_id = JOB_ID ,
915
- project_id = PROJECT_ID ,
916
- location = LOCATION ,
914
+ configuration = job_conf , job_id = JOB_ID , project_id = PROJECT_ID , location = LOCATION , nowait = nowait
917
915
)
918
916
919
917
mock_client .assert_called_once_with (
@@ -928,7 +926,12 @@ def test_insert_job(self, mock_client, mock_query_job):
928
926
},
929
927
mock_client .return_value ,
930
928
)
931
- mock_query_job .from_api_repr .return_value .result .assert_called_once_with ()
929
+ if nowait :
930
+ mock_query_job .from_api_repr .return_value ._begin .assert_called_once ()
931
+ mock_query_job .from_api_repr .return_value .result .assert_not_called ()
932
+ else :
933
+ mock_query_job .from_api_repr .return_value ._begin .assert_not_called ()
934
+ mock_query_job .from_api_repr .return_value .result .assert_called_once ()
932
935
933
936
def test_dbapi_get_uri (self ):
934
937
assert self .hook .get_uri ().startswith ('bigquery://' )
@@ -2014,7 +2017,7 @@ def test_create_external_table_labels(self, mock_create):
2014
2017
)
2015
2018
2016
2019
_ , kwargs = mock_create .call_args
2017
- self . assertDictEqual ( kwargs ['table_resource' ]['labels' ], labels )
2020
+ assert kwargs ['table_resource' ]['labels' ] == labels
2018
2021
2019
2022
@mock .patch ("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.create_empty_table" )
2020
2023
def test_create_external_table_description (self , mock_create ):
0 commit comments