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 :
@@ -673,10 +677,10 @@ def test_bigquery_operator_extra_serialized_field_when_single_query(
673
677
# Check DeSerialized version of operator link
674
678
assert isinstance (list (simple_task .operator_extra_links )[0 ], BigQueryConsoleLink )
675
679
676
- ti .xcom_push ("job_id " , 12345 )
680
+ ti .xcom_push ("job_id_path " , TEST_FULL_JOB_ID )
677
681
678
682
url = simple_task .get_extra_links (ti , BigQueryConsoleLink .name )
679
- assert url == "https://console.cloud.google.com/bigquery?j=12345 "
683
+ assert url == f "https://console.cloud.google.com/bigquery?j={ TEST_FULL_JOB_ID } "
680
684
681
685
@pytest .mark .need_serialized_dag
682
686
def test_bigquery_operator_extra_serialized_field_when_multiple_queries (
@@ -711,17 +715,18 @@ def test_bigquery_operator_extra_serialized_field_when_multiple_queries(
711
715
# Check DeSerialized version of operator link
712
716
assert isinstance (list (simple_task .operator_extra_links )[0 ], BigQueryConsoleIndexableLink )
713
717
714
- job_id = ["123" , "45" ]
715
- ti .xcom_push (key = "job_id" , value = job_id )
718
+ ti .xcom_push (key = "job_id_path" , value = [TEST_FULL_JOB_ID , TEST_FULL_JOB_ID_2 ])
716
719
717
720
assert {"BigQuery Console #1" , "BigQuery Console #2" } == simple_task .operator_extra_link_dict .keys ()
718
721
719
- assert "https://console.cloud.google.com/bigquery?j=123" == simple_task .get_extra_links (
720
- ti , "BigQuery Console #1"
722
+ assert (
723
+ f"https://console.cloud.google.com/bigquery?j={ TEST_FULL_JOB_ID } "
724
+ == simple_task .get_extra_links (ti , "BigQuery Console #1" )
721
725
)
722
726
723
- assert "https://console.cloud.google.com/bigquery?j=45" == simple_task .get_extra_links (
724
- ti , "BigQuery Console #2"
727
+ assert (
728
+ f"https://console.cloud.google.com/bigquery?j={ TEST_FULL_JOB_ID_2 } "
729
+ == simple_task .get_extra_links (ti , "BigQuery Console #2" )
725
730
)
726
731
727
732
@mock .patch ("airflow.providers.google.cloud.operators.bigquery.BigQueryHook" )
@@ -740,7 +745,9 @@ def test_bigquery_operator_extra_link_when_missing_job_id(
740
745
741
746
@mock .patch ("airflow.providers.google.cloud.operators.bigquery.BigQueryHook" )
742
747
def test_bigquery_operator_extra_link_when_single_query (
743
- self , mock_hook , create_task_instance_of_operator
748
+ self ,
749
+ mock_hook ,
750
+ create_task_instance_of_operator ,
744
751
):
745
752
ti = create_task_instance_of_operator (
746
753
BigQueryExecuteQueryOperator ,
@@ -751,11 +758,11 @@ def test_bigquery_operator_extra_link_when_single_query(
751
758
)
752
759
bigquery_task = ti .task
753
760
754
- job_id = "12345"
755
- ti .xcom_push (key = "job_id" , value = job_id )
761
+ ti .xcom_push (key = "job_id_path" , value = TEST_FULL_JOB_ID )
756
762
757
- assert f"https://console.cloud.google.com/bigquery?j={ job_id } " == bigquery_task .get_extra_links (
758
- ti , BigQueryConsoleLink .name
763
+ assert (
764
+ f"https://console.cloud.google.com/bigquery?j={ TEST_FULL_JOB_ID } "
765
+ == bigquery_task .get_extra_links (ti , BigQueryConsoleLink .name )
759
766
)
760
767
761
768
@mock .patch ("airflow.providers.google.cloud.operators.bigquery.BigQueryHook" )
@@ -771,17 +778,18 @@ def test_bigquery_operator_extra_link_when_multiple_query(
771
778
)
772
779
bigquery_task = ti .task
773
780
774
- job_id = ["123" , "45" ]
775
- ti .xcom_push (key = "job_id" , value = job_id )
781
+ ti .xcom_push (key = "job_id_path" , value = [TEST_FULL_JOB_ID , TEST_FULL_JOB_ID_2 ])
776
782
777
783
assert {"BigQuery Console #1" , "BigQuery Console #2" } == bigquery_task .operator_extra_link_dict .keys ()
778
784
779
- assert "https://console.cloud.google.com/bigquery?j=123" == bigquery_task .get_extra_links (
780
- ti , "BigQuery Console #1"
785
+ assert (
786
+ f"https://console.cloud.google.com/bigquery?j={ TEST_FULL_JOB_ID } "
787
+ == bigquery_task .get_extra_links (ti , "BigQuery Console #1" )
781
788
)
782
789
783
- assert "https://console.cloud.google.com/bigquery?j=45" == bigquery_task .get_extra_links (
784
- ti , "BigQuery Console #2"
790
+ assert (
791
+ f"https://console.cloud.google.com/bigquery?j={ TEST_FULL_JOB_ID_2 } "
792
+ == bigquery_task .get_extra_links (ti , "BigQuery Console #2" )
785
793
)
786
794
787
795
0 commit comments