2222
2323from google .api_core import path_template
2424from google .cloud import iam_credentials_v1
25+ from google .cloud .storage ._helpers import _NOW
26+ from google .cloud .storage ._helpers import _UTC
2527from . import _helpers
2628
2729
@@ -63,7 +65,7 @@ def test_create_signed_list_blobs_url_v2(storage_client, signing_bucket, no_mtls
6365def test_create_signed_list_blobs_url_v2_w_expiration (
6466 storage_client , signing_bucket , no_mtls
6567):
66- now = datetime . datetime . utcnow ( )
68+ now = _NOW ( _UTC ). replace ( tzinfo = None )
6769 delta = datetime .timedelta (seconds = 10 )
6870
6971 _create_signed_list_blobs_url_helper (
@@ -85,7 +87,7 @@ def test_create_signed_list_blobs_url_v4(storage_client, signing_bucket, no_mtls
8587def test_create_signed_list_blobs_url_v4_w_expiration (
8688 storage_client , signing_bucket , no_mtls
8789):
88- now = datetime . datetime . utcnow ( )
90+ now = _NOW ( _UTC ). replace ( tzinfo = None )
8991 delta = datetime .timedelta (seconds = 10 )
9092 _create_signed_list_blobs_url_helper (
9193 storage_client ,
@@ -158,7 +160,7 @@ def test_create_signed_read_url_v4(storage_client, signing_bucket, no_mtls):
158160def test_create_signed_read_url_v2_w_expiration (
159161 storage_client , signing_bucket , no_mtls
160162):
161- now = datetime . datetime . utcnow ( )
163+ now = _NOW ( _UTC ). replace ( tzinfo = None )
162164 delta = datetime .timedelta (seconds = 10 )
163165
164166 _create_signed_read_url_helper (
@@ -169,7 +171,7 @@ def test_create_signed_read_url_v2_w_expiration(
169171def test_create_signed_read_url_v4_w_expiration (
170172 storage_client , signing_bucket , no_mtls
171173):
172- now = datetime . datetime . utcnow ( )
174+ now = _NOW ( _UTC ). replace ( tzinfo = None )
173175 delta = datetime .timedelta (seconds = 10 )
174176 _create_signed_read_url_helper (
175177 storage_client , signing_bucket , expiration = now + delta , version = "v4"
@@ -391,14 +393,15 @@ def test_generate_signed_post_policy_v4(
391393 with open (blob_name , "wb" ) as f :
392394 f .write (payload )
393395
396+ now = _NOW (_UTC ).replace (tzinfo = None )
394397 policy = storage_client .generate_signed_post_policy_v4 (
395398 bucket_name ,
396399 blob_name ,
397400 conditions = [
398401 {"bucket" : bucket_name },
399402 ["starts-with" , "$Content-Type" , "text/pla" ],
400403 ],
401- expiration = datetime . datetime . utcnow () + datetime .timedelta (hours = 1 ),
404+ expiration = now + datetime .timedelta (hours = 1 ),
402405 fields = {"content-type" : "text/plain" },
403406 )
404407 with open (blob_name , "r" ) as f :
@@ -424,14 +427,15 @@ def test_generate_signed_post_policy_v4_invalid_field(
424427 with open (blob_name , "wb" ) as f :
425428 f .write (payload )
426429
430+ now = _NOW (_UTC ).replace (tzinfo = None )
427431 policy = storage_client .generate_signed_post_policy_v4 (
428432 bucket_name ,
429433 blob_name ,
430434 conditions = [
431435 {"bucket" : bucket_name },
432436 ["starts-with" , "$Content-Type" , "text/pla" ],
433437 ],
434- expiration = datetime . datetime . utcnow () + datetime .timedelta (hours = 1 ),
438+ expiration = now + datetime .timedelta (hours = 1 ),
435439 fields = {"x-goog-random" : "invalid_field" , "content-type" : "text/plain" },
436440 )
437441 with open (blob_name , "r" ) as f :
0 commit comments