@@ -157,20 +157,6 @@ def test_ctor_w_encryption_config(self):
157
157
self .assertIs (database ._instance , instance )
158
158
self .assertEqual (database ._encryption_config , encryption_config )
159
159
160
- def test_ctor_w_encryption_config_dict (self ):
161
- from google .cloud .spanner_admin_database_v1 import EncryptionConfig
162
-
163
- instance = _Instance (self .INSTANCE_NAME )
164
- encryption_config_dict = {"kms_key_name" : "kms_key" }
165
- encryption_config = EncryptionConfig (kms_key_name = "kms_key" )
166
- database = self ._make_one (
167
- self .DATABASE_ID , instance , encryption_config = encryption_config_dict
168
- )
169
- self .assertEqual (database .database_id , self .DATABASE_ID )
170
- self .assertIs (database ._instance , instance )
171
- self .assertEqual (database ._encryption_config , encryption_config )
172
-
173
-
174
160
def test_from_pb_bad_database_name (self ):
175
161
from google .cloud .spanner_admin_database_v1 import Database
176
162
@@ -487,15 +473,17 @@ def test_create_instance_not_found(self):
487
473
def test_create_success (self ):
488
474
from tests ._fixtures import DDL_STATEMENTS
489
475
from google .cloud .spanner_admin_database_v1 import CreateDatabaseRequest
476
+ from google .cloud .spanner_admin_database_v1 import EncryptionConfig
490
477
491
478
op_future = object ()
492
479
client = _Client ()
493
480
api = client .database_admin_api = self ._make_database_admin_api ()
494
481
api .create_database .return_value = op_future
495
482
instance = _Instance (self .INSTANCE_NAME , client = client )
496
483
pool = _Pool ()
484
+ encryption_config = EncryptionConfig (kms_key_name = "kms_key_name" )
497
485
database = self ._make_one (
498
- self .DATABASE_ID , instance , ddl_statements = DDL_STATEMENTS , pool = pool
486
+ self .DATABASE_ID , instance , ddl_statements = DDL_STATEMENTS , pool = pool , encryption_config = encryption_config
499
487
)
500
488
501
489
future = database .create ()
@@ -506,7 +494,40 @@ def test_create_success(self):
506
494
parent = self .INSTANCE_NAME ,
507
495
create_statement = "CREATE DATABASE {}" .format (self .DATABASE_ID ),
508
496
extra_statements = DDL_STATEMENTS ,
509
- encryption_config = None ,
497
+ encryption_config = encryption_config ,
498
+ )
499
+
500
+ api .create_database .assert_called_once_with (
501
+ request = expected_request ,
502
+ metadata = [("google-cloud-resource-prefix" , database .name )],
503
+ )
504
+
505
+ def test_create_success_w_encryption_config_dict (self ):
506
+ from tests ._fixtures import DDL_STATEMENTS
507
+ from google .cloud .spanner_admin_database_v1 import CreateDatabaseRequest
508
+ from google .cloud .spanner_admin_database_v1 import EncryptionConfig
509
+
510
+ op_future = object ()
511
+ client = _Client ()
512
+ api = client .database_admin_api = self ._make_database_admin_api ()
513
+ api .create_database .return_value = op_future
514
+ instance = _Instance (self .INSTANCE_NAME , client = client )
515
+ pool = _Pool ()
516
+ encryption_config = {"kms_key_name" : "kms_key_name" }
517
+ database = self ._make_one (
518
+ self .DATABASE_ID , instance , ddl_statements = DDL_STATEMENTS , pool = pool , encryption_config = encryption_config
519
+ )
520
+
521
+ future = database .create ()
522
+
523
+ self .assertIs (future , op_future )
524
+
525
+ expected_encryption_config = EncryptionConfig (** encryption_config )
526
+ expected_request = CreateDatabaseRequest (
527
+ parent = self .INSTANCE_NAME ,
528
+ create_statement = "CREATE DATABASE {}" .format (self .DATABASE_ID ),
529
+ extra_statements = DDL_STATEMENTS ,
530
+ encryption_config = expected_encryption_config ,
510
531
)
511
532
512
533
api .create_database .assert_called_once_with (
@@ -1123,6 +1144,7 @@ def test_restore_backup_unspecified(self):
1123
1144
1124
1145
def test_restore_grpc_error (self ):
1125
1146
from google .api_core .exceptions import Unknown
1147
+ from google .cloud .spanner_admin_database_v1 import RestoreDatabaseRequest
1126
1148
1127
1149
client = _Client ()
1128
1150
api = client .database_admin_api = self ._make_database_admin_api ()
@@ -1135,15 +1157,20 @@ def test_restore_grpc_error(self):
1135
1157
with self .assertRaises (Unknown ):
1136
1158
database .restore (backup )
1137
1159
1138
- api . restore_database . assert_called_once_with (
1160
+ expected_request = RestoreDatabaseRequest (
1139
1161
parent = self .INSTANCE_NAME ,
1140
1162
database_id = self .DATABASE_ID ,
1141
1163
backup = self .BACKUP_NAME ,
1164
+ )
1165
+
1166
+ api .restore_database .assert_called_once_with (
1167
+ request = expected_request ,
1142
1168
metadata = [("google-cloud-resource-prefix" , database .name )],
1143
1169
)
1144
1170
1145
1171
def test_restore_not_found (self ):
1146
1172
from google .api_core .exceptions import NotFound
1173
+ from google .cloud .spanner_admin_database_v1 import RestoreDatabaseRequest
1147
1174
1148
1175
client = _Client ()
1149
1176
api = client .database_admin_api = self ._make_database_admin_api ()
@@ -1156,31 +1183,84 @@ def test_restore_not_found(self):
1156
1183
with self .assertRaises (NotFound ):
1157
1184
database .restore (backup )
1158
1185
1159
- api . restore_database . assert_called_once_with (
1186
+ expected_request = RestoreDatabaseRequest (
1160
1187
parent = self .INSTANCE_NAME ,
1161
1188
database_id = self .DATABASE_ID ,
1162
1189
backup = self .BACKUP_NAME ,
1190
+ )
1191
+
1192
+ api .restore_database .assert_called_once_with (
1193
+ request = expected_request ,
1163
1194
metadata = [("google-cloud-resource-prefix" , database .name )],
1164
1195
)
1165
1196
1166
1197
def test_restore_success (self ):
1198
+ from google .cloud .spanner_admin_database_v1 import RestoreDatabaseEncryptionConfig
1199
+ from google .cloud .spanner_admin_database_v1 import RestoreDatabaseRequest
1200
+
1167
1201
op_future = object ()
1168
1202
client = _Client ()
1169
1203
api = client .database_admin_api = self ._make_database_admin_api ()
1170
1204
api .restore_database .return_value = op_future
1171
1205
instance = _Instance (self .INSTANCE_NAME , client = client )
1172
1206
pool = _Pool ()
1173
- database = self ._make_one (self .DATABASE_ID , instance , pool = pool )
1207
+ encryption_config = RestoreDatabaseEncryptionConfig (
1208
+ encryption_type = RestoreDatabaseEncryptionConfig .EncryptionType .CUSTOMER_MANAGED_ENCRYPTION ,
1209
+ kms_key_name = "kms_key_name"
1210
+ )
1211
+ database = self ._make_one (self .DATABASE_ID , instance , pool = pool , encryption_config = encryption_config )
1174
1212
backup = _Backup (self .BACKUP_NAME )
1175
1213
1176
1214
future = database .restore (backup )
1177
1215
1178
1216
self .assertIs (future , op_future )
1179
1217
1218
+ expected_request = RestoreDatabaseRequest (
1219
+ parent = self .INSTANCE_NAME ,
1220
+ database_id = self .DATABASE_ID ,
1221
+ backup = self .BACKUP_NAME ,
1222
+ encryption_config = encryption_config
1223
+ )
1224
+
1180
1225
api .restore_database .assert_called_once_with (
1226
+ request = expected_request ,
1227
+ metadata = [("google-cloud-resource-prefix" , database .name )],
1228
+ )
1229
+
1230
+ def test_restore_success_w_encryption_config_dict (self ):
1231
+ from google .cloud .spanner_admin_database_v1 import RestoreDatabaseEncryptionConfig
1232
+ from google .cloud .spanner_admin_database_v1 import RestoreDatabaseRequest
1233
+
1234
+ op_future = object ()
1235
+ client = _Client ()
1236
+ api = client .database_admin_api = self ._make_database_admin_api ()
1237
+ api .restore_database .return_value = op_future
1238
+ instance = _Instance (self .INSTANCE_NAME , client = client )
1239
+ pool = _Pool ()
1240
+ encryption_config = {
1241
+ 'encryption_type' : RestoreDatabaseEncryptionConfig .EncryptionType .CUSTOMER_MANAGED_ENCRYPTION ,
1242
+ 'kms_key_name' : 'kms_key_name'
1243
+ }
1244
+ database = self ._make_one (self .DATABASE_ID , instance , pool = pool , encryption_config = encryption_config )
1245
+ backup = _Backup (self .BACKUP_NAME )
1246
+
1247
+ future = database .restore (backup )
1248
+
1249
+ self .assertIs (future , op_future )
1250
+
1251
+ expected_encryption_config = RestoreDatabaseEncryptionConfig (
1252
+ encryption_type = RestoreDatabaseEncryptionConfig .EncryptionType .CUSTOMER_MANAGED_ENCRYPTION ,
1253
+ kms_key_name = "kms_key_name"
1254
+ )
1255
+ expected_request = RestoreDatabaseRequest (
1181
1256
parent = self .INSTANCE_NAME ,
1182
1257
database_id = self .DATABASE_ID ,
1183
1258
backup = self .BACKUP_NAME ,
1259
+ encryption_config = expected_encryption_config
1260
+ )
1261
+
1262
+ api .restore_database .assert_called_once_with (
1263
+ request = expected_request ,
1184
1264
metadata = [("google-cloud-resource-prefix" , database .name )],
1185
1265
)
1186
1266
0 commit comments