4444UNIQUE_SUFFIX = unique_resource_id ("-" )
4545INSTANCE_ID = "snippet-tests" + UNIQUE_SUFFIX
4646CLUSTER_ID = "clus-1-" + UNIQUE_SUFFIX
47+ APP_PROFILE_ID = "app-prof" + UNIQUE_SUFFIX
48+ ROUTING_POLICY_TYPE = enums .RoutingPolicyType .ANY
4749LOCATION_ID = "us-central1-f"
4850ALT_LOCATION_ID = "us-central1-a"
4951PRODUCTION = enums .Instance .Type .PRODUCTION
@@ -167,19 +169,22 @@ def test_bigtable_create_additional_cluster():
167169 retry_429 (cluster .delete )()
168170
169171
170- def test_bigtable_create_app_profile ():
172+ def test_bigtable_create_reload_delete_app_profile ():
173+ import re
174+
171175 # [START bigtable_create_app_profile]
172176 from google .cloud .bigtable import Client
177+ from google .cloud .bigtable import enums
178+
179+ routing_policy_type = enums .RoutingPolicyType .ANY
173180
174181 client = Client (admin = True )
175182 instance = client .instance (INSTANCE_ID )
176183
177- app_profile_id = "app-prof-" + UNIQUE_SUFFIX
178184 description = "routing policy-multy"
179- routing_policy_type = enums .RoutingPolicyType .ANY
180185
181186 app_profile = instance .app_profile (
182- app_profile_id = app_profile_id ,
187+ app_profile_id = APP_PROFILE_ID ,
183188 routing_policy_type = routing_policy_type ,
184189 description = description ,
185190 cluster_id = CLUSTER_ID ,
@@ -188,10 +193,70 @@ def test_bigtable_create_app_profile():
188193 app_profile = app_profile .create (ignore_warnings = True )
189194 # [END bigtable_create_app_profile]
190195
191- try :
192- assert app_profile .exists ()
193- finally :
194- retry_429 (app_profile .delete )(ignore_warnings = True )
196+ # [START bigtable_app_profile_name]
197+ from google .cloud .bigtable import Client
198+
199+ client = Client (admin = True )
200+ instance = client .instance (INSTANCE_ID )
201+ app_profile = instance .app_profile (APP_PROFILE_ID )
202+
203+ app_profile_name = app_profile .name
204+ # [END bigtable_app_profile_name]
205+ _profile_name_re = re .compile (
206+ r"^projects/(?P<project>[^/]+)/"
207+ r"instances/(?P<instance>[^/]+)/"
208+ r"appProfiles/(?P<appprofile_id>"
209+ r"[_a-zA-Z0-9][-_.a-zA-Z0-9]*)$"
210+ )
211+ assert _profile_name_re .match (app_profile_name )
212+
213+ # [START bigtable_app_profile_exists]
214+ from google .cloud .bigtable import Client
215+
216+ client = Client (admin = True )
217+ instance = client .instance (INSTANCE_ID )
218+ app_profile = instance .app_profile (APP_PROFILE_ID )
219+
220+ app_profile_exists = app_profile .exists ()
221+ # [END bigtable_app_profile_exists]
222+ assert app_profile_exists
223+
224+ # [START bigtable_reload_app_profile]
225+ from google .cloud .bigtable import Client
226+
227+ client = Client (admin = True )
228+ instance = client .instance (INSTANCE_ID )
229+ app_profile = instance .app_profile (APP_PROFILE_ID )
230+
231+ app_profile .reload ()
232+ # [END bigtable_reload_app_profile]
233+ assert app_profile .routing_policy_type == ROUTING_POLICY_TYPE
234+
235+ # [START bigtable_update_app_profile]
236+ from google .cloud .bigtable import Client
237+
238+ client = Client (admin = True )
239+ instance = client .instance (INSTANCE_ID )
240+ app_profile = instance .app_profile (APP_PROFILE_ID )
241+ app_profile .reload ()
242+
243+ description = "My new app profile"
244+ app_profile .description = description
245+ app_profile .update ()
246+ # [END bigtable_update_app_profile]
247+ assert app_profile .description == description
248+
249+ # [START bigtable_delete_app_profile]
250+ from google .cloud .bigtable import Client
251+
252+ client = Client (admin = True )
253+ instance = client .instance (INSTANCE_ID )
254+ app_profile = instance .app_profile (APP_PROFILE_ID )
255+ app_profile .reload ()
256+
257+ app_profile .delete (ignore_warnings = True )
258+ # [END bigtable_delete_app_profile]
259+ assert not app_profile .exists ()
195260
196261
197262def test_bigtable_list_instances ():
0 commit comments