def test_list_available_extensions_show_details(self): with mock.patch( 'azure.cli.core.extension.operations.get_index_extensions', autospec=True) as c: list_available_extensions(show_details=True, cli_ctx=self.cmd.cli_ctx) c.assert_called_once_with(None, self.cmd.cli_ctx)
def _get_available_extension_urls(): """ Get download urls for all the CLI extensions compatible with the installed development CLI. :return: list of 3-tuples in the form of '(extension_name, extension_file_name, extensions_download_url)' """ all_pub_extensions = list_available_extensions(show_details=True) compatible_extensions = list_available_extensions() name_url_tups = [] for ext in compatible_extensions: old_length = len(name_url_tups) ext_name, ext_version = ext["name"], ext["version"] for ext_info in all_pub_extensions[ext_name]: if ext_version == ext_info["metadata"]["version"]: name_url_tups.append( (ext_name, ext_info["filename"], ext_info["downloadUrl"])) break if old_length == len(name_url_tups): _logger.warning( "'%s' has no versions compatible with the installed CLI's version", ext_name) return name_url_tups
def test_list_available_extensions_operations_index_url(self): with mock.patch( 'azure.cli.core.extension.operations.get_index_extensions', autospec=True) as c: index_url = 'http://contoso.com' list_available_extensions(index_url=index_url) c.assert_called_once_with(index_url)
def check_extension_version(extension_name): from azure.cli.core.extension.operations import list_available_extensions, list_extensions available_extensions = list_available_extensions() installed_extensions = list_extensions() extension_to_check = [ ext for ext in installed_extensions if ext['name'] == extension_name ] if not extension_to_check: logger.debug( 'The extension with name %s does not exist within installed extensions.', extension_name) return extension_to_check = extension_to_check[0] for ext in available_extensions: if ext['name'] == extension_name and ext[ 'version'] > extension_to_check['version']: logger.warning( 'The %s extension is not up to date, please update with az extension update -n %s', extension_name, extension_name) return logger.debug( 'The extension with name %s does not exist within available extensions.', extension_name)
def test_list_available_extensions_no_show_details(self): sample_index_extensions = { 'test_sample_extension1': [{ 'metadata': { 'name': 'test_sample_extension1', 'summary': 'my summary', 'version': '0.1.0' } }], 'test_sample_extension2': [{ 'metadata': { 'name': 'test_sample_extension2', 'summary': 'my summary', 'version': '0.1.0', 'azext.isPreview': True, 'azext.isExperimental': True } }] } with mock.patch( 'azure.cli.core.extension.operations.get_index_extensions', return_value=sample_index_extensions): res = list_available_extensions(cli_ctx=self.cmd.cli_ctx) self.assertIsInstance(res, list) self.assertEqual(len(res), len(sample_index_extensions)) self.assertEqual(res[0]['name'], 'test_sample_extension1') self.assertEqual(res[0]['summary'], 'my summary') self.assertEqual(res[0]['version'], '0.1.0') self.assertEqual(res[0]['preview'], False) self.assertEqual(res[0]['experimental'], False) with mock.patch( 'azure.cli.core.extension.operations.get_index_extensions', return_value=sample_index_extensions): res = list_available_extensions(cli_ctx=self.cmd.cli_ctx) self.assertIsInstance(res, list) self.assertEqual(len(res), len(sample_index_extensions)) self.assertEqual(res[1]['name'], 'test_sample_extension2') self.assertEqual(res[1]['summary'], 'my summary') self.assertEqual(res[1]['version'], '0.1.0') self.assertEqual(res[1]['preview'], True) self.assertEqual(res[1]['experimental'], True)
def test_list_available_extensions_incompatible_cli_version(self): sample_index_extensions = { 'test_sample_extension1': [{ 'metadata': { "azext.maxCliCoreVersion": "0.0.0", 'name': 'test_sample_extension1', 'summary': 'my summary', 'version': '0.1.0' }}] } with mock.patch('azure.cli.core.extension.operations.get_index_extensions', return_value=sample_index_extensions): res = list_available_extensions() self.assertIsInstance(res, list) self.assertEqual(len(res), 0)
def test_list_available_extensions_incompatible_cli_version(self): sample_index_extensions = { 'test_sample_extension1': [{ 'metadata': { "azext.maxCliCoreVersion": "0.0.0", 'name': 'test_sample_extension1', 'summary': 'my summary', 'version': '0.1.0' }}] } with mock.patch('azure.cli.core.extension.operations.get_index_extensions', return_value=sample_index_extensions): res = list_available_extensions() self.assertIsInstance(res, list) self.assertEqual(len(res), 0)
def test_list_available_extensions_no_show_details(self): sample_index_extensions = { 'test_sample_extension1': [{ 'metadata': { 'name': 'test_sample_extension1', 'summary': 'my summary', 'version': '0.1.0' }}] } with mock.patch('azure.cli.core.extension.operations.get_index_extensions', return_value=sample_index_extensions): res = list_available_extensions() self.assertIsInstance(res, list) self.assertEqual(len(res), len(sample_index_extensions)) self.assertEqual(res[0]['name'], 'test_sample_extension1') self.assertEqual(res[0]['summary'], 'my summary') self.assertEqual(res[0]['version'], '0.1.0') self.assertEqual(res[0]['preview'], False)
def list_available_extensions_cmd(index_url=None, show_details=False): return list_available_extensions(index_url=index_url, show_details=show_details)
def list_available_extensions_cmd(cmd, index_url=None, show_details=False): return list_available_extensions(index_url=index_url, show_details=show_details, cli_ctx=cmd.cli_ctx)
def test_list_available_extensions_default(self): with mock.patch( 'azure.cli.core.extension.operations.get_index_extensions', autospec=True) as c: list_available_extensions() c.assert_called_once_with(None)
def test_list_available_extensions_show_details(self): with mock.patch('azure.cli.core.extension.operations.get_index_extensions', autospec=True) as c: list_available_extensions(show_details=True) c.assert_called_once_with(None)
def test_list_available_extensions_operations_index_url(self): with mock.patch('azure.cli.core.extension.operations.get_index_extensions', autospec=True) as c: index_url = 'http://contoso.com' list_available_extensions(index_url=index_url) c.assert_called_once_with(index_url)
def list_available_extensions_cmd(index_url=None, show_details=False): return list_available_extensions(index_url=index_url, show_details=show_details)