@@ -171,19 +171,6 @@ def test_ctor_w_encryption_config(self):
171
171
self .assertIs (database ._instance , instance )
172
172
self .assertEqual (database ._encryption_config , encryption_config )
173
173
174
- def test_ctor_w_encryption_config_dict (self ):
175
- from google .cloud .spanner_admin_database_v1 import EncryptionConfig
176
-
177
- instance = _Instance (self .INSTANCE_NAME )
178
- encryption_config_dict = {"kms_key_name" : "kms_key" }
179
- encryption_config = EncryptionConfig (kms_key_name = "kms_key" )
180
- database = self ._make_one (
181
- self .DATABASE_ID , instance , encryption_config = encryption_config_dict
182
- )
183
- self .assertEqual (database .database_id , self .DATABASE_ID )
184
- self .assertIs (database ._instance , instance )
185
- self .assertEqual (database ._encryption_config , encryption_config )
186
-
187
174
def test_from_pb_bad_database_name (self ):
188
175
from google .cloud .spanner_admin_database_v1 import Database
189
176
@@ -532,15 +519,17 @@ def test_create_instance_not_found(self):
532
519
def test_create_success (self ):
533
520
from tests ._fixtures import DDL_STATEMENTS
534
521
from google .cloud .spanner_admin_database_v1 import CreateDatabaseRequest
522
+ from google .cloud .spanner_admin_database_v1 import EncryptionConfig
535
523
536
524
op_future = object ()
537
525
client = _Client ()
538
526
api = client .database_admin_api = self ._make_database_admin_api ()
539
527
api .create_database .return_value = op_future
540
528
instance = _Instance (self .INSTANCE_NAME , client = client )
541
529
pool = _Pool ()
530
+ encryption_config = EncryptionConfig (kms_key_name = "kms_key_name" )
542
531
database = self ._make_one (
543
- self .DATABASE_ID , instance , ddl_statements = DDL_STATEMENTS , pool = pool
532
+ self .DATABASE_ID , instance , ddl_statements = DDL_STATEMENTS , pool = pool , encryption_config = encryption_config
544
533
)
545
534
546
535
future = database .create ()
@@ -551,7 +540,40 @@ def test_create_success(self):
551
540
parent = self .INSTANCE_NAME ,
552
541
create_statement = "CREATE DATABASE {}" .format (self .DATABASE_ID ),
553
542
extra_statements = DDL_STATEMENTS ,
554
- encryption_config = None ,
543
+ encryption_config = encryption_config ,
544
+ )
545
+
546
+ api .create_database .assert_called_once_with (
547
+ request = expected_request ,
548
+ metadata = [("google-cloud-resource-prefix" , database .name )],
549
+ )
550
+
551
+ def test_create_success_w_encryption_config_dict (self ):
552
+ from tests ._fixtures import DDL_STATEMENTS
553
+ from google .cloud .spanner_admin_database_v1 import CreateDatabaseRequest
554
+ from google .cloud .spanner_admin_database_v1 import EncryptionConfig
555
+
556
+ op_future = object ()
557
+ client = _Client ()
558
+ api = client .database_admin_api = self ._make_database_admin_api ()
559
+ api .create_database .return_value = op_future
560
+ instance = _Instance (self .INSTANCE_NAME , client = client )
561
+ pool = _Pool ()
562
+ encryption_config = {"kms_key_name" : "kms_key_name" }
563
+ database = self ._make_one (
564
+ self .DATABASE_ID , instance , ddl_statements = DDL_STATEMENTS , pool = pool , encryption_config = encryption_config
565
+ )
566
+
567
+ future = database .create ()
568
+
569
+ self .assertIs (future , op_future )
570
+
571
+ expected_encryption_config = EncryptionConfig (** encryption_config )
572
+ expected_request = CreateDatabaseRequest (
573
+ parent = self .INSTANCE_NAME ,
574
+ create_statement = "CREATE DATABASE {}" .format (self .DATABASE_ID ),
575
+ extra_statements = DDL_STATEMENTS ,
576
+ encryption_config = expected_encryption_config ,
555
577
)
556
578
557
579
api .create_database .assert_called_once_with (
@@ -1172,6 +1194,7 @@ def test_restore_backup_unspecified(self):
1172
1194
1173
1195
def test_restore_grpc_error (self ):
1174
1196
from google .api_core .exceptions import Unknown
1197
+ from google .cloud .spanner_admin_database_v1 import RestoreDatabaseRequest
1175
1198
1176
1199
client = _Client ()
1177
1200
api = client .database_admin_api = self ._make_database_admin_api ()
@@ -1184,15 +1207,20 @@ def test_restore_grpc_error(self):
1184
1207
with self .assertRaises (Unknown ):
1185
1208
database .restore (backup )
1186
1209
1187
- api . restore_database . assert_called_once_with (
1210
+ expected_request = RestoreDatabaseRequest (
1188
1211
parent = self .INSTANCE_NAME ,
1189
1212
database_id = self .DATABASE_ID ,
1190
1213
backup = self .BACKUP_NAME ,
1214
+ )
1215
+
1216
+ api .restore_database .assert_called_once_with (
1217
+ request = expected_request ,
1191
1218
metadata = [("google-cloud-resource-prefix" , database .name )],
1192
1219
)
1193
1220
1194
1221
def test_restore_not_found (self ):
1195
1222
from google .api_core .exceptions import NotFound
1223
+ from google .cloud .spanner_admin_database_v1 import RestoreDatabaseRequest
1196
1224
1197
1225
client = _Client ()
1198
1226
api = client .database_admin_api = self ._make_database_admin_api ()
@@ -1205,31 +1233,84 @@ def test_restore_not_found(self):
1205
1233
with self .assertRaises (NotFound ):
1206
1234
database .restore (backup )
1207
1235
1208
- api . restore_database . assert_called_once_with (
1236
+ expected_request = RestoreDatabaseRequest (
1209
1237
parent = self .INSTANCE_NAME ,
1210
1238
database_id = self .DATABASE_ID ,
1211
1239
backup = self .BACKUP_NAME ,
1240
+ )
1241
+
1242
+ api .restore_database .assert_called_once_with (
1243
+ request = expected_request ,
1212
1244
metadata = [("google-cloud-resource-prefix" , database .name )],
1213
1245
)
1214
1246
1215
1247
def test_restore_success (self ):
1248
+ from google .cloud .spanner_admin_database_v1 import RestoreDatabaseEncryptionConfig
1249
+ from google .cloud .spanner_admin_database_v1 import RestoreDatabaseRequest
1250
+
1216
1251
op_future = object ()
1217
1252
client = _Client ()
1218
1253
api = client .database_admin_api = self ._make_database_admin_api ()
1219
1254
api .restore_database .return_value = op_future
1220
1255
instance = _Instance (self .INSTANCE_NAME , client = client )
1221
1256
pool = _Pool ()
1222
- database = self ._make_one (self .DATABASE_ID , instance , pool = pool )
1257
+ encryption_config = RestoreDatabaseEncryptionConfig (
1258
+ encryption_type = RestoreDatabaseEncryptionConfig .EncryptionType .CUSTOMER_MANAGED_ENCRYPTION ,
1259
+ kms_key_name = "kms_key_name"
1260
+ )
1261
+ database = self ._make_one (self .DATABASE_ID , instance , pool = pool , encryption_config = encryption_config )
1223
1262
backup = _Backup (self .BACKUP_NAME )
1224
1263
1225
1264
future = database .restore (backup )
1226
1265
1227
1266
self .assertIs (future , op_future )
1228
1267
1268
+ expected_request = RestoreDatabaseRequest (
1269
+ parent = self .INSTANCE_NAME ,
1270
+ database_id = self .DATABASE_ID ,
1271
+ backup = self .BACKUP_NAME ,
1272
+ encryption_config = encryption_config
1273
+ )
1274
+
1229
1275
api .restore_database .assert_called_once_with (
1276
+ request = expected_request ,
1277
+ metadata = [("google-cloud-resource-prefix" , database .name )],
1278
+ )
1279
+
1280
+ def test_restore_success_w_encryption_config_dict (self ):
1281
+ from google .cloud .spanner_admin_database_v1 import RestoreDatabaseEncryptionConfig
1282
+ from google .cloud .spanner_admin_database_v1 import RestoreDatabaseRequest
1283
+
1284
+ op_future = object ()
1285
+ client = _Client ()
1286
+ api = client .database_admin_api = self ._make_database_admin_api ()
1287
+ api .restore_database .return_value = op_future
1288
+ instance = _Instance (self .INSTANCE_NAME , client = client )
1289
+ pool = _Pool ()
1290
+ encryption_config = {
1291
+ 'encryption_type' : RestoreDatabaseEncryptionConfig .EncryptionType .CUSTOMER_MANAGED_ENCRYPTION ,
1292
+ 'kms_key_name' : 'kms_key_name'
1293
+ }
1294
+ database = self ._make_one (self .DATABASE_ID , instance , pool = pool , encryption_config = encryption_config )
1295
+ backup = _Backup (self .BACKUP_NAME )
1296
+
1297
+ future = database .restore (backup )
1298
+
1299
+ self .assertIs (future , op_future )
1300
+
1301
+ expected_encryption_config = RestoreDatabaseEncryptionConfig (
1302
+ encryption_type = RestoreDatabaseEncryptionConfig .EncryptionType .CUSTOMER_MANAGED_ENCRYPTION ,
1303
+ kms_key_name = "kms_key_name"
1304
+ )
1305
+ expected_request = RestoreDatabaseRequest (
1230
1306
parent = self .INSTANCE_NAME ,
1231
1307
database_id = self .DATABASE_ID ,
1232
1308
backup = self .BACKUP_NAME ,
1309
+ encryption_config = expected_encryption_config
1310
+ )
1311
+
1312
+ api .restore_database .assert_called_once_with (
1313
+ request = expected_request ,
1233
1314
metadata = [("google-cloud-resource-prefix" , database .name )],
1234
1315
)
1235
1316
0 commit comments