@@ -72,6 +72,7 @@ def test_constructor_defaults(self):
7272 self .assertIsNone (instance .labels )
7373 self .assertIs (instance ._client , client )
7474 self .assertIsNone (instance .state )
75+ self .assertIsNone (instance .create_time )
7576
7677 def test_constructor_non_default (self ):
7778 from google .cloud .bigtable import enums
@@ -95,19 +96,34 @@ def test_constructor_non_default(self):
9596 self .assertEqual (instance .labels , labels )
9697 self .assertIs (instance ._client , client )
9798 self .assertEqual (instance .state , state )
99+ self .assertIsNone (instance .create_time )
100+
101+ @staticmethod
102+ def _make_timestamp_pb ():
103+ import datetime
104+ from google .protobuf import timestamp_pb2
105+
106+ now = datetime .datetime .utcnow ().replace (tzinfo = datetime .timezone .utc )
107+ seconds = int (now .timestamp ())
108+ nanos = int ((now .timestamp () - seconds ) * 1e9 )
109+ return timestamp_pb2 .Timestamp (seconds = seconds , nanos = nanos )
98110
99111 def test__update_from_pb_success (self ):
112+ import datetime
113+ from google .api_core .datetime_helpers import DatetimeWithNanoseconds
100114 from google .cloud .bigtable_admin_v2 .types import instance as data_v2_pb2
101115 from google .cloud .bigtable import enums
102116
103117 instance_type = data_v2_pb2 .Instance .Type .PRODUCTION
104118 state = enums .Instance .State .READY
119+ timestamp = self ._make_timestamp_pb ()
105120 # todo type to type_?
106121 instance_pb = data_v2_pb2 .Instance (
107122 display_name = self .DISPLAY_NAME ,
108123 type_ = instance_type ,
109124 labels = self .LABELS ,
110125 state = state ,
126+ create_time = timestamp ,
111127 )
112128
113129 instance = self ._make_one (None , None )
@@ -119,6 +135,8 @@ def test__update_from_pb_success(self):
119135 self .assertEqual (instance .type_ , instance_type )
120136 self .assertEqual (instance .labels , self .LABELS )
121137 self .assertEqual (instance ._state , state )
138+ expected_dt = DatetimeWithNanoseconds .from_timestamp_pb (timestamp )
139+ self .assertEqual ( instance .create_time , expected_dt )
122140
123141 def test__update_from_pb_success_defaults (self ):
124142 from google .cloud .bigtable_admin_v2 .types import instance as data_v2_pb2
@@ -134,6 +152,7 @@ def test__update_from_pb_success_defaults(self):
134152 self .assertEqual (instance .display_name , self .DISPLAY_NAME )
135153 self .assertEqual (instance .type_ , enums .Instance .Type .UNSPECIFIED )
136154 self .assertFalse (instance .labels )
155+ self .assertIsNone (instance .create_time )
137156
138157 def test__update_from_pb_no_display_name (self ):
139158 from google .cloud .bigtable_admin_v2 .types import instance as data_v2_pb2
@@ -145,6 +164,7 @@ def test__update_from_pb_no_display_name(self):
145164 instance ._update_from_pb (instance_pb )
146165
147166 def test_from_pb_success (self ):
167+ from google .api_core .datetime_helpers import DatetimeWithNanoseconds
148168 from google .cloud .bigtable_admin_v2 .types import instance as data_v2_pb2
149169 from google .cloud .bigtable import enums
150170
@@ -154,12 +174,14 @@ def test_from_pb_success(self):
154174 )
155175 instance_type = enums .Instance .Type .PRODUCTION
156176 state = enums .Instance .State .READY
177+ timestamp = self ._make_timestamp_pb ()
157178 instance_pb = data_v2_pb2 .Instance (
158179 name = self .INSTANCE_NAME ,
159180 display_name = self .INSTANCE_ID ,
160181 type_ = instance_type ,
161182 labels = self .LABELS ,
162183 state = state ,
184+ created_time = timestamp ,
163185 )
164186
165187 klass = self ._get_target_class ()
@@ -171,6 +193,8 @@ def test_from_pb_success(self):
171193 self .assertEqual (instance .type_ , instance_type )
172194 self .assertEqual (instance .labels , self .LABELS )
173195 self .assertEqual (instance ._state , state )
196+ expected_dt = DatetimeWithNanoseconds .from_timestamp_pb (timestamp )
197+ self .assertEqual ( instance .create_time , expected_dt )
174198
175199 def test_from_pb_bad_instance_name (self ):
176200 from google .cloud .bigtable_admin_v2 .types import instance as data_v2_pb2
0 commit comments