@@ -447,9 +447,7 @@ def test_upsert_records_inserts_one_record_to_empty_image_table(
447
447
col .HEIGHT .db_name : HEIGHT ,
448
448
}
449
449
)
450
- load_data_query = f"""INSERT INTO { load_table } VALUES(
451
- { query_values }
452
- );"""
450
+ load_data_query = utils .make_insert_query (load_table , query_values )
453
451
454
452
_set_up_std_popularity_func (
455
453
postgres_with_load_and_image_table ,
@@ -686,9 +684,8 @@ def test_upsert_records_replaces_data(
686
684
col .HEIGHT .db_name : HEIGHT_A ,
687
685
}
688
686
)
689
- load_data_query_a = f"""INSERT INTO { load_table } VALUES(
690
- { query_values }
691
- );"""
687
+ load_data_query_a = utils .make_insert_query (load_table , query_values )
688
+
692
689
_set_up_std_popularity_func (
693
690
postgres_with_load_and_image_table ,
694
691
load_data_query_a ,
@@ -728,9 +725,8 @@ def test_upsert_records_replaces_data(
728
725
col .HEIGHT .db_name : HEIGHT_B ,
729
726
}
730
727
)
731
- load_data_query_b = f"""INSERT INTO { load_table } VALUES(
732
- { query_values }
733
- );"""
728
+ load_data_query_b = utils .make_insert_query (load_table , query_values )
729
+
734
730
postgres_with_load_and_image_table .cursor .execute (f"DELETE FROM { load_table } ;" )
735
731
postgres_with_load_and_image_table .connection .commit ()
736
732
postgres_with_load_and_image_table .cursor .execute (load_data_query_b )
@@ -817,9 +813,8 @@ def test_upsert_records_does_not_replace_with_nulls(
817
813
col .HEIGHT .db_name : HEIGHT_A ,
818
814
}
819
815
)
820
- load_data_query_a = f"""INSERT INTO { load_table } VALUES(
821
- { query_values_a }
822
- );"""
816
+ load_data_query_a = utils .make_insert_query (load_table , query_values_a )
817
+
823
818
_set_up_std_popularity_func (
824
819
postgres_with_load_and_image_table ,
825
820
load_data_query_a ,
@@ -849,9 +844,8 @@ def test_upsert_records_does_not_replace_with_nulls(
849
844
col .SOURCE .db_name : SOURCE ,
850
845
}
851
846
)
852
- load_data_query_b = f"""INSERT INTO { load_table } VALUES(
853
- { query_values_b }
854
- );"""
847
+ load_data_query_b = utils .make_insert_query (load_table , query_values_b )
848
+
855
849
postgres_with_load_and_image_table .cursor .execute (f"DELETE FROM { load_table } ;" )
856
850
postgres_with_load_and_image_table .connection .commit ()
857
851
postgres_with_load_and_image_table .cursor .execute (load_data_query_b )
@@ -910,9 +904,7 @@ def test_upsert_records_merges_meta_data(
910
904
col .PROVIDER .db_name : PROVIDER ,
911
905
}
912
906
)
913
- load_data_query_a = f"""INSERT INTO { load_table } VALUES(
914
- { query_values_a }
915
- );"""
907
+ load_data_query_a = utils .make_insert_query (load_table , query_values_a )
916
908
917
909
query_values_b = utils .create_query_values (
918
910
{
@@ -923,9 +915,8 @@ def test_upsert_records_merges_meta_data(
923
915
col .PROVIDER .db_name : PROVIDER ,
924
916
}
925
917
)
926
- load_data_query_b = f"""INSERT INTO { load_table } VALUES(
927
- { query_values_b }
928
- );"""
918
+ load_data_query_b = utils .make_insert_query (load_table , query_values_b )
919
+
929
920
_set_up_std_popularity_func (
930
921
postgres_with_load_and_image_table ,
931
922
load_data_query_a ,
@@ -991,9 +982,7 @@ def test_upsert_records_does_not_replace_with_null_values_in_meta_data(
991
982
col .PROVIDER .db_name : PROVIDER ,
992
983
}
993
984
)
994
- load_data_query_a = f"""INSERT INTO { load_table } VALUES(
995
- { query_values_a }
996
- );"""
985
+ load_data_query_a = utils .make_insert_query (load_table , query_values_a )
997
986
998
987
query_values_b = utils .create_query_values (
999
988
{
@@ -1004,9 +993,8 @@ def test_upsert_records_does_not_replace_with_null_values_in_meta_data(
1004
993
col .PROVIDER .db_name : PROVIDER ,
1005
994
}
1006
995
)
1007
- load_data_query_b = f"""INSERT INTO { load_table } VALUES(
1008
- { query_values_b }
1009
- );"""
996
+ load_data_query_b = utils .make_insert_query (load_table , query_values_b )
997
+
1010
998
_set_up_std_popularity_func (
1011
999
postgres_with_load_and_image_table ,
1012
1000
load_data_query_a ,
@@ -1081,9 +1069,7 @@ def test_upsert_records_merges_tags(
1081
1069
col .PROVIDER .db_name : PROVIDER ,
1082
1070
}
1083
1071
)
1084
- load_data_query_a = f"""INSERT INTO { load_table } VALUES(
1085
- { query_values_a }
1086
- );"""
1072
+ load_data_query_a = utils .make_insert_query (load_table , query_values_a )
1087
1073
1088
1074
query_values_b = utils .create_query_values (
1089
1075
{
@@ -1094,9 +1080,7 @@ def test_upsert_records_merges_tags(
1094
1080
col .PROVIDER .db_name : PROVIDER ,
1095
1081
}
1096
1082
)
1097
- load_data_query_b = f"""INSERT INTO { load_table } VALUES(
1098
- { query_values_b }
1099
- );"""
1083
+ load_data_query_b = utils .make_insert_query (load_table , query_values_b )
1100
1084
_set_up_std_popularity_func (
1101
1085
postgres_with_load_and_image_table ,
1102
1086
load_data_query_a ,
@@ -1169,9 +1153,7 @@ def test_upsert_records_does_not_replace_tags_with_null(
1169
1153
col .PROVIDER .db_name : PROVIDER ,
1170
1154
}
1171
1155
)
1172
- load_data_query_a = f"""INSERT INTO { load_table } VALUES(
1173
- { query_values_a }
1174
- );"""
1156
+ load_data_query_a = utils .make_insert_query (load_table , query_values_a )
1175
1157
1176
1158
query_values_b = utils .create_query_values (
1177
1159
{
@@ -1181,9 +1163,8 @@ def test_upsert_records_does_not_replace_tags_with_null(
1181
1163
col .PROVIDER .db_name : PROVIDER ,
1182
1164
}
1183
1165
)
1184
- load_data_query_b = f"""INSERT INTO { load_table } VALUES(
1185
- { query_values_b }
1186
- );"""
1166
+ load_data_query_b = utils .make_insert_query (load_table , query_values_b )
1167
+
1187
1168
_set_up_std_popularity_func (
1188
1169
postgres_with_load_and_image_table ,
1189
1170
load_data_query_a ,
@@ -1253,9 +1234,8 @@ def test_upsert_records_replaces_null_tags(
1253
1234
}
1254
1235
)
1255
1236
logging .info (f"Query values a: { query_values_a } " )
1256
- load_data_query_a = f"""INSERT INTO { load_table } VALUES(
1257
- { query_values_a }
1258
- );"""
1237
+ load_data_query_a = utils .make_insert_query (load_table , query_values_a )
1238
+
1259
1239
query_values_b = utils .create_query_values (
1260
1240
{
1261
1241
col .FOREIGN_ID .db_name : FID ,
@@ -1265,9 +1245,7 @@ def test_upsert_records_replaces_null_tags(
1265
1245
col .PROVIDER .db_name : PROVIDER ,
1266
1246
}
1267
1247
)
1268
- load_data_query_b = f"""INSERT INTO { load_table } VALUES(
1269
- { query_values_b }
1270
- );"""
1248
+ load_data_query_b = utils .make_insert_query (load_table , query_values_b )
1271
1249
1272
1250
_set_up_std_popularity_func (
1273
1251
postgres_with_load_and_image_table ,
@@ -1342,9 +1320,7 @@ def test_upsert_records_handles_duplicate_url_and_does_not_merge(
1342
1320
col .PROVIDER .db_name : PROVIDER ,
1343
1321
}
1344
1322
)
1345
- load_data_query_a = f"""INSERT INTO { load_table } VALUES(
1346
- { query_values_a }
1347
- );"""
1323
+ load_data_query_a = utils .make_insert_query (load_table , query_values_a )
1348
1324
1349
1325
query_values_b = utils .create_query_values (
1350
1326
{
@@ -1355,9 +1331,7 @@ def test_upsert_records_handles_duplicate_url_and_does_not_merge(
1355
1331
col .PROVIDER .db_name : PROVIDER ,
1356
1332
}
1357
1333
)
1358
- load_data_query_b = f"""INSERT INTO { load_table } VALUES(
1359
- { query_values_b }
1360
- );"""
1334
+ load_data_query_b = utils .make_insert_query (load_table , query_values_b )
1361
1335
1362
1336
# Simulate a DAG run where A is ingested into the loading table, upserted into
1363
1337
# the image table, and finally the loading table is cleared for the next DAG run.
@@ -1438,9 +1412,7 @@ def test_upsert_records_handles_duplicate_urls_in_a_single_batch_and_does_not_me
1438
1412
col .PROVIDER .db_name : PROVIDER ,
1439
1413
}
1440
1414
)
1441
- load_data_query_a = f"""INSERT INTO { load_table } VALUES(
1442
- { query_values_a }
1443
- );"""
1415
+ load_data_query_a = utils .make_insert_query (load_table , query_values_a )
1444
1416
1445
1417
query_values_b = utils .create_query_values (
1446
1418
{
@@ -1451,9 +1423,7 @@ def test_upsert_records_handles_duplicate_urls_in_a_single_batch_and_does_not_me
1451
1423
col .PROVIDER .db_name : PROVIDER ,
1452
1424
}
1453
1425
)
1454
- load_data_query_b = f"""INSERT INTO { load_table } VALUES(
1455
- { query_values_b }
1456
- );"""
1426
+ load_data_query_b = utils .make_insert_query (load_table , query_values_b )
1457
1427
1458
1428
# C is not a duplicate of anything, just a normal image
1459
1429
query_values_c = utils .create_query_values (
@@ -1465,9 +1435,7 @@ def test_upsert_records_handles_duplicate_urls_in_a_single_batch_and_does_not_me
1465
1435
col .PROVIDER .db_name : PROVIDER ,
1466
1436
}
1467
1437
)
1468
- load_data_query_c = f"""INSERT INTO { load_table } VALUES(
1469
- { query_values_c }
1470
- );"""
1438
+ load_data_query_c = utils .make_insert_query (load_table , query_values_c )
1471
1439
1472
1440
# Simulate a DAG run where duplicates (A and B) and a non-duplicate (C) are all
1473
1441
# ingested in a single batch from the provider script, and we attempt to upsert
@@ -1595,13 +1563,13 @@ def test_upsert_records_calculates_standardized_popularity(
1595
1563
)
1596
1564
1597
1565
# Queries to insert the two records into the load table.
1598
- load_data_query_old_record = f"""INSERT INTO { load_table } VALUES (
1599
- { query_values_update_old_record }
1600
- );"""
1566
+ load_data_query_old_record = utils . make_insert_query (
1567
+ load_table , query_values_update_old_record
1568
+ )
1601
1569
1602
- load_data_query_new_record = f"""INSERT INTO { load_table } VALUES (
1603
- { query_values_update_new_record }
1604
- );"""
1570
+ load_data_query_new_record = utils . make_insert_query (
1571
+ load_table , query_values_update_new_record
1572
+ )
1605
1573
1606
1574
# Now actually insert the records into the load table. This simulates a DagRun which ingests both
1607
1575
# records.
0 commit comments