3939
4040LOCATION_ID = 'us-central1-c'
4141INSTANCE_ID = 'g-c-p' + unique_resource_id ('-' )
42- LABELS = {u'foo' : u'bar' }
4342TABLE_ID = 'google-cloud-python-test-table'
4443CLUSTER_ID = INSTANCE_ID + '-cluster'
4544SERVE_NODES = 3
5756ROUTING_POLICY_TYPE_ANY = 1
5857ROUTING_POLICY_TYPE_SINGLE = 2
5958EXISTING_INSTANCES = []
59+ LABEL_KEY = u'python-system'
60+ label_stamp = datetime .datetime .utcnow () \
61+ .replace (microsecond = 0 , tzinfo = UTC ,) \
62+ .strftime ("%Y-%m-%dt%H-%M-%S" )
63+ LABELS = {LABEL_KEY : str (label_stamp )}
6064
6165
6266class Config (object ):
@@ -150,7 +154,7 @@ def test_create_instance_defaults(self):
150154 from google .cloud .bigtable import enums
151155
152156 ALT_INSTANCE_ID = 'ndef' + unique_resource_id ('-' )
153- instance = Config .CLIENT .instance (ALT_INSTANCE_ID )
157+ instance = Config .CLIENT .instance (ALT_INSTANCE_ID , labels = LABELS )
154158 ALT_CLUSTER_ID = ALT_INSTANCE_ID + '-cluster'
155159 cluster = instance .cluster (
156160 ALT_CLUSTER_ID , location_id = LOCATION_ID , serve_nodes = SERVE_NODES )
@@ -170,8 +174,6 @@ def test_create_instance_defaults(self):
170174 # Make sure that by default a PRODUCTION type instance is created
171175 self .assertIsNone (instance .type_ )
172176 self .assertEqual (instance_alt .type_ , enums .Instance .Type .PRODUCTION )
173- self .assertIsNone (instance .labels )
174- self .assertFalse (instance_alt .labels )
175177
176178 def test_create_instance (self ):
177179 from google .cloud .bigtable import enums
@@ -214,7 +216,8 @@ def test_create_instance_w_two_clusters(self):
214216 _PRODUCTION = enums .Instance .Type .PRODUCTION
215217 ALT_INSTANCE_ID = 'dif' + unique_resource_id ('-' )
216218 instance = Config .CLIENT .instance (ALT_INSTANCE_ID ,
217- instance_type = _PRODUCTION )
219+ instance_type = _PRODUCTION ,
220+ labels = LABELS )
218221
219222 ALT_CLUSTER_ID_1 = ALT_INSTANCE_ID + '-c1'
220223 ALT_CLUSTER_ID_2 = ALT_INSTANCE_ID + '-c2'
@@ -261,7 +264,11 @@ def test_create_instance_w_two_clusters(self):
261264 def test_update_display_name_and_labels (self ):
262265 OLD_DISPLAY_NAME = Config .INSTANCE .display_name
263266 NEW_DISPLAY_NAME = 'Foo Bar Baz'
264- NEW_LABELS = {'foo_bar' : 'foo_bar' }
267+ n_label_stamp = datetime .datetime .utcnow () \
268+ .replace (microsecond = 0 , tzinfo = UTC ) \
269+ .strftime ("%Y-%m-%dt%H-%M-%S" )
270+
271+ NEW_LABELS = {LABEL_KEY : str (n_label_stamp )}
265272 Config .INSTANCE .display_name = NEW_DISPLAY_NAME
266273 Config .INSTANCE .labels = NEW_LABELS
267274 operation = Config .INSTANCE .update ()
@@ -291,9 +298,10 @@ def test_update_type(self):
291298
292299 _DEVELOPMENT = Instance .Type .DEVELOPMENT
293300 _PRODUCTION = Instance .Type .PRODUCTION
294- ALT_INSTANCE_ID = 'new ' + unique_resource_id ('-' )
301+ ALT_INSTANCE_ID = 'ndif ' + unique_resource_id ('-' )
295302 instance = Config .CLIENT .instance (ALT_INSTANCE_ID ,
296- instance_type = _DEVELOPMENT )
303+ instance_type = _DEVELOPMENT ,
304+ labels = LABELS )
297305 operation = instance .create (location_id = LOCATION_ID , serve_nodes = None )
298306 # Make sure this instance gets deleted after the test case.
299307 self .instances_to_delete .append (instance )
0 commit comments