forked from googleapis/python-bigtable
/
test_app_profile.py
706 lines (587 loc) · 27 KB
/
test_app_profile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
# Copyright 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import mock
from ._testing import _make_credentials
class MultiCallableStub(object):
"""Stub for the grpc.UnaryUnaryMultiCallable interface."""
def __init__(self, method, channel_stub):
self.method = method
self.channel_stub = channel_stub
def __call__(self, request, timeout=None, metadata=None, credentials=None):
self.channel_stub.requests.append((self.method, request))
return self.channel_stub.responses.pop()
class ChannelStub(object):
"""Stub for the grpc.Channel interface."""
def __init__(self, responses=[]):
self.responses = responses
self.requests = []
def unary_unary(self, method, request_serializer=None, response_deserializer=None):
return MultiCallableStub(method, self)
class TestAppProfile(unittest.TestCase):
PROJECT = "project"
INSTANCE_ID = "instance-id"
APP_PROFILE_ID = "app-profile-id"
APP_PROFILE_NAME = "projects/{}/instances/{}/appProfiles/{}".format(
PROJECT, INSTANCE_ID, APP_PROFILE_ID
)
CLUSTER_ID = "cluster-id"
OP_ID = 8765
OP_NAME = "operations/projects/{}/instances/{}/appProfiles/{}/operations/{}".format(
PROJECT, INSTANCE_ID, APP_PROFILE_ID, OP_ID
)
@staticmethod
def _get_target_class():
from google.cloud.bigtable.app_profile import AppProfile
return AppProfile
def _make_one(self, *args, **kwargs):
return self._get_target_class()(*args, **kwargs)
@staticmethod
def _get_target_client_class():
from google.cloud.bigtable.client import Client
return Client
def _make_client(self, *args, **kwargs):
return self._get_target_client_class()(*args, **kwargs)
def test_constructor_defaults(self):
client = _Client(self.PROJECT)
instance = _Instance(self.INSTANCE_ID, client)
app_profile = self._make_one(self.APP_PROFILE_ID, instance)
self.assertIsInstance(app_profile, self._get_target_class())
self.assertEqual(app_profile._instance, instance)
self.assertIsNone(app_profile.routing_policy_type)
self.assertIsNone(app_profile.description)
self.assertIsNone(app_profile.cluster_id)
self.assertIsNone(app_profile.allow_transactional_writes)
def test_constructor_non_defaults(self):
from google.cloud.bigtable.enums import RoutingPolicyType
ANY = RoutingPolicyType.ANY
DESCRIPTION_1 = "routing policy any"
APP_PROFILE_ID_2 = "app-profile-id-2"
SINGLE = RoutingPolicyType.SINGLE
DESCRIPTION_2 = "routing policy single"
ALLOW_WRITES = True
client = _Client(self.PROJECT)
instance = _Instance(self.INSTANCE_ID, client)
app_profile1 = self._make_one(
self.APP_PROFILE_ID,
instance,
routing_policy_type=ANY,
description=DESCRIPTION_1,
)
app_profile2 = self._make_one(
APP_PROFILE_ID_2,
instance,
routing_policy_type=SINGLE,
description=DESCRIPTION_2,
cluster_id=self.CLUSTER_ID,
allow_transactional_writes=ALLOW_WRITES,
)
self.assertEqual(app_profile1.app_profile_id, self.APP_PROFILE_ID)
self.assertIs(app_profile1._instance, instance)
self.assertEqual(app_profile1.routing_policy_type, ANY)
self.assertEqual(app_profile1.description, DESCRIPTION_1)
self.assertEqual(app_profile2.app_profile_id, APP_PROFILE_ID_2)
self.assertIs(app_profile2._instance, instance)
self.assertEqual(app_profile2.routing_policy_type, SINGLE)
self.assertEqual(app_profile2.description, DESCRIPTION_2)
self.assertEqual(app_profile2.cluster_id, self.CLUSTER_ID)
self.assertEqual(app_profile2.allow_transactional_writes, ALLOW_WRITES)
def test_name_property(self):
credentials = _make_credentials()
client = self._make_client(
project=self.PROJECT, credentials=credentials, admin=True
)
instance = _Instance(self.INSTANCE_ID, client)
app_profile = self._make_one(self.APP_PROFILE_ID, instance)
self.assertEqual(app_profile.name, self.APP_PROFILE_NAME)
def test___eq__(self):
client = _Client(self.PROJECT)
instance = _Instance(self.INSTANCE_ID, client)
app_profile1 = self._make_one(self.APP_PROFILE_ID, instance)
app_profile2 = self._make_one(self.APP_PROFILE_ID, instance)
self.assertTrue(app_profile1 == app_profile2)
def test___eq__type_instance_differ(self):
client = _Client(self.PROJECT)
instance = _Instance(self.INSTANCE_ID, client)
alt_instance = _Instance("other-instance", client)
other_object = _Other(self.APP_PROFILE_ID, instance)
app_profile1 = self._make_one(self.APP_PROFILE_ID, instance)
app_profile2 = self._make_one(self.APP_PROFILE_ID, alt_instance)
self.assertFalse(app_profile1 == other_object)
self.assertFalse(app_profile1 == app_profile2)
def test___ne__same_value(self):
client = _Client(self.PROJECT)
instance = _Instance(self.INSTANCE_ID, client)
app_profile1 = self._make_one(self.APP_PROFILE_ID, instance)
app_profile2 = self._make_one(self.APP_PROFILE_ID, instance)
self.assertFalse(app_profile1 != app_profile2)
def test___ne__(self):
client = _Client(self.PROJECT)
instance = _Instance(self.INSTANCE_ID, client)
app_profile1 = self._make_one("app_profile_id1", instance)
app_profile2 = self._make_one("app_profile_id2", instance)
self.assertTrue(app_profile1 != app_profile2)
def test_from_pb_success_routing_any(self):
from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2
from google.cloud.bigtable.enums import RoutingPolicyType
client = _Client(self.PROJECT)
instance = _Instance(self.INSTANCE_ID, client)
desctiption = "routing any"
routing = RoutingPolicyType.ANY
multi_cluster_routing_use_any = (
data_v2_pb2.AppProfile.MultiClusterRoutingUseAny()
)
app_profile_pb = data_v2_pb2.AppProfile(
name=self.APP_PROFILE_NAME,
description=desctiption,
multi_cluster_routing_use_any=multi_cluster_routing_use_any,
)
klass = self._get_target_class()
app_profile = klass.from_pb(app_profile_pb, instance)
self.assertIsInstance(app_profile, klass)
self.assertIs(app_profile._instance, instance)
self.assertEqual(app_profile.app_profile_id, self.APP_PROFILE_ID)
self.assertEqual(app_profile.description, desctiption)
self.assertEqual(app_profile.routing_policy_type, routing)
self.assertIsNone(app_profile.cluster_id)
self.assertEqual(app_profile.allow_transactional_writes, False)
def test_from_pb_success_routing_single(self):
from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2
from google.cloud.bigtable.enums import RoutingPolicyType
client = _Client(self.PROJECT)
instance = _Instance(self.INSTANCE_ID, client)
desctiption = "routing single"
allow_transactional_writes = True
routing = RoutingPolicyType.SINGLE
single_cluster_routing = data_v2_pb2.AppProfile.SingleClusterRouting(
cluster_id=self.CLUSTER_ID,
allow_transactional_writes=allow_transactional_writes,
)
app_profile_pb = data_v2_pb2.AppProfile(
name=self.APP_PROFILE_NAME,
description=desctiption,
single_cluster_routing=single_cluster_routing,
)
klass = self._get_target_class()
app_profile = klass.from_pb(app_profile_pb, instance)
self.assertIsInstance(app_profile, klass)
self.assertIs(app_profile._instance, instance)
self.assertEqual(app_profile.app_profile_id, self.APP_PROFILE_ID)
self.assertEqual(app_profile.description, desctiption)
self.assertEqual(app_profile.routing_policy_type, routing)
self.assertEqual(app_profile.cluster_id, self.CLUSTER_ID)
self.assertEqual(
app_profile.allow_transactional_writes, allow_transactional_writes
)
def test_from_pb_bad_app_profile_name(self):
from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2
bad_app_profile_name = "BAD_NAME"
app_profile_pb = data_v2_pb2.AppProfile(name=bad_app_profile_name)
klass = self._get_target_class()
with self.assertRaises(ValueError):
klass.from_pb(app_profile_pb, None)
def test_from_pb_instance_id_mistmatch(self):
from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2
ALT_INSTANCE_ID = "ALT_INSTANCE_ID"
client = _Client(self.PROJECT)
instance = _Instance(ALT_INSTANCE_ID, client)
self.assertEqual(instance.instance_id, ALT_INSTANCE_ID)
app_profile_pb = data_v2_pb2.AppProfile(name=self.APP_PROFILE_NAME)
klass = self._get_target_class()
with self.assertRaises(ValueError):
klass.from_pb(app_profile_pb, instance)
def test_from_pb_project_mistmatch(self):
from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2
ALT_PROJECT = "ALT_PROJECT"
client = _Client(project=ALT_PROJECT)
instance = _Instance(self.INSTANCE_ID, client)
self.assertEqual(client.project, ALT_PROJECT)
app_profile_pb = data_v2_pb2.AppProfile(name=self.APP_PROFILE_NAME)
klass = self._get_target_class()
with self.assertRaises(ValueError):
klass.from_pb(app_profile_pb, instance)
def test_reload_routing_any(self):
from google.cloud.bigtable_admin_v2.services.bigtable_instance_admin import (
BigtableInstanceAdminClient,
)
from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2
from google.cloud.bigtable.enums import RoutingPolicyType
api = mock.create_autospec(BigtableInstanceAdminClient)
credentials = _make_credentials()
client = self._make_client(
project=self.PROJECT, credentials=credentials, admin=True
)
instance = _Instance(self.INSTANCE_ID, client)
routing = RoutingPolicyType.ANY
description = "routing policy any"
app_profile = self._make_one(
self.APP_PROFILE_ID,
instance,
routing_policy_type=routing,
description=description,
)
# Create response_pb
description_from_server = "routing policy switched to single"
cluster_id_from_server = self.CLUSTER_ID
allow_transactional_writes = True
single_cluster_routing = data_v2_pb2.AppProfile.SingleClusterRouting(
cluster_id=cluster_id_from_server,
allow_transactional_writes=allow_transactional_writes,
)
response_pb = data_v2_pb2.AppProfile(
name=app_profile.name,
single_cluster_routing=single_cluster_routing,
description=description_from_server,
)
# Patch the stub used by the API method.
client._instance_admin_client = api
instance_stub = client._instance_admin_client
instance_stub.get_app_profile.side_effect = [response_pb]
# Create expected_result.
expected_result = None # reload() has no return value.
# Check app_profile config values before.
self.assertEqual(app_profile.routing_policy_type, routing)
self.assertEqual(app_profile.description, description)
self.assertIsNone(app_profile.cluster_id)
self.assertIsNone(app_profile.allow_transactional_writes)
# Perform the method and check the result.
result = app_profile.reload()
self.assertEqual(result, expected_result)
self.assertEqual(app_profile.routing_policy_type, RoutingPolicyType.SINGLE)
self.assertEqual(app_profile.description, description_from_server)
self.assertEqual(app_profile.cluster_id, cluster_id_from_server)
self.assertEqual(
app_profile.allow_transactional_writes, allow_transactional_writes
)
def test_exists(self):
from google.cloud.bigtable_admin_v2.services.bigtable_instance_admin import (
BigtableInstanceAdminClient,
)
from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2
from google.api_core import exceptions
instance_api = mock.create_autospec(BigtableInstanceAdminClient)
credentials = _make_credentials()
client = self._make_client(
project=self.PROJECT, credentials=credentials, admin=True
)
instance = client.instance(self.INSTANCE_ID)
# Create response_pb
response_pb = data_v2_pb2.AppProfile(name=self.APP_PROFILE_NAME)
client._instance_admin_client = instance_api
# Patch the stub used by the API method.
client._instance_admin_client = instance_api
instance_stub = client._instance_admin_client
instance_stub.get_app_profile.side_effect = [
response_pb,
exceptions.NotFound("testing"),
exceptions.BadRequest("testing"),
]
# Perform the method and check the result.
non_existing_app_profile_id = "other-app-profile-id"
app_profile = self._make_one(self.APP_PROFILE_ID, instance)
alt_app_profile = self._make_one(non_existing_app_profile_id, instance)
self.assertTrue(app_profile.exists())
self.assertFalse(alt_app_profile.exists())
with self.assertRaises(exceptions.BadRequest):
alt_app_profile.exists()
def test_create_routing_any(self):
from google.cloud.bigtable.enums import RoutingPolicyType
from google.cloud.bigtable_admin_v2.services.bigtable_instance_admin import (
BigtableInstanceAdminClient,
)
credentials = _make_credentials()
client = self._make_client(
project=self.PROJECT, credentials=credentials, admin=True
)
instance = client.instance(self.INSTANCE_ID)
routing = RoutingPolicyType.ANY
description = "routing policy any"
ignore_warnings = True
app_profile = self._make_one(
self.APP_PROFILE_ID,
instance,
routing_policy_type=routing,
description=description,
)
expected_request_app_profile = app_profile._to_pb()
name = instance.name
expected_request = {
"request": {
"parent": name,
"app_profile_id": self.APP_PROFILE_ID,
"app_profile": expected_request_app_profile,
"ignore_warnings": ignore_warnings,
}
}
instance_api = mock.create_autospec(BigtableInstanceAdminClient)
instance_api.app_profile_path.return_value = (
"projects/project/instances/instance-id/appProfiles/app-profile-id"
)
instance_api.instance_path.return_value = name
instance_api.create_app_profile.return_value = expected_request_app_profile
# Patch the stub used by the API method.
client._instance_admin_client = instance_api
app_profile._instance._client._instance_admin_client = instance_api
# Perform the method and check the result.
result = app_profile.create(ignore_warnings)
actual_request = client._instance_admin_client.create_app_profile.call_args_list[
0
].kwargs
self.assertEqual(actual_request, expected_request)
self.assertIsInstance(result, self._get_target_class())
self.assertEqual(result.app_profile_id, self.APP_PROFILE_ID)
self.assertIs(result._instance, instance)
self.assertEqual(result.routing_policy_type, routing)
self.assertEqual(result.description, description)
self.assertEqual(result.allow_transactional_writes, False)
self.assertIsNone(result.cluster_id)
def test_create_routing_single(self):
from google.cloud.bigtable.enums import RoutingPolicyType
from google.cloud.bigtable_admin_v2.services.bigtable_instance_admin import (
BigtableInstanceAdminClient,
)
credentials = _make_credentials()
client = self._make_client(
project=self.PROJECT, credentials=credentials, admin=True
)
instance = client.instance(self.INSTANCE_ID)
routing = RoutingPolicyType.SINGLE
description = "routing policy single"
allow_writes = False
ignore_warnings = True
app_profile = self._make_one(
self.APP_PROFILE_ID,
instance,
routing_policy_type=routing,
description=description,
cluster_id=self.CLUSTER_ID,
allow_transactional_writes=allow_writes,
)
expected_request_app_profile = app_profile._to_pb()
instance_name = instance.name
expected_request = {
"request": {
"parent": instance_name,
"app_profile_id": self.APP_PROFILE_ID,
"app_profile": expected_request_app_profile,
"ignore_warnings": ignore_warnings,
}
}
# Patch the stub used by the API method.
instance_api = mock.create_autospec(BigtableInstanceAdminClient)
instance_api.app_profile_path.return_value = (
"projects/project/instances/instance-id/appProfiles/app-profile-id"
)
instance_api.instance_path.return_value = instance_name
instance_api.create_app_profile.return_value = expected_request_app_profile
client._instance_admin_client = instance_api
# Perform the method and check the result.
result = app_profile.create(ignore_warnings)
actual_request = client._instance_admin_client.create_app_profile.call_args_list[
0
].kwargs
self.assertEqual(actual_request, expected_request)
self.assertIsInstance(result, self._get_target_class())
self.assertEqual(result.app_profile_id, self.APP_PROFILE_ID)
self.assertIs(result._instance, instance)
self.assertEqual(result.routing_policy_type, routing)
self.assertEqual(result.description, description)
self.assertEqual(result.allow_transactional_writes, allow_writes)
self.assertEqual(result.cluster_id, self.CLUSTER_ID)
def test_create_app_profile_with_wrong_routing_policy(self):
credentials = _make_credentials()
client = self._make_client(
project=self.PROJECT, credentials=credentials, admin=True
)
instance = client.instance(self.INSTANCE_ID)
app_profile = self._make_one(
self.APP_PROFILE_ID, instance, routing_policy_type=None
)
with self.assertRaises(ValueError):
app_profile.create()
def test_update_app_profile_routing_any(self):
from google.longrunning import operations_pb2
from google.protobuf.any_pb2 import Any
from google.cloud.bigtable_admin_v2.types import (
bigtable_instance_admin as messages_v2_pb2,
)
from google.cloud.bigtable.enums import RoutingPolicyType
from google.cloud.bigtable_admin_v2.services.bigtable_instance_admin import (
BigtableInstanceAdminClient,
)
from google.protobuf import field_mask_pb2
credentials = _make_credentials()
client = self._make_client(
project=self.PROJECT, credentials=credentials, admin=True
)
instance = client.instance(self.INSTANCE_ID)
routing = RoutingPolicyType.SINGLE
description = "to routing policy single"
allow_writes = True
app_profile = self._make_one(
self.APP_PROFILE_ID,
instance,
routing_policy_type=routing,
description=description,
cluster_id=self.CLUSTER_ID,
allow_transactional_writes=allow_writes,
)
# Create response_pb
metadata = messages_v2_pb2.UpdateAppProfileMetadata()
type_url = "type.googleapis.com/{}".format(
messages_v2_pb2.UpdateAppProfileMetadata._meta._pb.DESCRIPTOR.full_name
)
response_pb = operations_pb2.Operation(
name=self.OP_NAME,
metadata=Any(type_url=type_url, value=metadata._pb.SerializeToString()),
)
# Patch the stub used by the API method.
instance_api = mock.create_autospec(BigtableInstanceAdminClient)
# Mock api calls
instance_api.app_profile_path.return_value = (
"projects/project/instances/instance-id/appProfiles/app-profile-id"
)
client._instance_admin_client = instance_api
# Perform the method and check the result.
ignore_warnings = True
expected_request_update_mask = field_mask_pb2.FieldMask(
paths=["description", "single_cluster_routing"]
)
expected_request = {
"request": {
"app_profile": app_profile._to_pb(),
"update_mask": expected_request_update_mask,
"ignore_warnings": ignore_warnings,
}
}
instance_api.update_app_profile.return_value = response_pb
app_profile._instance._client._instance_admin_client = instance_api
result = app_profile.update(ignore_warnings=ignore_warnings)
actual_request = client._instance_admin_client.update_app_profile.call_args_list[
0
].kwargs
self.assertEqual(actual_request, expected_request)
self.assertEqual(
result.metadata.type_url,
"type.googleapis.com/google.bigtable.admin.v2.UpdateAppProfileMetadata",
)
def test_update_app_profile_routing_single(self):
from google.longrunning import operations_pb2
from google.protobuf.any_pb2 import Any
from google.cloud.bigtable_admin_v2.types import (
bigtable_instance_admin as messages_v2_pb2,
)
from google.cloud.bigtable.enums import RoutingPolicyType
from google.cloud.bigtable_admin_v2.services.bigtable_instance_admin import (
BigtableInstanceAdminClient,
)
from google.protobuf import field_mask_pb2
credentials = _make_credentials()
client = self._make_client(
project=self.PROJECT, credentials=credentials, admin=True
)
instance = client.instance(self.INSTANCE_ID)
routing = RoutingPolicyType.ANY
app_profile = self._make_one(
self.APP_PROFILE_ID, instance, routing_policy_type=routing
)
# Create response_pb
metadata = messages_v2_pb2.UpdateAppProfileMetadata()
type_url = "type.googleapis.com/{}".format(
messages_v2_pb2.UpdateAppProfileMetadata._meta._pb.DESCRIPTOR.full_name
)
response_pb = operations_pb2.Operation(
name=self.OP_NAME,
metadata=Any(type_url=type_url, value=metadata._pb.SerializeToString()),
)
# Patch the stub used by the API method.
instance_api = mock.create_autospec(BigtableInstanceAdminClient)
# Mock api calls
instance_api.app_profile_path.return_value = (
"projects/project/instances/instance-id/appProfiles/app-profile-id"
)
client._instance_admin_client = instance_api
client._instance_admin_client.update_app_profile.return_value = response_pb
# Perform the method and check the result.
ignore_warnings = True
expected_request_update_mask = field_mask_pb2.FieldMask(
paths=["multi_cluster_routing_use_any"]
)
expected_request = {
"request": {
"app_profile": app_profile._to_pb(),
"update_mask": expected_request_update_mask,
"ignore_warnings": ignore_warnings,
}
}
result = app_profile.update(ignore_warnings=ignore_warnings)
actual_request = client._instance_admin_client.update_app_profile.call_args_list[
0
].kwargs
self.assertEqual(actual_request, expected_request)
self.assertEqual(
result.metadata.type_url,
"type.googleapis.com/google.bigtable.admin.v2.UpdateAppProfileMetadata",
)
def test_update_app_profile_with_wrong_routing_policy(self):
credentials = _make_credentials()
client = self._make_client(
project=self.PROJECT, credentials=credentials, admin=True
)
instance = client.instance(self.INSTANCE_ID)
app_profile = self._make_one(
self.APP_PROFILE_ID, instance, routing_policy_type=None
)
with self.assertRaises(ValueError):
app_profile.update()
def test_delete(self):
from google.protobuf import empty_pb2
from google.cloud.bigtable_admin_v2.services.bigtable_instance_admin import (
BigtableInstanceAdminClient,
)
instance_api = mock.create_autospec(BigtableInstanceAdminClient)
credentials = _make_credentials()
client = self._make_client(
project=self.PROJECT, credentials=credentials, admin=True
)
instance = client.instance(self.INSTANCE_ID)
app_profile = self._make_one(self.APP_PROFILE_ID, instance)
# Create response_pb
response_pb = empty_pb2.Empty()
# Patch the stub used by the API method.
client._instance_admin_client = instance_api
instance_stub = client._instance_admin_client.transport
instance_stub.delete_cluster.side_effect = [response_pb]
# Create expected_result.
expected_result = None # delete() has no return value.
# Perform the method and check the result.
result = app_profile.delete()
self.assertEqual(result, expected_result)
class _Client(object):
def __init__(self, project):
self.project = project
self.project_name = "projects/" + self.project
self._operations_stub = mock.sentinel.operations_stub
def __eq__(self, other):
return other.project == self.project and other.project_name == self.project_name
class _Instance(object):
def __init__(self, instance_id, client):
self.instance_id = instance_id
self._client = client
def __eq__(self, other):
return other.instance_id == self.instance_id and other._client == self._client
class _Other(object):
def __init__(self, app_profile_id, instance):
self.app_profile_id = app_profile_id
self._instance = instance