@@ -517,174 +517,129 @@ def test_lookup_bucket_hit(self):
517
517
method = "GET" , url = URI , data = mock .ANY , headers = mock .ANY
518
518
)
519
519
520
- def test_create_bucket_with_string_conflict (self ):
520
+ def test_create_bucket_w_missing_client_project (self ):
521
+ credentials = _make_credentials ()
522
+ client = self ._make_one (project = None , credentials = credentials )
523
+
524
+ with self .assertRaises (ValueError ):
525
+ client .create_bucket ("bucket" )
526
+
527
+ def test_create_bucket_w_conflict (self ):
521
528
from google .cloud .exceptions import Conflict
522
529
523
530
project = "PROJECT"
524
531
user_project = "USER_PROJECT"
525
532
other_project = "OTHER_PROJECT"
526
533
credentials = _make_credentials ()
527
534
client = self ._make_one (project = project , credentials = credentials )
535
+ connection = _make_connection ()
536
+ client ._base_connection = connection
537
+ connection .api_request .side_effect = Conflict ("testing" )
528
538
529
539
bucket_name = "bucket-name"
530
- URI = "/" .join (
531
- [
532
- client ._connection .API_BASE_URL ,
533
- "storage" ,
534
- client ._connection .API_VERSION ,
535
- "b?project=%s&userProject=%s" % (other_project , user_project ),
536
- ]
537
- )
538
- data = {"error" : {"message" : "Conflict" }}
539
- json_expected = {"name" : bucket_name }
540
- http = _make_requests_session (
541
- [_make_json_response (data , status = http_client .CONFLICT )]
542
- )
543
- client ._http_internal = http
540
+ data = {"name" : bucket_name }
544
541
545
542
with self .assertRaises (Conflict ):
546
543
client .create_bucket (
547
544
bucket_name , project = other_project , user_project = user_project
548
545
)
549
546
550
- http .request .assert_called_once_with (
551
- method = "POST" , url = URI , data = mock .ANY , headers = mock .ANY
547
+ connection .api_request .assert_called_once_with (
548
+ method = "POST" ,
549
+ path = "/b" ,
550
+ query_params = {"project" : other_project , "userProject" : user_project },
551
+ data = data ,
552
+ _target_object = mock .ANY ,
552
553
)
553
- json_sent = http .request .call_args_list [0 ][1 ]["data" ]
554
- self .assertEqual (json_expected , json .loads (json_sent ))
555
-
556
- def test_create_bucket_with_object_conflict (self ):
557
- from google .cloud .exceptions import Conflict
558
- from google .cloud .storage .bucket import Bucket
559
554
555
+ def test_create_bucket_w_predefined_acl_invalid (self ):
560
556
project = "PROJECT"
561
- other_project = "OTHER_PROJECT"
562
- credentials = _make_credentials ()
563
- client = self ._make_one (project = project , credentials = credentials )
564
-
565
557
bucket_name = "bucket-name"
566
- bucket_obj = Bucket (client , bucket_name )
567
- URI = "/" .join (
568
- [
569
- client ._connection .API_BASE_URL ,
570
- "storage" ,
571
- client ._connection .API_VERSION ,
572
- "b?project=%s" % (other_project ,),
573
- ]
574
- )
575
- data = {"error" : {"message" : "Conflict" }}
576
- http = _make_requests_session (
577
- [_make_json_response (data , status = http_client .CONFLICT )]
578
- )
579
- client ._http_internal = http
580
-
581
- with self .assertRaises (Conflict ):
582
- client .create_bucket (bucket_obj , project = other_project )
583
-
584
- http .request .assert_called_once_with (
585
- method = "POST" , url = URI , data = mock .ANY , headers = mock .ANY
586
- )
587
- json_expected = {"name" : bucket_name }
588
- json_sent = http .request .call_args_list [0 ][1 ]["data" ]
589
- self .assertEqual (json_expected , json .loads (json_sent ))
590
-
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
558
credentials = _make_credentials ()
601
- client = self ._make_one (project = PROJECT , credentials = credentials )
559
+ client = self ._make_one (project = project , credentials = credentials )
602
560
603
561
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
562
+ client .create_bucket (bucket_name , predefined_acl = "bogus" )
608
563
609
- PROJECT = "PROJECT"
610
- BUCKET_NAME = "bucket-name"
611
- DATA = {"name" : BUCKET_NAME }
564
+ def test_create_bucket_w_predefined_acl_valid (self ):
565
+ project = "PROJECT"
566
+ bucket_name = "bucket-name"
567
+ data = {"name" : bucket_name }
612
568
613
- client = Client (project = PROJECT )
614
- connection = _make_connection (DATA )
569
+ credentials = _make_credentials ()
570
+ client = self ._make_one (project = project , credentials = credentials )
571
+ connection = _make_connection (data )
615
572
client ._base_connection = connection
616
- bucket = client .create_bucket (BUCKET_NAME , predefined_acl = "publicRead" )
573
+ bucket = client .create_bucket (bucket_name , predefined_acl = "publicRead" )
617
574
618
575
connection .api_request .assert_called_once_with (
619
576
method = "POST" ,
620
577
path = "/b" ,
621
- query_params = {"project" : PROJECT , "predefinedAcl" : "publicRead" },
622
- data = DATA ,
578
+ query_params = {"project" : project , "predefinedAcl" : "publicRead" },
579
+ data = data ,
623
580
_target_object = bucket ,
624
581
)
625
582
626
- def test_create_w_predefined_default_object_acl_invalid (self ):
627
- PROJECT = "PROJECT"
628
- BUCKET_NAME = "bucket-name"
583
+ def test_create_bucket_w_predefined_default_object_acl_invalid (self ):
584
+ project = "PROJECT"
585
+ bucket_name = "bucket-name"
629
586
630
587
credentials = _make_credentials ()
631
- client = self ._make_one (project = PROJECT , credentials = credentials )
588
+ client = self ._make_one (project = project , credentials = credentials )
632
589
633
590
with self .assertRaises (ValueError ):
634
- client .create_bucket (BUCKET_NAME , predefined_default_object_acl = "bogus" )
591
+ client .create_bucket (bucket_name , predefined_default_object_acl = "bogus" )
635
592
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 }
593
+ def test_create_bucket_w_predefined_default_object_acl_valid (self ):
594
+ project = "PROJECT"
595
+ bucket_name = "bucket-name"
596
+ data = {"name" : bucket_name }
642
597
643
- client = Client (project = PROJECT )
644
- connection = _make_connection (DATA )
598
+ credentials = _make_credentials ()
599
+ client = self ._make_one (project = project , credentials = credentials )
600
+ connection = _make_connection (data )
645
601
client ._base_connection = connection
646
602
bucket = client .create_bucket (
647
- BUCKET_NAME , predefined_default_object_acl = "publicRead"
603
+ bucket_name , predefined_default_object_acl = "publicRead"
648
604
)
649
605
650
606
connection .api_request .assert_called_once_with (
651
607
method = "POST" ,
652
608
path = "/b" ,
653
609
query_params = {
654
- "project" : PROJECT ,
610
+ "project" : project ,
655
611
"predefinedDefaultObjectAcl" : "publicRead" ,
656
612
},
657
- data = DATA ,
613
+ data = data ,
658
614
_target_object = bucket ,
659
615
)
660
616
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 }
617
+ def test_create_bucket_w_explicit_location (self ):
618
+ project = "PROJECT"
619
+ bucket_name = "bucket-name"
620
+ location = "us-central1"
621
+ data = {"location" : location , "name" : bucket_name }
668
622
669
623
connection = _make_connection (
670
- DATA , "{'location': 'us-central1', 'name': 'bucket-name'}"
624
+ data , "{'location': 'us-central1', 'name': 'bucket-name'}"
671
625
)
672
626
673
- client = Client (project = PROJECT )
627
+ credentials = _make_credentials ()
628
+ client = self ._make_one (project = project , credentials = credentials )
674
629
client ._base_connection = connection
675
630
676
- bucket = client .create_bucket (BUCKET_NAME , location = LOCATION )
631
+ bucket = client .create_bucket (bucket_name , location = location )
677
632
678
633
connection .api_request .assert_called_once_with (
679
634
method = "POST" ,
680
635
path = "/b" ,
681
- data = DATA ,
636
+ data = data ,
682
637
_target_object = bucket ,
683
- query_params = {"project" : "PROJECT" },
638
+ query_params = {"project" : project },
684
639
)
685
- self .assertEqual (bucket .location , LOCATION )
640
+ self .assertEqual (bucket .location , location )
686
641
687
- def test_create_bucket_with_string_success (self ):
642
+ def test_create_bucket_w_string_success (self ):
688
643
from google .cloud .storage .bucket import Bucket
689
644
690
645
project = "PROJECT"
@@ -716,7 +671,7 @@ def test_create_bucket_with_string_success(self):
716
671
json_sent = http .request .call_args_list [0 ][1 ]["data" ]
717
672
self .assertEqual (json_expected , json .loads (json_sent ))
718
673
719
- def test_create_bucket_with_object_success (self ):
674
+ def test_create_bucket_w_object_success (self ):
720
675
from google .cloud .storage .bucket import Bucket
721
676
722
677
project = "PROJECT"
0 commit comments