Skip to content

Commit cd7e592

Browse files
author
Christine WANJAU
committed
Testing
1 parent 788518b commit cd7e592

2 files changed

Lines changed: 43 additions & 138 deletions

File tree

src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/test_appconfig_kv_commands.py

Lines changed: 31 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,37 @@ def test_azconfig_kv(self):
309309
with self.assertRaisesRegex(MutuallyExclusiveArgumentError, "The '--dry-run' and '--yes' options cannot be specified together."):
310310
self.cmd('appconfig kv restore --datetime "2019-05-01T11:24:12Z" --endpoint {endpoint} --auth-mode login --key {key} --label {label} --dry-run -y')
311311

312+
# Description property: set with --description, verify it is returned, preserved on edit, and overwritten
313+
self.kwargs.update({
314+
'key': "DescKey",
315+
'value': "Red",
316+
'description': "The theme color"
317+
})
318+
self.cmd('appconfig kv set --endpoint {endpoint} --auth-mode login --key {key} --value {value} --description "{description}" -y',
319+
checks=[self.check('key', "DescKey"),
320+
self.check('value', "Red"),
321+
self.check('description', "The theme color")])
322+
323+
# Description is returned by show
324+
self.cmd('appconfig kv show --endpoint {endpoint} --auth-mode login --key {key}',
325+
checks=[self.check('description', "The theme color")])
326+
327+
# Description is selectable via --fields
328+
partial_kv = self.cmd('appconfig kv list --endpoint {endpoint} --auth-mode login --key {key} --fields description').get_output_in_json()
329+
self.assertEqual(partial_kv[0]['description'], "The theme color")
330+
self.assertNotIn('value', partial_kv[0])
331+
332+
# Updating another property without --description preserves the existing description
333+
self.kwargs.update({'value': "Green"})
334+
self.cmd('appconfig kv set --endpoint {endpoint} --auth-mode login --key {key} --value {value} -y',
335+
checks=[self.check('value', "Green"),
336+
self.check('description', "The theme color")])
337+
338+
# Explicitly updating the description overwrites it
339+
self.kwargs.update({'description': "The updated theme color"})
340+
self.cmd('appconfig kv set --endpoint {endpoint} --auth-mode login --key {key} --description "{description}" -y',
341+
checks=[self.check('description', "The updated theme color")])
342+
312343

313344
@AllowLargeResponse()
314345
@ResourceGroupPreparer()
@@ -519,70 +550,4 @@ def test_azconfig_kv_revision_list(self):
519550
revisions = self.cmd('appconfig revision list --endpoint {endpoint} --auth-mode login --key {key} --label *').get_output_in_json()
520551
assert len(revisions) == 3
521552

