@@ -62,18 +62,53 @@ def test_ctor_defaults(self):
62
62
self .assertIsNone (backup ._expire_time )
63
63
64
64
def test_ctor_non_defaults (self ):
65
+ from google .cloud .spanner_admin_database_v1 import CreateBackupEncryptionConfig
65
66
instance = _Instance (self .INSTANCE_NAME )
66
67
timestamp = self ._make_timestamp ()
67
68
69
+ encryption_config = CreateBackupEncryptionConfig (
70
+ encryption_type = CreateBackupEncryptionConfig .EncryptionType .CUSTOMER_MANAGED_ENCRYPTION ,
71
+ kms_key_name = "key_name"
72
+ )
68
73
backup = self ._make_one (
69
- self .BACKUP_ID , instance , database = self .DATABASE_NAME , expire_time = timestamp
74
+ self .BACKUP_ID ,
75
+ instance ,
76
+ database = self .DATABASE_NAME ,
77
+ expire_time = timestamp ,
78
+ encryption_config = encryption_config
79
+ )
80
+
81
+ self .assertEqual (backup .backup_id , self .BACKUP_ID )
82
+ self .assertIs (backup ._instance , instance )
83
+ self .assertEqual (backup ._database , self .DATABASE_NAME )
84
+ self .assertIsNotNone (backup ._expire_time )
85
+ self .assertIs (backup ._expire_time , timestamp )
86
+ self .assertEqual (backup .encryption_config , encryption_config )
87
+
88
+ def test_ctor_w_encryption_config_dict (self ):
89
+ from google .cloud .spanner_admin_database_v1 import CreateBackupEncryptionConfig
90
+ instance = _Instance (self .INSTANCE_NAME )
91
+ timestamp = self ._make_timestamp ()
92
+
93
+ encryption_config = {
94
+ "encryption_type" : 3 ,
95
+ "kms_key_name" : "key_name"
96
+ }
97
+ backup = self ._make_one (
98
+ self .BACKUP_ID ,
99
+ instance ,
100
+ database = self .DATABASE_NAME ,
101
+ expire_time = timestamp ,
102
+ encryption_config = encryption_config
70
103
)
104
+ expected_encryption_config = CreateBackupEncryptionConfig (** encryption_config )
71
105
72
106
self .assertEqual (backup .backup_id , self .BACKUP_ID )
73
107
self .assertIs (backup ._instance , instance )
74
108
self .assertEqual (backup ._database , self .DATABASE_NAME )
75
109
self .assertIsNotNone (backup ._expire_time )
76
110
self .assertIs (backup ._expire_time , timestamp )
111
+ self .assertEqual (backup .encryption_config , expected_encryption_config )
77
112
78
113
def test_from_pb_project_mismatch (self ):
79
114
from google .cloud .spanner_admin_database_v1 import Backup
@@ -180,10 +215,22 @@ def test_encrpytion_info_property(self):
180
215
)
181
216
self .assertEqual (backup .encryption_info , expected )
182
217
218
+ def test_encryption_config_property (self ):
219
+ from google .cloud .spanner_admin_database_v1 import CreateBackupEncryptionConfig
220
+
221
+ instance = _Instance (self .INSTANCE_NAME )
222
+ backup = self ._make_one (self .BACKUP_ID , instance )
223
+ expected = backup ._encryption_config = CreateBackupEncryptionConfig (
224
+ encryption_type = CreateBackupEncryptionConfig .EncryptionType .CUSTOMER_MANAGED_ENCRYPTION ,
225
+ kms_key_name = "kms_key_name"
226
+ )
227
+ self .assertEqual (backup .encryption_config , expected )
228
+
183
229
def test_create_grpc_error (self ):
184
230
from google .api_core .exceptions import GoogleAPICallError
185
231
from google .api_core .exceptions import Unknown
186
232
from google .cloud .spanner_admin_database_v1 import Backup
233
+ from google .cloud .spanner_admin_database_v1 import CreateBackupRequest
187
234
188
235
client = _Client ()
189
236
api = client .database_admin_api = self ._make_database_admin_api ()
@@ -200,16 +247,21 @@ def test_create_grpc_error(self):
200
247
with self .assertRaises (GoogleAPICallError ):
201
248
backup .create ()
202
249
203
- api . create_backup . assert_called_once_with (
250
+ request = CreateBackupRequest (
204
251
parent = self .INSTANCE_NAME ,
205
252
backup_id = self .BACKUP_ID ,
206
253
backup = backup_pb ,
254
+ )
255
+
256
+ api .create_backup .assert_called_once_with (
257
+ request = request ,
207
258
metadata = [("google-cloud-resource-prefix" , backup .name )],
208
259
)
209
260
210
261
def test_create_already_exists (self ):
211
262
from google .cloud .exceptions import Conflict
212
263
from google .cloud .spanner_admin_database_v1 import Backup
264
+ from google .cloud .spanner_admin_database_v1 import CreateBackupRequest
213
265
214
266
client = _Client ()
215
267
api = client .database_admin_api = self ._make_database_admin_api ()
@@ -226,16 +278,21 @@ def test_create_already_exists(self):
226
278
with self .assertRaises (Conflict ):
227
279
backup .create ()
228
280
229
- api . create_backup . assert_called_once_with (
281
+ request = CreateBackupRequest (
230
282
parent = self .INSTANCE_NAME ,
231
283
backup_id = self .BACKUP_ID ,
232
284
backup = backup_pb ,
285
+ )
286
+
287
+ api .create_backup .assert_called_once_with (
288
+ request = request ,
233
289
metadata = [("google-cloud-resource-prefix" , backup .name )],
234
290
)
235
291
236
292
def test_create_instance_not_found (self ):
237
293
from google .cloud .exceptions import NotFound
238
294
from google .cloud .spanner_admin_database_v1 import Backup
295
+ from google .cloud .spanner_admin_database_v1 import CreateBackupRequest
239
296
240
297
client = _Client ()
241
298
api = client .database_admin_api = self ._make_database_admin_api ()
@@ -252,10 +309,14 @@ def test_create_instance_not_found(self):
252
309
with self .assertRaises (NotFound ):
253
310
backup .create ()
254
311
255
- api . create_backup . assert_called_once_with (
312
+ request = CreateBackupRequest (
256
313
parent = self .INSTANCE_NAME ,
257
314
backup_id = self .BACKUP_ID ,
258
315
backup = backup_pb ,
316
+ )
317
+
318
+ api .create_backup .assert_called_once_with (
319
+ request = request ,
259
320
metadata = [("google-cloud-resource-prefix" , backup .name )],
260
321
)
261
322
@@ -276,6 +337,8 @@ def test_create_database_not_set(self):
276
337
277
338
def test_create_success (self ):
278
339
from google .cloud .spanner_admin_database_v1 import Backup
340
+ from google .cloud .spanner_admin_database_v1 import CreateBackupRequest
341
+ from google .cloud .spanner_admin_database_v1 import CreateBackupEncryptionConfig
279
342
from datetime import datetime
280
343
from datetime import timedelta
281
344
from pytz import UTC
@@ -289,12 +352,17 @@ def test_create_success(self):
289
352
version_timestamp = datetime .utcnow () - timedelta (minutes = 5 )
290
353
version_timestamp = version_timestamp .replace (tzinfo = UTC )
291
354
expire_timestamp = self ._make_timestamp ()
355
+ encryption_config = {
356
+ "encryption_type" : 3 ,
357
+ "kms_key_name" : "key_name"
358
+ }
292
359
backup = self ._make_one (
293
360
self .BACKUP_ID ,
294
361
instance ,
295
362
database = self .DATABASE_NAME ,
296
363
expire_time = expire_timestamp ,
297
364
version_time = version_timestamp ,
365
+ encryption_config = encryption_config
298
366
)
299
367
300
368
backup_pb = Backup (
@@ -306,10 +374,16 @@ def test_create_success(self):
306
374
future = backup .create ()
307
375
self .assertIs (future , op_future )
308
376
309
- api .create_backup .assert_called_once_with (
377
+ expected_encryption_config = CreateBackupEncryptionConfig (** encryption_config )
378
+ request = CreateBackupRequest (
310
379
parent = self .INSTANCE_NAME ,
311
380
backup_id = self .BACKUP_ID ,
312
381
backup = backup_pb ,
382
+ encryption_config = expected_encryption_config
383
+ )
384
+
385
+ api .create_backup .assert_called_once_with (
386
+ request = request ,
313
387
metadata = [("google-cloud-resource-prefix" , backup .name )],
314
388
)
315
389
0 commit comments