83
83
}
84
84
TEST_TABLE = "test-table"
85
85
GCP_CONN_ID = "google_cloud_default"
86
+ TEST_JOB_ID_1 = "test-job-id"
87
+ TEST_JOB_ID_2 = "test-123"
88
+ TEST_FULL_JOB_ID = f"{ TEST_GCP_PROJECT_ID } :{ TEST_DATASET_LOCATION } :{ TEST_JOB_ID_1 } "
89
+ TEST_FULL_JOB_ID_2 = f"{ TEST_GCP_PROJECT_ID } :{ TEST_DATASET_LOCATION } :{ TEST_JOB_ID_2 } "
86
90
87
91
88
92
class TestBigQueryCreateEmptyTableOperator :
@@ -672,11 +676,15 @@ def test_bigquery_operator_extra_serialized_field_when_single_query(
672
676
673
677
# Check DeSerialized version of operator link
674
678
assert isinstance (list (simple_task .operator_extra_links )[0 ], BigQueryConsoleLink )
675
-
676
- ti .xcom_push ("job_id" , 12345 )
679
+ test_job_id_params = {
680
+ "job_id" : TEST_JOB_ID_1 ,
681
+ "project_id" : TEST_GCP_PROJECT_ID ,
682
+ "location" : TEST_DATASET_LOCATION ,
683
+ }
684
+ ti .xcom_push ("job_id_params" , test_job_id_params )
677
685
678
686
url = simple_task .get_extra_links (ti , BigQueryConsoleLink .name )
679
- assert url == "https://console.cloud.google.com/bigquery?j=12345 "
687
+ assert url == f "https://console.cloud.google.com/bigquery?j={ TEST_FULL_JOB_ID } "
680
688
681
689
@pytest .mark .need_serialized_dag
682
690
def test_bigquery_operator_extra_serialized_field_when_multiple_queries (
@@ -711,17 +719,23 @@ def test_bigquery_operator_extra_serialized_field_when_multiple_queries(
711
719
# Check DeSerialized version of operator link
712
720
assert isinstance (list (simple_task .operator_extra_links )[0 ], BigQueryConsoleIndexableLink )
713
721
714
- job_id = ["123" , "45" ]
715
- ti .xcom_push (key = "job_id" , value = job_id )
722
+ test_job_id_params = {
723
+ "job_id" : [TEST_JOB_ID_1 , TEST_JOB_ID_2 ],
724
+ "project_id" : TEST_GCP_PROJECT_ID ,
725
+ "location" : TEST_DATASET_LOCATION ,
726
+ }
727
+ ti .xcom_push (key = "job_id_params" , value = test_job_id_params )
716
728
717
729
assert {"BigQuery Console #1" , "BigQuery Console #2" } == simple_task .operator_extra_link_dict .keys ()
718
730
719
- assert "https://console.cloud.google.com/bigquery?j=123" == simple_task .get_extra_links (
720
- ti , "BigQuery Console #1"
731
+ assert (
732
+ f"https://console.cloud.google.com/bigquery?j={ TEST_FULL_JOB_ID } "
733
+ == simple_task .get_extra_links (ti , "BigQuery Console #1" )
721
734
)
722
735
723
- assert "https://console.cloud.google.com/bigquery?j=45" == simple_task .get_extra_links (
724
- ti , "BigQuery Console #2"
736
+ assert (
737
+ f"https://console.cloud.google.com/bigquery?j={ TEST_FULL_JOB_ID_2 } "
738
+ == simple_task .get_extra_links (ti , "BigQuery Console #2" )
725
739
)
726
740
727
741
@mock .patch ("airflow.providers.google.cloud.operators.bigquery.BigQueryHook" )
@@ -740,7 +754,9 @@ def test_bigquery_operator_extra_link_when_missing_job_id(
740
754
741
755
@mock .patch ("airflow.providers.google.cloud.operators.bigquery.BigQueryHook" )
742
756
def test_bigquery_operator_extra_link_when_single_query (
743
- self , mock_hook , create_task_instance_of_operator
757
+ self ,
758
+ mock_hook ,
759
+ create_task_instance_of_operator ,
744
760
):
745
761
ti = create_task_instance_of_operator (
746
762
BigQueryExecuteQueryOperator ,
@@ -751,11 +767,15 @@ def test_bigquery_operator_extra_link_when_single_query(
751
767
)
752
768
bigquery_task = ti .task
753
769
754
- job_id = "12345"
755
- ti .xcom_push (key = "job_id" , value = job_id )
756
-
757
- assert f"https://console.cloud.google.com/bigquery?j={ job_id } " == bigquery_task .get_extra_links (
758
- ti , BigQueryConsoleLink .name
770
+ test_job_id_params = {
771
+ "job_id" : TEST_JOB_ID_1 ,
772
+ "project_id" : TEST_GCP_PROJECT_ID ,
773
+ "location" : TEST_DATASET_LOCATION ,
774
+ }
775
+ ti .xcom_push (key = "job_id_params" , value = test_job_id_params )
776
+ assert (
777
+ f"https://console.cloud.google.com/bigquery?j={ TEST_FULL_JOB_ID } "
778
+ == bigquery_task .get_extra_links (ti , BigQueryConsoleLink .name )
759
779
)
760
780
761
781
@mock .patch ("airflow.providers.google.cloud.operators.bigquery.BigQueryHook" )
@@ -771,17 +791,22 @@ def test_bigquery_operator_extra_link_when_multiple_query(
771
791
)
772
792
bigquery_task = ti .task
773
793
774
- job_id = ["123" , "45" ]
775
- ti .xcom_push (key = "job_id" , value = job_id )
776
-
794
+ test_job_id_params = {
795
+ "job_id" : [TEST_JOB_ID_1 , TEST_JOB_ID_2 ],
796
+ "project_id" : TEST_GCP_PROJECT_ID ,
797
+ "location" : TEST_DATASET_LOCATION ,
798
+ }
799
+ ti .xcom_push (key = "job_id_params" , value = test_job_id_params )
777
800
assert {"BigQuery Console #1" , "BigQuery Console #2" } == bigquery_task .operator_extra_link_dict .keys ()
778
801
779
- assert "https://console.cloud.google.com/bigquery?j=123" == bigquery_task .get_extra_links (
780
- ti , "BigQuery Console #1"
802
+ assert (
803
+ f"https://console.cloud.google.com/bigquery?j={ TEST_FULL_JOB_ID } "
804
+ == bigquery_task .get_extra_links (ti , "BigQuery Console #1" )
781
805
)
782
806
783
- assert "https://console.cloud.google.com/bigquery?j=45" == bigquery_task .get_extra_links (
784
- ti , "BigQuery Console #2"
807
+ assert (
808
+ f"https://console.cloud.google.com/bigquery?j={ TEST_FULL_JOB_ID_2 } "
809
+ == bigquery_task .get_extra_links (ti , "BigQuery Console #2" )
785
810
)
786
811
787
812
0 commit comments