@@ -844,6 +844,22 @@ def test_date_format_setter(self):
844844 config .date_format = date_format
845845 self .assertEqual (config ._properties ["load" ]["dateFormat" ], date_format )
846846
847+ def test_time_zone_missing (self ):
848+ config = self ._get_target_class ()()
849+ self .assertIsNone (config .time_zone )
850+
851+ def test_time_zone_hit (self ):
852+ time_zone = "UTC"
853+ config = self ._get_target_class ()()
854+ config ._properties ["load" ]["timeZone" ] = time_zone
855+ self .assertEqual (config .time_zone , time_zone )
856+
857+ def test_time_zone_setter (self ):
858+ time_zone = "America/New_York"
859+ config = self ._get_target_class ()()
860+ config .time_zone = time_zone
861+ self .assertEqual (config ._properties ["load" ]["timeZone" ], time_zone )
862+
847863 def test_parquet_options_missing (self ):
848864 config = self ._get_target_class ()()
849865 self .assertIsNone (config .parquet_options )
@@ -917,3 +933,114 @@ def test_column_name_character_map_none(self):
917933 config ._properties ["load" ]["columnNameCharacterMap" ],
918934 ColumnNameCharacterMap .COLUMN_NAME_CHARACTER_MAP_UNSPECIFIED ,
919935 )
936+
937+ RESOURCE = {
938+ "load" : {
939+ "allowJaggedRows" : True ,
940+ "createDisposition" : "CREATE_NEVER" ,
941+ "encoding" : "UTF-8" ,
942+ "fieldDelimiter" : "," ,
943+ "ignoreUnknownValues" : True ,
944+ "maxBadRecords" : 10 ,
945+ "nullMarker" : "\\ N" ,
946+ "quote" : '"' ,
947+ "schema" : {
948+ "fields" : [
949+ {"name" : "name" , "type" : "STRING" , "mode" : "NULLABLE" },
950+ {"name" : "age" , "type" : "INTEGER" , "mode" : "NULLABLE" },
951+ ]
952+ },
953+ "skipLeadingRows" : "1" ,
954+ "sourceFormat" : "CSV" ,
955+ "timePartitioning" : {
956+ "type" : "DAY" ,
957+ "field" : "transaction_date" ,
958+ },
959+ "useAvroLogicalTypes" : True ,
960+ "writeDisposition" : "WRITE_TRUNCATE" ,
961+ "timeZone" : "America/New_York" ,
962+ "parquetOptions" : {"enableListInference" : True },
963+ "columnNameCharacterMap" : "V2" ,
964+ "someNewField" : "some-value" ,
965+ }
966+ }
967+
968+ def test_from_api_repr (self ):
969+ from google .cloud .bigquery .job import (
970+ CreateDisposition ,
971+ LoadJobConfig ,
972+ SourceFormat ,
973+ WriteDisposition ,
974+ )
975+ from google .cloud .bigquery .schema import SchemaField
976+ from google .cloud .bigquery .table import TimePartitioning , TimePartitioningType
977+
978+ from google .cloud .bigquery .job .load import ColumnNameCharacterMap
979+
980+ config = LoadJobConfig .from_api_repr (self .RESOURCE )
981+
982+ self .assertTrue (config .allow_jagged_rows )
983+ self .assertEqual (config .create_disposition , CreateDisposition .CREATE_NEVER )
984+ self .assertEqual (config .encoding , "UTF-8" )
985+ self .assertEqual (config .field_delimiter , "," )
986+ self .assertTrue (config .ignore_unknown_values )
987+ self .assertEqual (config .max_bad_records , 10 )
988+ self .assertEqual (config .null_marker , "\\ N" )
989+ self .assertEqual (config .quote_character , '"' )
990+ self .assertEqual (
991+ config .schema ,
992+ [SchemaField ("name" , "STRING" ), SchemaField ("age" , "INTEGER" )],
993+ )
994+ self .assertEqual (config .skip_leading_rows , 1 )
995+ self .assertEqual (config .source_format , SourceFormat .CSV )
996+ self .assertEqual (
997+ config .time_partitioning ,
998+ TimePartitioning (type_ = TimePartitioningType .DAY , field = "transaction_date" ),
999+ )
1000+ self .assertTrue (config .use_avro_logical_types )
1001+ self .assertEqual (config .write_disposition , WriteDisposition .WRITE_TRUNCATE )
1002+ self .assertEqual (config .time_zone , "America/New_York" )
1003+ self .assertTrue (config .parquet_options .enable_list_inference )
1004+ self .assertEqual (config .column_name_character_map , ColumnNameCharacterMap .V2 )
1005+ self .assertEqual (config ._properties ["load" ]["someNewField" ], "some-value" )
1006+
1007+ def test_to_api_repr (self ):
1008+ from google .cloud .bigquery .job import (
1009+ CreateDisposition ,
1010+ LoadJobConfig ,
1011+ SourceFormat ,
1012+ WriteDisposition ,
1013+ )
1014+ from google .cloud .bigquery .schema import SchemaField
1015+ from google .cloud .bigquery .table import TimePartitioning , TimePartitioningType
1016+ from google .cloud .bigquery .format_options import ParquetOptions
1017+ from google .cloud .bigquery .job .load import ColumnNameCharacterMap
1018+
1019+ config = LoadJobConfig ()
1020+ config .allow_jagged_rows = True
1021+ config .create_disposition = CreateDisposition .CREATE_NEVER
1022+ config .encoding = "UTF-8"
1023+ config .field_delimiter = ","
1024+ config .ignore_unknown_values = True
1025+ config .max_bad_records = 10
1026+ config .null_marker = r"\N"
1027+ config .quote_character = '"'
1028+ config .schema = [SchemaField ("name" , "STRING" ), SchemaField ("age" , "INTEGER" )]
1029+ config .skip_leading_rows = 1
1030+ config .source_format = SourceFormat .CSV
1031+ config .time_partitioning = TimePartitioning (
1032+ type_ = TimePartitioningType .DAY , field = "transaction_date"
1033+ )
1034+ config .use_avro_logical_types = True
1035+ config .write_disposition = WriteDisposition .WRITE_TRUNCATE
1036+ config .time_zone = "America/New_York"
1037+ parquet_options = ParquetOptions ()
1038+ parquet_options .enable_list_inference = True
1039+ config .parquet_options = parquet_options
1040+ config .column_name_character_map = ColumnNameCharacterMap .V2
1041+ config ._properties ["load" ]["someNewField" ] = "some-value"
1042+
1043+ api_repr = config .to_api_repr ()
1044+
1045+ expected = self .RESOURCE
1046+ self .assertEqual (api_repr , expected )
0 commit comments