-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathtest_service.py
More file actions
856 lines (714 loc) · 26 KB
/
test_service.py
File metadata and controls
856 lines (714 loc) · 26 KB
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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
import json
from unittest import mock
import click
import pytest
from cumulusci.cli.runtime import CliRuntime
from cumulusci.cli.service import get_sensitive_service_attributes, get_service_data
from cumulusci.core.config import ServiceConfig
from cumulusci.core.exceptions import ServiceNotConfigured
from cumulusci.core.runtime import BaseCumulusCI
from cumulusci.core.tests.utils import EnvironmentVarGuard
from .utils import run_cli_command
@mock.patch("cumulusci.cli.service.CliTable")
def test_service_list(table_mock):
runtime = BaseCumulusCI(
config={
"services": {
"bad": {"description": "Unconfigured Service"},
"test": {"description": "Test Service"},
"something_else": {"description": "something else"},
}
}
)
runtime.keychain.config["services"] = {
"test": {"test_alias": ServiceConfig({}), "test2_alias": ServiceConfig({})},
"bad": {"bad_alias": ServiceConfig({})},
}
runtime.keychain._default_services = {"test": "test_alias", "bad": "bad_alias"}
run_cli_command("service", "list", runtime=runtime)
table_mock.assert_called_once_with(
[
["Default", "Type", "Name", "Description"],
[True, "bad", "bad_alias", "Unconfigured Service"],
[False, "something_else", "", "something else"],
[False, "test", "test2_alias", "Test Service"],
[True, "test", "test_alias", "Test Service"],
],
title="Services",
dim_rows=[2],
)
def test_service_list__json():
expected_services = {
"bad": {"description": "Unconfigured Service"},
"test": {"description": "Test Service"},
}
runtime = BaseCumulusCI(config={"services": expected_services})
result = run_cli_command("service", "list", "--json", runtime=runtime)
result_json = json.loads(result.output)
# I don't think this is actually very useful...
assert result_json == expected_services
def test_service_connect__list_service_types():
runtime = BaseCumulusCI(config={"services": {"project_test": {}}})
result = run_cli_command("service", "connect", runtime=runtime)
assert "project_test" in result.output
def test_service_connect__list_service_types_from_universal_config():
runtime = BaseCumulusCI()
runtime.project_config = None
runtime.universal_config.config["services"] = {"universal_test": {}}
result = run_cli_command("service", "connect", runtime=runtime)
assert "universal_test" in result.output
def test_service_connect():
runtime = BaseCumulusCI(
config={"services": {"test": {"attributes": {"attr": {"required": False}}}}}
)
run_cli_command("service", "connect", "test", "test-alias", runtime=runtime)
assert "test-alias" in runtime.keychain.list_services()["test"]
def test_service_connect__attr_with_default_value():
runtime = BaseCumulusCI(
config={
"services": {
"test": {
"attributes": {
"attr": {"default": "PRESET", "description": "example"}
}
}
}
},
)
result = run_cli_command(
"service", "connect", "test", "test-alias", runtime=runtime, input="\n"
)
# User should have been prompted to override the default,
# but input of an empty line accepts the default.
assert "attr (example) [PRESET]: " in result.output
service_config = runtime.keychain.get_service("test", "test-alias")
with (
mock.patch("cumulusci.core.config.base_config.STRICT_GETATTR", False),
pytest.warns(DeprecationWarning, match="attr"),
):
assert service_config.lookup("attr") == "PRESET"
assert service_config.attr == "PRESET"
def test_service_connect__attr_with_default_factory():
runtime = BaseCumulusCI(
config={
"services": {
"test": {
"attributes": {
"attr": {
"default_factory": "cumulusci.cli.tests.test_service.get_default"
}
}
}
}
},
)
run_cli_command("service", "connect", "test", "test-alias", runtime=runtime)
# The service should have the attribute value returned by the default factory.
service_config = runtime.keychain.get_service("test", "test-alias")
with (
mock.patch("cumulusci.core.config.base_config.STRICT_GETATTR", False),
pytest.warns(DeprecationWarning, match="attr"),
):
assert service_config.lookup("attr") == "CALCULATED"
assert service_config.attr == "CALCULATED"
def test_service_connect__alias_already_exists():
runtime = BaseCumulusCI(
config={
"services": {"test-type": {"attributes": {"attr": {"required": True}}}}
},
)
runtime.keychain.set_service(
"test-type", "already-exists", ServiceConfig({"attr": "old"})
)
run_cli_command(
"service",
"connect",
"test-type",
"already-exists",
runtime=runtime,
input="new\ny\nn\n",
)
service_config = runtime.keychain.get_service("test-type", "already-exists")
with (
mock.patch("cumulusci.core.config.base_config.STRICT_GETATTR", False),
pytest.warns(DeprecationWarning, match="attr"),
):
assert service_config.lookup("attr") == "new"
assert service_config.attr == "new"
def test_service_connect__set_new_service_as_default():
runtime = BaseCumulusCI(
config={
"services": {"test-type": {"attributes": {"attr": {"required": False}}}}
}
)
runtime.keychain.set_service("test-type", "existing-service", ServiceConfig({}))
run_cli_command(
"service", "connect", "test-type", "new-service", runtime=runtime, input="y\n"
)
assert runtime.keychain.get_default_service_name("test-type") == "new-service"
def test_service_connect__do_not_set_new_service_as_default():
runtime = BaseCumulusCI(
config={
"services": {"test-type": {"attributes": {"attr": {"required": False}}}}
}
)
runtime.keychain.set_service("test-type", "existing-service", ServiceConfig({}))
run_cli_command(
"service", "connect", "test-type", "new-service", input="n\n", runtime=runtime
)
assert runtime.keychain.get_default_service_name("test-type") == "existing-service"
def test_service_connect__no_name_given():
runtime = BaseCumulusCI(
config={
"services": {"test-type": {"attributes": {"attr": {"required": False}}}}
}
)
result = run_cli_command("service", "connect", "test-type", runtime=runtime)
# service_name is None, so the alias when setting the service should be 'default'
assert (
"No service name specified. Using 'default' as the service name."
in result.output
)
assert "default" in runtime.keychain.list_services()["test-type"]
def test_service_connect__global_default():
runtime = BaseCumulusCI(
config={"services": {"test": {"attributes": {"attr": {"required": False}}}}}
)
result = run_cli_command(
"service", "connect", "test", "test-alias", "--default", runtime=runtime
)
assert "Service test:test-alias is now connected" in result.output
assert (
"Service test:test-alias is now the default for all CumulusCI projects"
in result.output
)
def test_service_connect__project_default():
runtime = BaseCumulusCI(
config={"services": {"test": {"attributes": {"attr": {"required": False}}}}}
)
result = run_cli_command(
"service", "connect", "test", "test-alias", "--project", runtime=runtime
)
assert "Service test:test-alias is now connected" in result.output
assert "Service test:test-alias is now the default for project" in result.output
def test_service_connect__global_keychain():
runtime = BaseCumulusCI()
runtime.project_config = None
runtime.keychain.project_config = runtime.universal_config
runtime.universal_config.config["services"] = {
"test": {"attributes": {"attr": {"required": False}}}
}
run_cli_command("service", "connect", "test", "test-alias", runtime=runtime)
assert "test-alias" in runtime.keychain.list_services()["test"]
def test_service_connect__invalid_service():
runtime = BaseCumulusCI()
with pytest.raises(click.UsageError):
run_cli_command("service", "connect", "test", runtime=runtime)
def test_service_connect_validator():
runtime = BaseCumulusCI(
config={
"services": {
"test": {
"attributes": {},
"validator": "cumulusci.cli.tests.test_service.validate_service",
}
}
}
)
run_cli_command("service", "connect", "test", "test-alias", runtime=runtime)
service_config = runtime.keychain.get_service("test", "test-alias")
assert service_config.config == {"service_name": "test-alias", "key": "value"}
def test_service_connect_validator_failure():
runtime = BaseCumulusCI(
config={
"services": {
"test": {
"attributes": {},
"validator": "cumulusci.cli.tests.test_service.validate_service_error",
}
}
}
)
with pytest.raises(Exception, match="Validation failed"):
run_cli_command("service", "connect", "test", "test-alias", runtime=runtime)
def test_service_connect_without_whitespaces():
attr_value = " Sample attr value "
attr_value_without_whitespaces = "Sample attr value"
runtime = BaseCumulusCI(
config={"services": {"test": {"attributes": {"attr": {"required": False}}}}}
)
result = run_cli_command(
"service",
"connect",
"test",
"test-alias",
"--attr",
attr_value,
runtime=runtime,
)
result = runtime.keychain.get_service("test", "test-alias")
assert attr_value != result.attr
assert attr_value_without_whitespaces == result.attr
def test_service_update__success():
# Create a new color-picker service type
runtime = CliRuntime(
config={
"services": {"color-picker": {"attributes": {"color": {"required": False}}}}
}
)
# Setup an existing service of type color-picker
original_color = "Turquoise"
runtime.keychain.set_service(
"color-picker",
"foo",
ServiceConfig({"color": original_color}),
)
# Update the existing service
chosen_color = "Maroon"
result = run_cli_command(
"service",
"update",
"color-picker",
"foo",
input=f"{chosen_color}\n",
runtime=runtime,
)
assert "updated successfully!" in result.output
# ensure info was written to disk
result = run_cli_command(
"service",
"info",
"color-picker",
"foo",
runtime=runtime,
)
assert chosen_color in result.output
assert original_color not in result.output
def test_service_update_without_whitespaces():
# Create a new color-picker service type
runtime = CliRuntime(
config={
"services": {"color-picker": {"attributes": {"color": {"required": False}}}}
}
)
# Setup an existing service of type color-picker
original_color = "Turquoise"
runtime.keychain.set_service(
"color-picker",
"foo",
ServiceConfig({"color": original_color}),
)
# Update the existing service
chosen_color = " Maroon "
chosen_color_without_whitespaces = "Maroon"
result = run_cli_command(
"service",
"update",
"color-picker",
"foo",
input=f"{chosen_color}\n",
runtime=runtime,
)
# ensure info was written without whitespaces
result = runtime.keychain.get_service("color-picker", "foo")
assert chosen_color != result.color
assert chosen_color_without_whitespaces == result.color
def test_service_update_headless__success():
# Create a new color-picker service type
runtime = CliRuntime(
config={
"services": {
"color-picker": {
"attributes": {
"primary": {"required": False},
"secondary": {"required": False},
}
}
}
}
)
# Setup an existing service of type color-picker
original_primary = "Turquoise"
original_secondary = "Burgundy"
runtime.keychain.set_service(
"color-picker",
"foo",
ServiceConfig({"primary": original_primary, "secondary": original_secondary}),
)
# Update the existing service
new_primary = "Maroon"
new_secondary = "Purple"
result = run_cli_command(
"service",
"update",
"color-picker",
"foo",
"--attribute",
"primary",
new_primary,
"-a",
"secondary",
new_secondary,
runtime=runtime,
)
assert "updated successfully!" in result.output
# ensure info was written to disk
result = run_cli_command(
"service",
"info",
"color-picker",
"foo",
runtime=runtime,
)
assert new_primary in result.output
assert new_secondary in result.output
assert original_primary not in result.output
assert original_secondary not in result.output
def test_service_update_headless__unrecognized_service_attribute():
# Create a new color-picker service type
runtime = CliRuntime(
config={
"services": {
"color-picker": {
"attributes": {
"primary": {"required": False},
"secondary": {"required": False},
}
}
}
}
)
# Setup an existing service of type color-picker
original_primary = "Turquoise"
original_secondary = "Burgundy"
runtime.keychain.set_service(
"color-picker",
"foo",
ServiceConfig({"primary": original_primary, "secondary": original_secondary}),
)
# Update the service
new_primary = "Maroon"
result = run_cli_command(
"service",
"update",
"color-picker",
"foo",
"--attribute",
"does-not-exist",
new_primary,
runtime=runtime,
)
assert "Unrecognized service attribute 'does-not-exist" in result.output
assert "Acceptable values include: primary, secondary" in result.output
def test_service_update__service_does_not_exist():
# Create a new color-picker service type
runtime = CliRuntime(
config={
"services": {"color-picker": {"attributes": {"color": {"required": False}}}}
}
)
# Update service that doesn't exist
chosen_color = "Maroon"
with pytest.raises(ServiceNotConfigured):
run_cli_command(
"service",
"update",
"color-picker",
"foo",
input=f"{chosen_color}\n",
runtime=runtime,
)
def test_service_update__nothing_updated():
# Create a new color-picker service type
runtime = CliRuntime(
config={
"services": {"color-picker": {"attributes": {"color": {"required": False}}}}
}
)
# Setup an existing service of type color-picker
original_color = "Turquoise"
runtime.keychain.set_service(
"color-picker",
"foo",
ServiceConfig({"color": original_color}),
)
# Update the existing service
result = run_cli_command(
"service",
"update",
"color-picker",
"foo",
input="\n",
runtime=runtime,
)
print(f">>> {result.output=}")
assert "No updates made. Exiting." in result.output
def test_service_connect__connected_app():
runtime = BaseCumulusCI()
run_cli_command(
"service",
"connect",
"connected_app",
"new",
input="\n\nID\nSECRET\nn\n",
runtime=runtime,
)
service_config = runtime.keychain.get_service("connected_app", "new")
assert service_config.config == {
"service_name": "new",
"login_url": "https://login.salesforce.com",
"callback_url": "http://localhost:8080/callback",
"client_id": "ID",
"client_secret": "SECRET",
}
def test_service_connect__connected_app__with_cli_options():
runtime = BaseCumulusCI()
run_cli_command(
"service",
"connect",
"connected_app",
"new",
"--login_url",
"https://custom",
input="\nID\nSECRET\nn\n", # not prompted for login_url
runtime=runtime,
)
service_config = runtime.keychain.get_service("connected_app", "new")
assert service_config.config == {
"service_name": "new",
"login_url": "https://custom",
"callback_url": "http://localhost:8080/callback",
"client_id": "ID",
"client_secret": "SECRET",
}
def test_service_info():
runtime = CliRuntime(
config={
"services": {
"test": {
"attributes": {
"sensitive_attr": {"sensitive": True},
"non_sensitive_attr": {},
}
}
}
}
)
runtime.keychain.set_service(
"test",
"test-alias",
ServiceConfig({"sensitive_attr": "abcdefgh", "non_sensitive_attr": 1}),
)
result = run_cli_command("service", "info", "test", "test-alias", runtime=runtime)
assert (
result.output
== """ test:test-alias
Key Value
─────────────────────────────────────
\x1b[1msensitive_attr\x1b[0m ********
\x1b[1mnon_sensitive_attr\x1b[0m 1
""" # noqa: W291,W293
)
def test_service_info_json():
runtime = BaseCumulusCI(
config={
"services": {
"test": {
"attributes": {
"sensitive_attr": {"sensitive": True},
"non_sensitive_attr": {},
}
}
}
}
)
runtime.keychain.set_service(
"test",
"test-alias",
ServiceConfig({"sensitive_attr": "abcdefgh", "non_sensitive_attr": True}),
)
result = run_cli_command(
"service", "info", "test", "test-alias", "--json", runtime=runtime
)
assert (
result.output == '{"sensitive_attr": "abcdefgh", "non_sensitive_attr": true}\n'
) # noqa: W291,W293
def test_get_service_data():
service_config = ServiceConfig(
{
"sensitive_attr": "abcdef",
"other_secret": "abcdefghijk",
"non_sensitive_attr": "hellothere",
}
)
result = get_service_data(service_config, ["sensitive_attr", "other_secret"])
assert result == [
["Key", "Value"],
["\x1b[1msensitive_attr\x1b[0m", "******"],
["\x1b[1mother_secret\x1b[0m", "abcde******"],
["\x1b[1mnon_sensitive_attr\x1b[0m", "hellothere"],
]
def test_get_sensitive_service_attributes():
runtime = CliRuntime(
config={
"services": {
"universal_test": {
"attributes": {
"sensitive_attr": {"sensitive": True},
"non_sensitive_attr": {},
}
}
}
}
)
result = get_sensitive_service_attributes(runtime, "universal_test")
assert result == ["sensitive_attr"]
def test_service_info_not_configured():
runtime = BaseCumulusCI()
result = run_cli_command("service", "info", "test", "test-alias", runtime=runtime)
assert "not configured for this project" in result.output
def test_service_default__global():
runtime = BaseCumulusCI(config={"services": {"test": {"attributes": {}}}})
runtime.keychain.set_service("test", "test-alias", ServiceConfig({}))
runtime.keychain._default_services["test"] = None
result = run_cli_command(
"service", "default", "test", "test-alias", runtime=runtime
)
assert (
"Service test:test-alias is now the default for all CumulusCI projects"
in result.output
)
assert runtime.keychain.get_default_service_name("test") == "test-alias"
def test_service_default__project():
runtime = BaseCumulusCI(config={"services": {"test": {"attributes": {}}}})
runtime.keychain.project_local_dir = "test"
runtime.keychain.set_service("test", "test-alias", ServiceConfig({}))
runtime.keychain._default_services["test"] = None
result = run_cli_command(
"service", "default", "test", "test-alias", "--project", runtime=runtime
)
assert (
"Service test:test-alias is now the default for project 'test'" in result.output
)
assert runtime.keychain.get_default_service_name("test") == "test-alias"
def test_service_connect__project_default_no_project():
runtime = BaseCumulusCI()
runtime.project_config = None
runtime.keychain.project_config = runtime.universal_config
with pytest.raises(click.UsageError):
run_cli_command(
"service", "default", "test", "test-alias", "--project", runtime=runtime
)
def test_service_default__bad_service_type():
runtime = BaseCumulusCI()
result = run_cli_command(
"service", "default", "no-such-type", "test-alias", runtime=runtime
)
assert (
"An error occurred setting the default service: No services of type no-such-type are currently configured"
in result.output
)
def test_service_rename():
expected_config = {"a": "a"}
runtime = BaseCumulusCI(config={"services": {"test-type": {"attributes": {}}}})
runtime.keychain.set_service(
"test-type", "old-alias", ServiceConfig(expected_config)
)
result = run_cli_command(
"service", "rename", "test-type", "old-alias", "new-alias", runtime=runtime
)
assert "Service test-type:old-alias has been renamed to new-alias" in result.output
assert list(runtime.keychain.list_services()["test-type"]) == ["new-alias"]
service_config = runtime.keychain.get_service("test-type", "new-alias")
assert service_config.config == expected_config
def test_service_rename__bad_service_type():
runtime = BaseCumulusCI()
result = run_cli_command(
"service", "rename", "test-type", "old-alias", "new-alias", runtime=runtime
)
assert (
"An error occurred renaming the service: No services of type test-type are currently configured"
in result.output
)
def test_service_remove():
runtime = BaseCumulusCI(config={"services": {"test-type": {"attributes": {}}}})
runtime.keychain.env_service_var_prefix = "CUMULUSCI_SERVICE_"
runtime.keychain.set_service(
"test-type", "current-default-alias", ServiceConfig({})
)
runtime.keychain.set_service("test-type", "other-alias", ServiceConfig({}))
runtime.keychain.set_service("test-type", "future-default-alias", ServiceConfig({}))
result = run_cli_command(
"service",
"remove",
"test-type",
"current-default-alias",
input="future-default-alias\n",
runtime=runtime,
)
assert "Service test-type:current-default-alias has been removed." in result.output
assert "current-default-alias" not in runtime.keychain.list_services()["test-type"]
assert (
runtime.keychain.get_default_service_name("test-type") == "future-default-alias"
)
def test_service_remove__new_default_does_not_exist():
runtime = BaseCumulusCI(config={"services": {"test-type": {"attributes": {}}}})
runtime.keychain.env_service_var_prefix = "CUMULUSCI_SERVICE_"
runtime.keychain.set_service(
"test-type", "current-default-alias", ServiceConfig({})
)
runtime.keychain.set_service("test-type", "other-alias-1", ServiceConfig({}))
runtime.keychain.set_service("test-type", "other-alias-2", ServiceConfig({}))
result = run_cli_command(
"service",
"remove",
"test-type",
"current-default-alias",
input="this-alias-does-not-exist\n",
runtime=runtime,
)
assert (
"No service of type test-type with name: this-alias-does-not-exist"
in result.output
)
assert "current-default-alias" in runtime.keychain.list_services()["test-type"]
assert (
runtime.keychain.get_default_service_name("test-type")
== "current-default-alias"
)
def test_service_remove__bad_service_name():
runtime = BaseCumulusCI(config={"services": {"test-type": {"attributes": {}}}})
runtime.keychain.env_service_var_prefix = "CUMULUSCI_SERVICE_"
result = run_cli_command(
"service",
"remove",
"test-type",
"bogus",
runtime=runtime,
)
assert (
"An error occurred removing the service: No services of type test-type are currently configured"
in result.output
)
def test_service_remove__environment_service_cannot_be_removed():
runtime = BaseCumulusCI(config={"services": {"test-type": {"attributes": {}}}})
runtime.keychain.env_service_var_prefix = "CUMULUSCI_SERVICE_"
runtime.keychain.set_service("test-type", "env-foo", ServiceConfig({}))
with EnvironmentVarGuard() as env:
env.set(
"CUMULUSCI_SERVICE_github__env-foo", '{"username":"foo", "token": "bar"}'
)
result = run_cli_command(
"service", "remove", "github", "env-foo", runtime=runtime
)
assert (
"The service github:env-foo is defined by environment variables. "
"If you would like it removed please delete the environment variable with name: "
"CUMULUSCI_SERVICE_github__env-foo"
) in result.output
def validate_service(options, keychain):
return {"key": "value"}
def validate_service_error(options, keychain):
raise Exception("Validation failed")
def get_default():
return "CALCULATED"