@@ -299,16 +299,23 @@ def _make_one(self, client=None, name=None, properties=None, user_project=None):
299
299
bucket ._properties = properties or {}
300
300
return bucket
301
301
302
+ def test_ctor_w_invalid_name (self ):
303
+ NAME = "#invalid"
304
+ with self .assertRaises (ValueError ):
305
+ self ._make_one (name = NAME )
306
+
302
307
def test_ctor (self ):
303
308
NAME = "name"
304
309
properties = {"key" : "value" }
305
310
bucket = self ._make_one (name = NAME , properties = properties )
306
311
self .assertEqual (bucket .name , NAME )
307
312
self .assertEqual (bucket ._properties , properties )
313
+ self .assertEqual (list (bucket ._changes ), [])
308
314
self .assertFalse (bucket ._acl .loaded )
309
315
self .assertIs (bucket ._acl .bucket , bucket )
310
316
self .assertFalse (bucket ._default_object_acl .loaded )
311
317
self .assertIs (bucket ._default_object_acl .bucket , bucket )
318
+ self .assertEqual (list (bucket ._label_removals ), [])
312
319
self .assertIsNone (bucket .user_project )
313
320
314
321
def test_ctor_w_user_project (self ):
@@ -319,11 +326,13 @@ def test_ctor_w_user_project(self):
319
326
bucket = self ._make_one (client , name = NAME , user_project = USER_PROJECT )
320
327
self .assertEqual (bucket .name , NAME )
321
328
self .assertEqual (bucket ._properties , {})
322
- self .assertEqual (bucket .user_project , USER_PROJECT )
329
+ self .assertEqual (list ( bucket ._changes ), [] )
323
330
self .assertFalse (bucket ._acl .loaded )
324
331
self .assertIs (bucket ._acl .bucket , bucket )
325
332
self .assertFalse (bucket ._default_object_acl .loaded )
326
333
self .assertIs (bucket ._default_object_acl .bucket , bucket )
334
+ self .assertEqual (list (bucket ._label_removals ), [])
335
+ self .assertEqual (bucket .user_project , USER_PROJECT )
327
336
328
337
def test_blob_wo_keys (self ):
329
338
from google .cloud .storage .blob import Blob
@@ -1496,6 +1505,47 @@ def test_labels_setter_with_removal(self):
1496
1505
_ , _ , kwargs = client ._connection .api_request .mock_calls [0 ]
1497
1506
self .assertNotIn ("labels" , kwargs ["data" ])
1498
1507
1508
+ def test_location_type_getter_unset (self ):
1509
+ bucket = self ._make_one ()
1510
+ self .assertIsNone (bucket .location_type )
1511
+
1512
+ def test_location_type_getter_set (self ):
1513
+ klass = self ._get_target_class ()
1514
+ properties = {"locationType" : klass .REGION_LOCATION_TYPE }
1515
+ bucket = self ._make_one (properties = properties )
1516
+ self .assertEqual (bucket .location_type , klass .REGION_LOCATION_TYPE )
1517
+
1518
+ def test_location_type_setter_invalid (self ):
1519
+ NAME = "name"
1520
+ bucket = self ._make_one (name = NAME )
1521
+ with self .assertRaises (ValueError ):
1522
+ bucket .location_type = "bogus"
1523
+ self .assertFalse ("locationType" in bucket ._changes )
1524
+
1525
+ def test_location_type_setter_MULTI_REGION (self ):
1526
+ klass = self ._get_target_class ()
1527
+ NAME = "name"
1528
+ bucket = self ._make_one (name = NAME )
1529
+ bucket .location_type = klass .MULTI_REGION_LOCATION_TYPE
1530
+ self .assertEqual (bucket .location_type , klass .MULTI_REGION_LOCATION_TYPE )
1531
+ self .assertTrue ("locationType" in bucket ._changes )
1532
+
1533
+ def test_location_type_setter_REGION (self ):
1534
+ klass = self ._get_target_class ()
1535
+ NAME = "name"
1536
+ bucket = self ._make_one (name = NAME )
1537
+ bucket .location_type = klass .REGION_LOCATION_TYPE
1538
+ self .assertEqual (bucket .location_type , klass .REGION_LOCATION_TYPE )
1539
+ self .assertTrue ("locationType" in bucket ._changes )
1540
+
1541
+ def test_location_type_setter_DUAL_REGION (self ):
1542
+ klass = self ._get_target_class ()
1543
+ NAME = "name"
1544
+ bucket = self ._make_one (name = NAME )
1545
+ bucket .location_type = klass .DUAL_REGION_LOCATION_TYPE
1546
+ self .assertEqual (bucket .location_type , klass .DUAL_REGION_LOCATION_TYPE )
1547
+ self .assertTrue ("locationType" in bucket ._changes )
1548
+
1499
1549
def test_get_logging_w_prefix (self ):
1500
1550
NAME = "name"
1501
1551
LOG_BUCKET = "logs"
@@ -1658,10 +1708,10 @@ def test_self_link(self):
1658
1708
self .assertEqual (bucket .self_link , SELF_LINK )
1659
1709
1660
1710
def test_storage_class_getter (self ):
1661
- STORAGE_CLASS = "http://example.com/ self/"
1662
- properties = {"storageClass" : STORAGE_CLASS }
1711
+ klass = self . _get_target_class ()
1712
+ properties = {"storageClass" : klass . NEARLINE_STORAGE_CLASS }
1663
1713
bucket = self ._make_one (properties = properties )
1664
- self .assertEqual (bucket .storage_class , STORAGE_CLASS )
1714
+ self .assertEqual (bucket .storage_class , klass . NEARLINE_STORAGE_CLASS )
1665
1715
1666
1716
def test_storage_class_setter_invalid (self ):
1667
1717
NAME = "name"
@@ -1671,45 +1721,56 @@ def test_storage_class_setter_invalid(self):
1671
1721
self .assertFalse ("storageClass" in bucket ._changes )
1672
1722
1673
1723
def test_storage_class_setter_STANDARD (self ):
1724
+ klass = self ._get_target_class ()
1674
1725
NAME = "name"
1675
1726
bucket = self ._make_one (name = NAME )
1676
- bucket .storage_class = "STANDARD"
1677
- self .assertEqual (bucket .storage_class , "STANDARD" )
1727
+ bucket .storage_class = klass . STANDARD_STORAGE_CLASS
1728
+ self .assertEqual (bucket .storage_class , klass . STANDARD_STORAGE_CLASS )
1678
1729
self .assertTrue ("storageClass" in bucket ._changes )
1679
1730
1680
1731
def test_storage_class_setter_NEARLINE (self ):
1732
+ klass = self ._get_target_class ()
1681
1733
NAME = "name"
1682
1734
bucket = self ._make_one (name = NAME )
1683
- bucket .storage_class = "NEARLINE"
1684
- self .assertEqual (bucket .storage_class , "NEARLINE" )
1735
+ bucket .storage_class = klass . NEARLINE_STORAGE_CLASS
1736
+ self .assertEqual (bucket .storage_class , klass . NEARLINE_STORAGE_CLASS )
1685
1737
self .assertTrue ("storageClass" in bucket ._changes )
1686
1738
1687
1739
def test_storage_class_setter_COLDLINE (self ):
1740
+ klass = self ._get_target_class ()
1688
1741
NAME = "name"
1689
1742
bucket = self ._make_one (name = NAME )
1690
- bucket .storage_class = "COLDLINE"
1691
- self .assertEqual (bucket .storage_class , "COLDLINE" )
1743
+ bucket .storage_class = klass . COLDLINE_STORAGE_CLASS
1744
+ self .assertEqual (bucket .storage_class , klass . COLDLINE_STORAGE_CLASS )
1692
1745
self .assertTrue ("storageClass" in bucket ._changes )
1693
1746
1694
1747
def test_storage_class_setter_MULTI_REGIONAL (self ):
1748
+ klass = self ._get_target_class ()
1695
1749
NAME = "name"
1696
1750
bucket = self ._make_one (name = NAME )
1697
- bucket .storage_class = "MULTI_REGIONAL"
1698
- self .assertEqual (bucket .storage_class , "MULTI_REGIONAL" )
1751
+ bucket .storage_class = klass .MULTI_REGIONAL_LEGACY_STORAGE_CLASS
1752
+ self .assertEqual (
1753
+ bucket .storage_class , klass .MULTI_REGIONAL_LEGACY_STORAGE_CLASS
1754
+ )
1699
1755
self .assertTrue ("storageClass" in bucket ._changes )
1700
1756
1701
1757
def test_storage_class_setter_REGIONAL (self ):
1758
+ klass = self ._get_target_class ()
1702
1759
NAME = "name"
1703
1760
bucket = self ._make_one (name = NAME )
1704
- bucket .storage_class = "REGIONAL"
1705
- self .assertEqual (bucket .storage_class , "REGIONAL" )
1761
+ bucket .storage_class = klass . REGIONAL_LEGACY_STORAGE_CLASS
1762
+ self .assertEqual (bucket .storage_class , klass . REGIONAL_LEGACY_STORAGE_CLASS )
1706
1763
self .assertTrue ("storageClass" in bucket ._changes )
1707
1764
1708
1765
def test_storage_class_setter_DURABLE_REDUCED_AVAILABILITY (self ):
1766
+ klass = self ._get_target_class ()
1709
1767
NAME = "name"
1710
1768
bucket = self ._make_one (name = NAME )
1711
- bucket .storage_class = "DURABLE_REDUCED_AVAILABILITY"
1712
- self .assertEqual (bucket .storage_class , "DURABLE_REDUCED_AVAILABILITY" )
1769
+ bucket .storage_class = klass .DURABLE_REDUCED_AVAILABILITY_LEGACY_STORAGE_CLASS
1770
+ self .assertEqual (
1771
+ bucket .storage_class ,
1772
+ klass .DURABLE_REDUCED_AVAILABILITY_LEGACY_STORAGE_CLASS ,
1773
+ )
1713
1774
self .assertTrue ("storageClass" in bucket ._changes )
1714
1775
1715
1776
def test_time_created (self ):
0 commit comments