@@ -543,7 +543,9 @@ def test_create_bucket_with_string_conflict(self):
543543 client ._http_internal = http
544544
545545 with self .assertRaises (Conflict ):
546- client .create_bucket (bucket_name , project = other_project , user_project = user_project )
546+ client .create_bucket (
547+ bucket_name , project = other_project , user_project = user_project
548+ )
547549
548550 http .request .assert_called_once_with (
549551 method = "POST" , url = URI , data = mock .ANY , headers = mock .ANY
@@ -586,6 +588,102 @@ def test_create_bucket_with_object_conflict(self):
586588 json_sent = http .request .call_args_list [0 ][1 ]["data" ]
587589 self .assertEqual (json_expected , json .loads (json_sent ))
588590
591+ def test_create_w_missing_client_project (self ):
592+ client = self ._make_one (project = None )
593+
594+ with self .assertRaises (ValueError ):
595+ client .create_bucket ("bucket" )
596+
597+ def test_create_w_predefined_acl_invalid (self ):
598+ PROJECT = "PROJECT"
599+ BUCKET_NAME = "bucket-name"
600+ credentials = _make_credentials ()
601+ client = self ._make_one (project = PROJECT , credentials = credentials )
602+
603+ with self .assertRaises (ValueError ):
604+ client .create_bucket (BUCKET_NAME , predefined_acl = "bogus" )
605+
606+ def test_create_w_predefined_acl_valid (self ):
607+ from google .cloud .storage .client import Client
608+
609+ PROJECT = "PROJECT"
610+ BUCKET_NAME = "bucket-name"
611+ DATA = {"name" : BUCKET_NAME }
612+
613+ client = Client (project = PROJECT )
614+ connection = _make_connection (DATA )
615+ client ._base_connection = connection
616+ bucket = client .create_bucket (BUCKET_NAME , predefined_acl = "publicRead" )
617+
618+ connection .api_request .assert_called_once_with (
619+ method = "POST" ,
620+ path = "/b" ,
621+ query_params = {"project" : PROJECT , "predefinedAcl" : "publicRead" },
622+ data = DATA ,
623+ _target_object = bucket ,
624+ )
625+
626+ def test_create_w_predefined_default_object_acl_invalid (self ):
627+ PROJECT = "PROJECT"
628+ BUCKET_NAME = "bucket-name"
629+
630+ credentials = _make_credentials ()
631+ client = self ._make_one (project = PROJECT , credentials = credentials )
632+
633+ with self .assertRaises (ValueError ):
634+ client .create_bucket (BUCKET_NAME , predefined_default_object_acl = "bogus" )
635+
636+ def test_create_w_predefined_default_object_acl_valid (self ):
637+ from google .cloud .storage .client import Client
638+
639+ PROJECT = "PROJECT"
640+ BUCKET_NAME = "bucket-name"
641+ DATA = {"name" : BUCKET_NAME }
642+
643+ client = Client (project = PROJECT )
644+ connection = _make_connection (DATA )
645+ client ._base_connection = connection
646+ bucket = client .create_bucket (
647+ BUCKET_NAME , predefined_default_object_acl = "publicRead"
648+ )
649+
650+ connection .api_request .assert_called_once_with (
651+ method = "POST" ,
652+ path = "/b" ,
653+ query_params = {
654+ "project" : PROJECT ,
655+ "predefinedDefaultObjectAcl" : "publicRead" ,
656+ },
657+ data = DATA ,
658+ _target_object = bucket ,
659+ )
660+
661+ def test_create_w_explicit_location (self ):
662+ from google .cloud .storage .client import Client
663+
664+ PROJECT = "PROJECT"
665+ BUCKET_NAME = "bucket-name"
666+ LOCATION = "us-central1"
667+ DATA = {"location" : LOCATION , "name" : BUCKET_NAME }
668+
669+ connection = _make_connection (
670+ DATA , "{'location': 'us-central1', 'name': 'bucket-name'}"
671+ )
672+
673+ client = Client (project = PROJECT )
674+ client ._base_connection = connection
675+
676+ bucket = client .create_bucket (BUCKET_NAME , location = LOCATION )
677+
678+ connection .api_request .assert_called_once_with (
679+ method = "POST" ,
680+ path = "/b" ,
681+ data = DATA ,
682+ _target_object = bucket ,
683+ query_params = {"project" : "PROJECT" },
684+ )
685+ self .assertEqual (bucket .location , LOCATION )
686+
589687 def test_create_bucket_with_string_success (self ):
590688 from google .cloud .storage .bucket import Bucket
591689
0 commit comments