@@ -72,6 +72,63 @@ def test_blob(self):
7272 self .assertEqual (blob .chunk_size , CHUNK_SIZE )
7373 self .assertEqual (blob ._encryption_key , KEY )
7474
75+ def test_notification_defaults (self ):
76+ from google .cloud .storage .notification import BucketNotification
77+
78+ PROJECT = 'PROJECT'
79+ BUCKET_NAME = 'BUCKET_NAME'
80+ TOPIC_NAME = 'TOPIC_NAME'
81+ client = _Client (_Connection (), project = PROJECT )
82+ bucket = self ._make_one (client , name = BUCKET_NAME )
83+
84+ notification = bucket .notification (TOPIC_NAME )
85+
86+ self .assertIsInstance (notification , BucketNotification )
87+ self .assertIs (notification .bucket , bucket )
88+ self .assertEqual (notification .topic_project , PROJECT )
89+ self .assertIsNone (notification .custom_attributes )
90+ self .assertIsNone (notification .event_types )
91+ self .assertIsNone (notification .blob_name_prefix )
92+ self .assertIsNone (notification .payload_format )
93+
94+ def test_notification_explicit (self ):
95+ from google .cloud .storage .notification import (
96+ BucketNotification ,
97+ OBJECT_FINALIZE_EVENT_TYPE ,
98+ OBJECT_DELETE_EVENT_TYPE ,
99+ JSON_API_V1_PAYLOAD_FORMAT )
100+
101+ PROJECT = 'PROJECT'
102+ BUCKET_NAME = 'BUCKET_NAME'
103+ TOPIC_NAME = 'TOPIC_NAME'
104+ TOPIC_ALT_PROJECT = 'topic-project-456'
105+ CUSTOM_ATTRIBUTES = {
106+ 'attr1' : 'value1' ,
107+ 'attr2' : 'value2' ,
108+ }
109+ EVENT_TYPES = [OBJECT_FINALIZE_EVENT_TYPE , OBJECT_DELETE_EVENT_TYPE ]
110+ BLOB_NAME_PREFIX = 'blob-name-prefix/'
111+ client = _Client (_Connection (), project = PROJECT )
112+ bucket = self ._make_one (client , name = BUCKET_NAME )
113+
114+ notification = bucket .notification (
115+ TOPIC_NAME ,
116+ topic_project = TOPIC_ALT_PROJECT ,
117+ custom_attributes = CUSTOM_ATTRIBUTES ,
118+ event_types = EVENT_TYPES ,
119+ blob_name_prefix = BLOB_NAME_PREFIX ,
120+ payload_format = JSON_API_V1_PAYLOAD_FORMAT ,
121+ )
122+
123+ self .assertIsInstance (notification , BucketNotification )
124+ self .assertIs (notification .bucket , bucket )
125+ self .assertEqual (notification .topic_project , TOPIC_ALT_PROJECT )
126+ self .assertEqual (notification .custom_attributes , CUSTOM_ATTRIBUTES )
127+ self .assertEqual (notification .event_types , EVENT_TYPES )
128+ self .assertEqual (notification .blob_name_prefix , BLOB_NAME_PREFIX )
129+ self .assertEqual (
130+ notification .payload_format , JSON_API_V1_PAYLOAD_FORMAT )
131+
75132 def test_bucket_name_value (self ):
76133 bucket_name = 'testing123'
77134 mixin = self ._make_one (name = bucket_name )
0 commit comments