522-
@AllowLargeResponse()
523-
# Uses Entra ID auth (store created with local auth disabled); target a resource group where the
524-
# recording principal holds "App Configuration Data Owner". Override via AZURE_CLI_APPCONFIG_TEST_RG.
525-
def test_azconfig_kv_description(self):
526-
# Lowercase store-name prefix so the HTTP-lowercased '<name>.azconfig.io' host matches the
527-
# name registered with the recording name-replacer, keeping cassettes scrubbed for playback.
528-
config_store_prefix = get_resource_name_prefix('kvdesctest')
529-
config_store_name = self.create_random_name(prefix=config_store_prefix, length=24)
530-
531-
location = 'eastus'
532-
sku = 'standard'
533-
self.kwargs.update({
534-
'config_store_name': config_store_name,
535-
'rg_loc': location,
536-
'rg': get_test_resource_group(),
537-
'sku': sku,
538-
'endpoint': 'https://' + config_store_name + '.azconfig.io'
539-
})
540-
create_config_store(self, self.kwargs, disable_local_auth=True)
541-
542-
entry_key = "Color"
543-
entry_value = "Red"
544-
entry_description = "The theme color"
545-
546-
self.kwargs.update({
547-
'key': entry_key,
548-
'value': entry_value,
549-
'description': entry_description
550-
})
551-
552-
# Set a key-value with a description
553-
self.cmd('appconfig kv set --endpoint {endpoint} --auth-mode login --key {key} --value {value} --description "{description}" -y',
554-
checks=[self.check('key', entry_key),
555-
self.check('value', entry_value),
556-
self.check('description', entry_description)])
557-
558-
# Show the key-value and verify the description is returned
559-
self.cmd('appconfig kv show --endpoint {endpoint} --auth-mode login --key {key}',
560-
checks=[self.check('key', entry_key),
561-
self.check('value', entry_value),
562-
self.check('description', entry_description)])
563-
564-
# List with only the description field selected
565-
partial_kv = self.cmd('appconfig kv list --endpoint {endpoint} --auth-mode login --key {key} --fields description').get_output_in_json()
566-
self.assertEqual(partial_kv[0]['description'], entry_description)
567-
self.assertNotIn('value', partial_kv[0])
568-
569-
# Updating another property without --description should preserve the existing description
570-
updated_value = "Green"
571-
self.kwargs.update({
572-
'value': updated_value
573-
})
574-
self.cmd('appconfig kv set --endpoint {endpoint} --auth-mode login --key {key} --value {value} -y',
575-
checks=[self.check('key', entry_key),
576-
self.check('value', updated_value),
577-
self.check('description', entry_description)])
578-
579-
# Explicitly updating the description should overwrite the previous value
580-
updated_description = "The updated theme color"
581-
self.kwargs.update({
582-
'description': updated_description
583-
})
584-
self.cmd('appconfig kv set --endpoint {endpoint} --auth-mode login --key {key} --description "{description}" -y',
585-
checks=[self.check('key', entry_key),
586-
self.check('value', updated_value),
587-
self.check('description', updated_description)])
588553

src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/test_appconfig_snapshot_commands.py

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,32 @@ def test_azconfig_snapshot_mgmt(self):
9292
'retention_period': retention_period
9393
})
9494

95-
self.cmd('appconfig snapshot create --endpoint {endpoint} --auth-mode login --snapshot-name {snapshot_name} --filters {filter} --retention-period {retention_period} --composition-type key_label --tags tag1=value1',
95+
snapshot_description = "Snapshot of Test key-values"
96+
self.kwargs.update({
97+
'snapshot_description': snapshot_description
98+
})
99+
100+
self.cmd('appconfig snapshot create --endpoint {endpoint} --auth-mode login --snapshot-name {snapshot_name} --filters {filter} --retention-period {retention_period} --composition-type key_label --tags tag1=value1 --description "{snapshot_description}"',
96101
checks=[self.check('itemsCount', 2),
97-
self.check('status', 'ready')])
102+
self.check('status', 'ready'),
103+
self.check('description', snapshot_description)])
98104

99105

100106
# Test showing created snapshot
101-
created_snapshot = self.cmd('appconfig snapshot show --endpoint {endpoint} --auth-mode login --snapshot-name {snapshot_name} --fields name status items_count filters').get_output_in_json()
107+
created_snapshot = self.cmd('appconfig snapshot show --endpoint {endpoint} --auth-mode login --snapshot-name {snapshot_name} --fields name status items_count filters description').get_output_in_json()
102108

103109
self.assertEqual(created_snapshot['items_count'], 2)
104110
self.check(created_snapshot['status'], 'ready')
105111
self.assertDictEqual(created_snapshot['filters'][0], filter_dict)
112+
self.assertEqual(created_snapshot['description'], snapshot_description)
106113
self.assertRaises(KeyError, lambda: created_snapshot['created'])
107114

108115
# Test listing snapshots
109-
created_snapshots = self.cmd('appconfig snapshot list --snapshot-name {snapshot_name} --endpoint {endpoint} --auth-mode login --fields name status items_count filters').get_output_in_json()
116+
created_snapshots = self.cmd('appconfig snapshot list --snapshot-name {snapshot_name} --endpoint {endpoint} --auth-mode login --fields name status items_count filters description').get_output_in_json()
110117
self.assertEqual(created_snapshots[0]['items_count'], 2)
111118
self.assertEqual(created_snapshots[0]['status'], 'ready')
112119
self.assertDictEqual(created_snapshots[0]['filters'][0], filter_dict)
120+
self.assertEqual(created_snapshots[0]['description'], snapshot_description)
113121

