@@ -111,6 +111,79 @@ def test_ctor_explicit(self):
111111 self .assertEqual (
112112 notification .payload_format , self .payload_format ())
113113
114+ def test_from_api_repr_no_topic (self ):
115+ klass = self ._get_target_class ()
116+ client = self ._make_client ()
117+ bucket = self ._make_bucket (client )
118+ resource = {}
119+
120+ with self .assertRaises (ValueError ):
121+ klass .from_api_repr (resource , bucket = bucket )
122+
123+ def test_from_api_repr_invalid_topic (self ):
124+ klass = self ._get_target_class ()
125+ client = self ._make_client ()
126+ bucket = self ._make_bucket (client )
127+ resource = {
128+ 'topic' : '@#$%' ,
129+ }
130+
131+ with self .assertRaises (ValueError ):
132+ klass .from_api_repr (resource , bucket = bucket )
133+
134+ def test_from_api_repr_minimal (self ):
135+ klass = self ._get_target_class ()
136+ client = self ._make_client ()
137+ bucket = self ._make_bucket (client )
138+ resource = {
139+ 'topic' : self .TOPIC_REF ,
140+ 'id' : self .NOTIFICATION_ID ,
141+ 'etag' : self .ETAG ,
142+ 'selfLink' : self .SELF_LINK ,
143+ }
144+
145+ notification = klass .from_api_repr (resource , bucket = bucket )
146+
147+ self .assertIs (notification .bucket , bucket )
148+ self .assertEqual (notification .topic_name , self .TOPIC_NAME )
149+ self .assertEqual (notification .topic_project , self .BUCKET_PROJECT )
150+ self .assertIsNone (notification .custom_attributes )
151+ self .assertIsNone (notification .event_types )
152+ self .assertIsNone (notification .blob_name_prefix )
153+ self .assertIsNone (notification .payload_format )
154+ self .assertEqual (notification .etag , self .ETAG )
155+ self .assertEqual (notification .self_link , self .SELF_LINK )
156+
157+ def test_from_api_repr_explicit (self ):
158+ klass = self ._get_target_class ()
159+ client = self ._make_client ()
160+ bucket = self ._make_bucket (client )
161+ resource = {
162+ 'topic' : self .TOPIC_ALT_REF ,
163+ 'custom_attributes' : self .CUSTOM_ATTRIBUTES ,
164+ 'event_types' : self .event_types (),
165+ 'blob_name_prefix' : self .BLOB_NAME_PREFIX ,
166+ 'payload_format' : self .payload_format (),
167+ 'id' : self .NOTIFICATION_ID ,
168+ 'etag' : self .ETAG ,
169+ 'selfLink' : self .SELF_LINK ,
170+ }
171+
172+ notification = klass .from_api_repr (resource , bucket = bucket )
173+
174+ self .assertIs (notification .bucket , bucket )
175+ self .assertEqual (notification .topic_name , self .TOPIC_NAME )
176+ self .assertEqual (notification .topic_project , self .TOPIC_ALT_PROJECT )
177+ self .assertEqual (
178+ notification .custom_attributes , self .CUSTOM_ATTRIBUTES )
179+ self .assertEqual (notification .event_types , self .event_types ())
180+ self .assertEqual (notification .blob_name_prefix , self .BLOB_NAME_PREFIX )
181+ self .assertEqual (
182+ notification .payload_format , self .payload_format ())
183+ self .assertEqual (notification .notification_id , self .NOTIFICATION_ID )
184+ self .assertEqual (notification .etag , self .ETAG )
185+ self .assertEqual (notification .self_link , self .SELF_LINK )
186+
114187 def test_notification_id (self ):
115188 client = self ._make_client ()
116189 bucket = self ._make_bucket (client )
0 commit comments