|
17 | 17 | remove_remote_build_app_settings, |
18 | 18 | config_source_control, |
19 | 19 | validate_app_settings_in_scm, |
20 | | - update_container_settings_functionapp) |
| 20 | + update_container_settings_functionapp, |
| 21 | + list_function_keys) |
21 | 22 | from azure.cli.core.profiles import ResourceType |
22 | 23 | from azure.cli.core.azclierror import (AzureInternalError, UnclassifiedUserFault) |
23 | 24 | from azure.cli.core.azclierror import ResourceNotFoundError |
@@ -849,3 +850,42 @@ def test_flex_parse_raw_stacks_prefers_functions_worker_runtime_when_present(sel |
849 | 850 |
|
850 | 851 | # assert |
851 | 852 | self.assertEqual(matched.name, 'dotnet-isolated') |
| 853 | + |
| 854 | + @mock.patch('azure.cli.command_modules.appservice.custom.web_client_factory', autospec=True) |
| 855 | + def test_list_function_keys_unwraps_broken_string_dictionary(self, web_client_factory_mock): |
| 856 | + # azure-mgmt-web 11.0.0 deserializes flat dictionary responses with .properties = None |
| 857 | + from azure.mgmt.web import models as _models |
| 858 | + from azure.mgmt.web._utils.model_base import _deserialize |
| 859 | + |
| 860 | + broken = _deserialize( |
| 861 | + _models.StringDictionary, |
| 862 | + {'default': 'vvrX4LJY1JWbimFI28UM', 'myCustomKey': 'abc'}) |
| 863 | + self.assertIsNone(broken.properties) |
| 864 | + |
| 865 | + cmd_mock = _get_test_cmd() |
| 866 | + client_mock = mock.MagicMock() |
| 867 | + client_mock.web_apps.list_function_keys.return_value = broken |
| 868 | + web_client_factory_mock.return_value = client_mock |
| 869 | + |
| 870 | + result = list_function_keys(cmd_mock, 'rg', 'app', 'httpget') |
| 871 | + |
| 872 | + self.assertEqual(result, {'default': 'vvrX4LJY1JWbimFI28UM', 'myCustomKey': 'abc'}) |
| 873 | + client_mock.web_apps.list_function_keys.assert_called_once_with('rg', 'app', 'httpget') |
| 874 | + client_mock.web_apps.list_function_keys_slot.assert_not_called() |
| 875 | + |
| 876 | + @mock.patch('azure.cli.command_modules.appservice.custom.web_client_factory', autospec=True) |
| 877 | + def test_list_function_keys_uses_properties_when_sdk_returns_enveloped_response(self, web_client_factory_mock): |
| 878 | + # Prefers .properties when populated (forward-compatible with a future SDK fix) |
| 879 | + fixed = mock.MagicMock() |
| 880 | + fixed.properties = {'default': 'abc'} |
| 881 | + |
| 882 | + cmd_mock = _get_test_cmd() |
| 883 | + client_mock = mock.MagicMock() |
| 884 | + client_mock.web_apps.list_function_keys_slot.return_value = fixed |
| 885 | + web_client_factory_mock.return_value = client_mock |
| 886 | + |
| 887 | + result = list_function_keys(cmd_mock, 'rg', 'app', 'httpget', slot='staging') |
| 888 | + |
| 889 | + self.assertEqual(result, {'default': 'abc'}) |
| 890 | + client_mock.web_apps.list_function_keys_slot.assert_called_once_with('rg', 'app', 'httpget', 'staging') |
| 891 | + client_mock.web_apps.list_function_keys.assert_not_called() |
0 commit comments