114122
# Test snapshot archive
115123
archived_snapshot = self.cmd('appconfig snapshot archive --endpoint {endpoint} --auth-mode login --snapshot-name {snapshot_name}').get_output_in_json()
@@ -358,71 +366,3 @@ def test_azconfig_snapshot_filtering(self):
358366
self.check('status', 'ready')])
359367

360368

361-
@AllowLargeResponse()
362-
# Uses Entra ID auth (store created with local auth disabled); target a resource group where the
363-
# recording principal holds "App Configuration Data Owner". Override via AZURE_CLI_APPCONFIG_TEST_RG.
364-
def test_azconfig_snapshot_description(self):
365-
store_name_prefix = get_resource_name_prefix('snapshotdesc')
366-
config_store_name = self.create_random_name(prefix=store_name_prefix, length=24)
367-
snapshot_name = "DescriptionSnapshot"
368-
snapshot_description = "Snapshot of Test key-values"
369-
store_location = 'francecentral'
370-
sku = 'standard'
371-
372-
self.kwargs.update({
373-
'config_store_name': config_store_name,
374-
'snapshot_name': snapshot_name,
375-
'snapshot_description': snapshot_description,
376-
'rg_loc': store_location,
377-
'rg': get_test_resource_group(),
378-
'sku': sku,
379-
'retention_days': 1,
380-
'enable_purge_protection': False,
381-
'endpoint': 'https://' + config_store_name + '.azconfig.io'
382-
})
383-
384-
create_config_store(self, self.kwargs, disable_local_auth=True)
385-
386-
# Create a couple of key-values to include in the snapshot
387-
self.kwargs.update({
388-
'key': "TestKey1",
389-
'value': "TestValue1",
390-
})
391-
self.cmd('appconfig kv set --endpoint {endpoint} --auth-mode login --key {key} --value {value} -y',
392-
checks=[self.check('key', "TestKey1"),
393-
self.check('value', "TestValue1")])
394-
395-
self.kwargs.update({
396-
'key': "TestKey2",
397-
'value': "TestValue2",
398-
})
399-
self.cmd('appconfig kv set --endpoint {endpoint} --auth-mode login --key {key} --value {value} -y',
400-
checks=[self.check('key', "TestKey2"),
401-
self.check('value', "TestValue2")])
402-
403-
# Create a snapshot with a description
404-
filter_dict = {"key": "Test*"}
405-
self.kwargs.update({
406-
'filter': '\'{}\''.format(json.dumps(filter_dict)),
407-
'retention_period': 3600
408-
})
409-
410-
self.cmd('appconfig snapshot create --endpoint {endpoint} --auth-mode login --snapshot-name {snapshot_name} --filters {filter} --retention-period {retention_period} --description "{snapshot_description}"',
411-
checks=[self.check('itemsCount', 2),
412-
self.check('status', 'ready'),
413-
self.check('description', snapshot_description)])
414-
415-
# Show the snapshot and verify the description is returned
416-
self.cmd('appconfig snapshot show --endpoint {endpoint} --auth-mode login --snapshot-name {snapshot_name}',
417-
checks=[self.check('name', snapshot_name),
418-
self.check('description', snapshot_description)])
419-
420-
# Show only the description field
421-
partial_snapshot = self.cmd('appconfig snapshot show --endpoint {endpoint} --auth-mode login --snapshot-name {snapshot_name} --fields description').get_output_in_json()
422-
self.assertEqual(partial_snapshot['description'], snapshot_description)
423-
self.assertRaises(KeyError, lambda: partial_snapshot['name'])
424-
425-
# List snapshots and verify the description is returned
426-
listed_snapshots = self.cmd('appconfig snapshot list --endpoint {endpoint} --auth-mode login --snapshot-name {snapshot_name}').get_output_in_json()
427-
self.assertEqual(listed_snapshots[0]['description'], snapshot_description)
428-

0 commit comments

Comments
 (0)