@@ -5002,17 +5002,6 @@ def test_rewrite_same_name_w_kms_key_w_version(self):
50025002 _target_object = dest ,
50035003 )
50045004
5005- def test_update_storage_class_invalid (self ):
5006- blob_name = "blob-name"
5007- bucket = _Bucket ()
5008- blob = self ._make_one (blob_name , bucket = bucket )
5009- blob .rewrite = mock .Mock (spec = [])
5010-
5011- with self .assertRaises (ValueError ):
5012- blob .update_storage_class ("BOGUS" )
5013-
5014- blob .rewrite .assert_not_called ()
5015-
50165005 def _update_storage_class_multi_pass_helper (self , ** kw ):
50175006 blob_name = "blob-name"
50185007 storage_class = "NEARLINE"
@@ -5223,6 +5212,38 @@ def test_update_storage_class_single_pass_w_retry(self):
52235212 retry = mock .Mock (spec = [])
52245213 self ._update_storage_class_single_pass_helper (retry = retry )
52255214
5215+ def test_update_storage_class_invalid (self ):
5216+ from google .cloud .exceptions import BadRequest
5217+
5218+ storage_class = "BOGUS"
5219+ blob_name = "blob-name"
5220+ client = mock .Mock (spec = [])
5221+ bucket = _Bucket (client = client )
5222+ blob = self ._make_one (blob_name , bucket = bucket )
5223+ blob .rewrite = mock .Mock (spec = [])
5224+ blob .rewrite .side_effect = BadRequest ("Invalid storage class" )
5225+
5226+ with self .assertRaises (BadRequest ):
5227+ blob .update_storage_class (storage_class )
5228+
5229+ # Test that invalid classes are allowed without client side validation.
5230+ # Fall back to server side validation and errors.
5231+ self .assertEqual (blob .storage_class , storage_class )
5232+
5233+ blob .rewrite .assert_called_once_with (
5234+ blob ,
5235+ if_generation_match = None ,
5236+ if_generation_not_match = None ,
5237+ if_metageneration_match = None ,
5238+ if_metageneration_not_match = None ,
5239+ if_source_generation_match = None ,
5240+ if_source_generation_not_match = None ,
5241+ if_source_metageneration_match = None ,
5242+ if_source_metageneration_not_match = None ,
5243+ timeout = self ._get_default_timeout (),
5244+ retry = DEFAULT_RETRY_IF_GENERATION_SPECIFIED ,
5245+ )
5246+
52265247 def test_cache_control_getter (self ):
52275248 BLOB_NAME = "blob-name"
52285249 bucket = _Bucket ()
0 commit comments