@@ -294,6 +294,17 @@ def test_from_api_repr_defaults(self):
294294 self .assertNotIn ("policyTags" , field ._properties )
295295 self .assertNotIn ("rangeElementType" , field ._properties )
296296
297+ def test_from_api_repr_timestamp_precision_str (self ):
298+ # The backend would return timestampPrecision field as a string, even
299+ # if we send over an integer. This test verifies we manually converted
300+ # it into integer to ensure resending could succeed.
301+ field = self ._get_target_class ().from_api_repr (
302+ {
303+ "timestampPrecision" : "12" ,
304+ }
305+ )
306+ self .assertEqual (field ._properties ["timestampPrecision" ], 12 )
307+
297308 def test_name_property (self ):
298309 name = "lemon-ness"
299310 schema_field = self ._make_one (name , "INTEGER" )
@@ -353,6 +364,14 @@ def test_foreign_type_definition_property_str(self):
353364 schema_field ._properties ["foreignTypeDefinition" ] = FOREIGN_TYPE_DEFINITION
354365 self .assertEqual (schema_field .foreign_type_definition , FOREIGN_TYPE_DEFINITION )
355366
367+ def test_timestamp_precision_unsupported_type (self ):
368+ with pytest .raises (ValueError ) as e :
369+ self ._make_one ("test" , "TIMESTAMP" , timestamp_precision = 12 )
370+
371+ assert "timestamp_precision must be class enums.TimestampPrecision" in str (
372+ e .value
373+ )
374+
356375 def test_timestamp_precision_property (self ):
357376 TIMESTAMP_PRECISION = enums .TimestampPrecision .PICOSECOND
358377 schema_field = self ._make_one ("test" , "TIMESTAMP" )
0 commit comments