@@ -1258,6 +1258,31 @@ def test_verify_schema_ignores_field_mode(self):
1258
1258
assert self .sut .verify_schema (
1259
1259
self .dataset_prefix + "1" , TABLE_ID + test_id , test_schema_2 )
1260
1260
1261
+ def test_upload_data_with_valid_user_schema (self ):
1262
+ df = tm .makeMixedDataFrame ()
1263
+ test_id = "15"
1264
+ test_schema = [{'name' : 'A' , 'type' : 'FLOAT' },
1265
+ {'name' : 'B' , 'type' : 'FLOAT' },
1266
+ {'name' : 'C' , 'type' : 'STRING' },
1267
+ {'name' : 'D' , 'type' : 'TIMESTAMP' }]
1268
+ destination_table = self .destination_table + test_id
1269
+ gbq .to_gbq (df , destination_table , _get_project_id (),
1270
+ private_key = _get_private_key_path (), table_schema = test_schema )
1271
+ dataset , table = destination_table .split ('.' )
1272
+ assert self .table .verify_schema (dataset , table , dict (fields = test_schema ))
1273
+
1274
+ def test_upload_data_with_invalid_user_schema_raises_error (self ):
1275
+ df = tm .makeMixedDataFrame ()
1276
+ test_id = "16"
1277
+ test_schema = [{'name' : 'A' , 'type' : 'FLOAT' },
1278
+ {'name' : 'B' , 'type' : 'FLOAT' },
1279
+ {'name' : 'C' , 'type' : 'FLOAT' },
1280
+ {'name' : 'D' , 'type' : 'FLOAT' }]
1281
+ destination_table = self .destination_table + test_id
1282
+ with tm .assertRaises (gbq .StreamingInsertError ):
1283
+ gbq .to_gbq (df , destination_table , _get_project_id (),
1284
+ private_key = _get_private_key_path (), table_schema = test_schema )
1285
+
1261
1286
def test_list_dataset (self ):
1262
1287
dataset_id = self .dataset_prefix + "1"
1263
1288
assert dataset_id in self .dataset .datasets ()
0 commit comments