Best Python code snippet using locust
commands.py
Source:commands.py  
1# --------------------------------------------------------------------------------------------2# Copyright (c) Microsoft Corporation. All rights reserved.3# Licensed under the MIT License. See License.txt in the project root for license information.4# --------------------------------------------------------------------------------------------5from azure.cli.core.commands import CliCommandType6# pylint: disable=line-too-long, too-many-locals, too-many-statements7def load_command_table(self, _):8    from ._client_factory import (9        cf_alert_rules, cf_metric_def, cf_alert_rule_incidents, cf_log_profiles, cf_autoscale,10        cf_diagnostics, cf_activity_log, cf_action_groups, cf_activity_log_alerts, cf_event_categories,11        cf_metric_alerts, cf_metric_ns, cf_log_analytics_deleted_workspaces, cf_log_analytics_workspace,12        cf_log_analytics_workspace_tables, cf_log_analytics_workspace_management_groups,13        cf_log_analytics_workspace_usage, cf_log_analytics_workspace_schema, cf_log_analytics_workspace_shared_keys,14        cf_log_analytics_workspace_intelligence_packs, cf_log_analytics_cluster,15        cf_log_analytics_workspace_linked_service, cf_diagnostics_category,16        cf_private_link_resources, cf_private_link_scoped_resources,17        cf_private_link_scopes, cf_private_endpoint_connections, cf_log_analytics_linked_storage,18        cf_log_analytics_workspace_saved_searches, cf_subscription_diagnostics,19        cf_log_analytics_workspace_data_exports)20    from .transformers import (action_group_list_table)21    from .validators import (process_autoscale_create_namespace,22                             validate_private_endpoint_connection_id,23                             process_action_group_detail_for_creation)24    from ._exception_handler import exception_handler25    monitor_custom = CliCommandType(26        operations_tmpl='azure.cli.command_modules.monitor.custom#{}',27        exception_handler=exception_handler)28    action_group_sdk = CliCommandType(29        operations_tmpl='azure.mgmt.monitor.operations#ActionGroupsOperations.{}',30        client_factory=cf_action_groups,31        operation_group='action_groups',32        exception_handler=exception_handler)33    action_group_custom = CliCommandType(34        operations_tmpl='azure.cli.command_modules.monitor.operations.action_groups#{}',35        client_factory=cf_action_groups,36        operation_group='action_groups',37        exception_handler=exception_handler)38    activity_log_sdk = CliCommandType(39        operations_tmpl='azure.mgmt.monitor.operations#EventCategoriesOperations.{}',40        client_factory=cf_event_categories,41        operation_group='event_categories',42        exception_handler=exception_handler)43    activity_log_alerts_sdk = CliCommandType(44        operations_tmpl='azure.mgmt.monitor.operations#ActivityLogAlertsOperations.{}',45        client_factory=cf_activity_log_alerts,46        operation_group='activity_log_alerts',47        exception_handler=exception_handler)48    activity_log_alerts_custom = CliCommandType(49        operations_tmpl='azure.cli.command_modules.monitor.operations.activity_log_alerts#{}',50        client_factory=cf_activity_log_alerts,51        operation_group='activity_log_alerts',52        exception_handler=exception_handler)53    alert_sdk = CliCommandType(54        operations_tmpl='azure.mgmt.monitor.operations#AlertRulesOperations.{}',55        client_factory=cf_alert_rules,56        operation_group='alert_rules',57        exception_handler=exception_handler)58    alert_rule_incidents_sdk = CliCommandType(59        operations_tmpl='azure.mgmt.monitor.operations#AlertRuleIncidentsOperations.{}',60        client_factory=cf_alert_rule_incidents,61        operation_group='alert_rule_incidents',62        exception_handler=exception_handler)63    autoscale_sdk = CliCommandType(64        operations_tmpl='azure.mgmt.monitor.operations#AutoscaleSettingsOperations.{}',65        client_factory=cf_autoscale,66        operation_group='autoscale_settings',67        exception_handler=exception_handler)68    autoscale_custom = CliCommandType(69        operations_tmpl='azure.cli.command_modules.monitor.operations.autoscale_settings#{}',70        client_factory=cf_autoscale,71        operation_group='autoscale_settings',72        exception_handler=exception_handler)73    diagnostics_sdk = CliCommandType(74        operations_tmpl='azure.mgmt.monitor.operations#DiagnosticSettingsOperations.{}',75        client_factory=cf_diagnostics,76        operation_group='diagnostic_settings',77        exception_handler=exception_handler)78    diagnostics_categories_sdk = CliCommandType(79        operations_tmpl='azure.mgmt.monitor.operations#DiagnosticSettingsCategoryOperations.{}',80        client_factory=cf_diagnostics_category,81        operation_group='diagnostic_settings_category',82        exception_handler=exception_handler)83    diagnostics_custom = CliCommandType(84        operations_tmpl='azure.cli.command_modules.monitor.operations.diagnostics_settings#{}',85        client_factory=cf_diagnostics,86        operation_group='diagnostic_settings_category',87        exception_handler=exception_handler)88    log_profiles_sdk = CliCommandType(89        operations_tmpl='azure.mgmt.monitor.operations#LogProfilesOperations.{}',90        client_factory=cf_log_profiles,91        operation_group='log_profiles',92        exception_handler=exception_handler)93    log_profiles_custom = CliCommandType(94        operations_tmpl='azure.cli.command_modules.monitor.operations.log_profiles#{}',95        client_factory=cf_log_profiles,96        operation_group='log_profiles',97        exception_handler=exception_handler)98    subscription_dianostic_settings_sdk = CliCommandType(99        operations_tmpl='azure.mgmt.monitor.operations#SubscriptionDiagnosticSettingsOperations.{}',100        client_factory=cf_subscription_diagnostics,101        operation_group='subscription_diagnostic_settings',102        exception_handler=exception_handler)103    subscription_dianostic_settings_custom = CliCommandType(104        operations_tmpl='azure.cli.command_modules.monitor.operations.subscription_diagnostic_settings#{}',105        client_factory=cf_subscription_diagnostics,106        operation_group='subscription_diagnostic_settings',107        exception_handler=exception_handler)108    alert_custom = CliCommandType(109        operations_tmpl='azure.cli.command_modules.monitor.operations.metric_alert#{}',110        client_factory=cf_alert_rules,111        operation_group='alert_rules',112        exception_handler=exception_handler)113    metric_alert_sdk = CliCommandType(114        operations_tmpl='azure.mgmt.monitor.operations#MetricAlertsOperations.{}',115        client_factory=cf_metric_alerts,116        operation_group='metric_alerts',117        exception_handler=exception_handler)118    metric_definitions_sdk = CliCommandType(119        operations_tmpl='azure.mgmt.monitor.operations#MetricDefinitionsOperations.{}',120        client_factory=cf_metric_def,121        operation_group='metric_definitions',122        exception_handler=exception_handler)123    metric_namespaces_sdk = CliCommandType(124        operations_tmpl='azure.mgmt.monitor.operations#MetricNamespacesOperations.{}',125        client_factory=cf_metric_ns,126        operation_group='metric_namespaces',127        exception_handler=exception_handler128    )129    log_analytics_workspace_sdk = CliCommandType(130        operations_tmpl='azure.mgmt.loganalytics.operations#WorkspacesOperations.{}',131        client_factory=cf_log_analytics_workspace,132        exception_handler=exception_handler)133    private_link_resources_sdk = CliCommandType(134        operations_tmpl='azure.mgmt.monitor.operations#PrivateLinkResourcesOperations.{}',135        client_factory=cf_private_link_resources,136        operation_group='private_link_resources',137        exception_handler=exception_handler)138    private_link_scoped_resources_sdk = CliCommandType(139        operations_tmpl='azure.mgmt.monitor.operations#PrivateLinkScopedResourcesOperations.{}',140        client_factory=cf_private_link_scoped_resources,141        operation_group='private_link_scoped_resources',142        exception_handler=exception_handler)143    private_link_scopes_sdk = CliCommandType(144        operations_tmpl='azure.mgmt.monitor.operations#PrivateLinkScopesOperations.{}',145        client_factory=cf_private_link_scopes,146        operation_group='private_link_scopes',147        exception_handler=exception_handler)148    private_endpoint_connections_sdk = CliCommandType(149        operations_tmpl='azure.mgmt.monitor.operations#PrivateEndpointConnectionsOperations.{}',150        client_factory=cf_private_endpoint_connections,151        operation_group='private_endpoint_connections',152        exception_handler=exception_handler)153    private_link_scope_custom = CliCommandType(154        operations_tmpl='azure.cli.command_modules.monitor.operations.private_link_scope#{}',155        client_factory=cf_private_link_scopes,156        exception_handler=exception_handler)157    log_analytics_deleted_workspace_custom = CliCommandType(158        operations_tmpl='azure.cli.command_modules.monitor.operations.log_analytics_workspace#{}',159        client_factory=cf_log_analytics_deleted_workspaces,160        exception_handler=exception_handler)161    log_analytics_workspace_custom = CliCommandType(162        operations_tmpl='azure.cli.command_modules.monitor.operations.log_analytics_workspace#{}',163        client_factory=cf_log_analytics_workspace,164        exception_handler=exception_handler)165    log_analytics_workspace_management_groups_sdk = CliCommandType(166        operations_tmpl='azure.mgmt.loganalytics.operations#ManagementGroupsOperations.{}',167        client_factory=cf_log_analytics_workspace_management_groups,168        exception_handler=exception_handler)169    log_analytics_workspace_usage_sdk = CliCommandType(170        operations_tmpl='azure.mgmt.loganalytics.operations#UsagesOperations.{}',171        client_factory=cf_log_analytics_workspace_usage,172        exception_handler=exception_handler)173    log_analytics_workspace_schema_sdk = CliCommandType(174        operations_tmpl='azure.mgmt.loganalytics.operations#SchemaOperations.{}',175        client_factory=cf_log_analytics_workspace_schema,176        exception_handler=exception_handler)177    log_analytics_workspace_shared_keys_sdk = CliCommandType(178        operations_tmpl='azure.mgmt.loganalytics.operations#SharedKeysOperations.{}',179        client_factory=cf_log_analytics_workspace_shared_keys,180        exception_handler=exception_handler)181    log_analytics_workspace_intelligence_packs_sdk = CliCommandType(182        operations_tmpl='azure.mgmt.loganalytics.operations#IntelligencePacksOperations.{}',183        client_factory=cf_log_analytics_workspace_intelligence_packs,184        exception_handler=exception_handler)185    log_analytics_workspace_saved_search_sdk = CliCommandType(186        operations_tmpl='azure.mgmt.loganalytics.operations#SavedSearchesOperations.{}',187        client_factory=cf_log_analytics_workspace_saved_searches,188        exception_handler=exception_handler)189    log_analytics_workspace_linked_service_sdk = CliCommandType(190        operations_tmpl='azure.mgmt.loganalytics.operations#LinkedServicesOperations.{}',191        client_factory=cf_log_analytics_workspace_linked_service,192        exception_handler=exception_handler)193    log_analytics_workspace_linked_service_custom = CliCommandType(194        operations_tmpl='azure.cli.command_modules.monitor.operations.log_analytics_workspace_linked_service#{}',195        client_factory=cf_log_analytics_workspace_linked_service,196        exception_handler=exception_handler)197    log_analytics_workspace_table_sdk = CliCommandType(198        operations_tmpl='azure.mgmt.loganalytics.operations#TablesOperations.{}',199        client_factory=cf_log_analytics_workspace_tables,200        exception_handler=exception_handler)201    log_analytics_workspace_data_exports_sdk = CliCommandType(202        operations_tmpl='azure.mgmt.loganalytics.operations#DataExportsOperations.{}',203        client_factory=cf_log_analytics_workspace_data_exports,204        exception_handler=exception_handler)205    log_analytics_cluster_sdk = CliCommandType(206        operations_tmpl='azure.mgmt.loganalytics.operations#ClustersOperations.{}',207        client_factory=cf_log_analytics_cluster,208        exception_handler=exception_handler)209    log_analytics_cluster_custom = CliCommandType(210        operations_tmpl='azure.cli.command_modules.monitor.operations.log_analytics_cluster#{}',211        client_factory=cf_log_analytics_cluster,212        exception_handler=exception_handler)213    log_analytics_linked_storage_sdk = CliCommandType(214        operations_tmpl='azure.mgmt.loganalytics.operations#LinkedStorageAccountsOperations.{}',215        client_factory=cf_log_analytics_linked_storage,216        exception_handler=exception_handler)217    log_analytics_linked_storage_custom = CliCommandType(218        operations_tmpl='azure.cli.command_modules.monitor.operations.log_analytics_linked_storage_account#{}',219        client_factory=cf_log_analytics_linked_storage,220        exception_handler=exception_handler)221    monitor_general_custom = CliCommandType(222        operations_tmpl='azure.cli.command_modules.monitor.operations.general_operations#{}',223        client_factory=cf_metric_alerts,224        exception_handler=exception_handler)225    with self.command_group('monitor action-group', action_group_sdk, custom_command_type=action_group_custom) as g:226        g.show_command('show', 'get', table_transformer=action_group_list_table)227        g.command('create', 'create_or_update', table_transformer=action_group_list_table, validator=process_action_group_detail_for_creation)228        g.command('delete', 'delete')229        g.custom_command('enable-receiver', 'enable_receiver', table_transformer=action_group_list_table)230        g.custom_command('list', 'list_action_groups', table_transformer=action_group_list_table)231        g.generic_update_command('update', custom_func_name='update_action_groups', setter_arg_name='action_group',232                                 table_transformer=action_group_list_table)233    with self.command_group('monitor activity-log', activity_log_sdk) as g:234        g.custom_command('list', 'list_activity_log', client_factory=cf_activity_log)235        g.command('list-categories', 'list')236    with self.command_group('monitor activity-log alert', activity_log_alerts_sdk, custom_command_type=activity_log_alerts_custom) as g:237        g.custom_command('list', 'list_activity_logs_alert')238        g.custom_command('create', 'create')239        g.show_command('show', 'get')240        g.command('delete', 'delete')241        g.generic_update_command('update', custom_func_name='update', setter_arg_name='activity_log_alert')242        g.custom_command('action-group add', 'add_action_group')243        g.custom_command('action-group remove', 'remove_action_group')244        g.custom_command('scope add', 'add_scope')245        g.custom_command('scope remove', 'remove_scope')246    with self.command_group('monitor alert', alert_sdk, custom_command_type=alert_custom, deprecate_info=self.deprecate(redirect='monitor metrics alert', hide='2.0.44')) as g:247        g.custom_command('create', 'create_metric_rule')248        g.command('delete', 'delete')249        g.show_command('show', 'get')250        g.command('list', 'list_by_resource_group')251        g.command('show-incident', 'get', command_type=alert_rule_incidents_sdk)252        g.command('list-incidents', 'list_by_alert_rule', command_type=alert_rule_incidents_sdk)253        g.generic_update_command('update', custom_func_name='update_metric_rule')254    with self.command_group('monitor autoscale', autoscale_sdk, custom_command_type=autoscale_custom) as g:255        g.custom_command('create', 'autoscale_create', validator=process_autoscale_create_namespace)256        g.generic_update_command('update', custom_func_name='autoscale_update', custom_func_type=autoscale_custom)257        g.command('delete', 'delete')258        g.show_command('show', 'get')259        g.command('list', 'list_by_resource_group')260    with self.command_group('monitor autoscale profile', autoscale_sdk, custom_command_type=autoscale_custom) as g:261        g.custom_command('create', 'autoscale_profile_create')262        g.custom_command('list', 'autoscale_profile_list')263        g.custom_show_command('show', 'autoscale_profile_show')264        g.custom_command('delete', 'autoscale_profile_delete')265        g.custom_command('list-timezones', 'autoscale_profile_list_timezones')266    with self.command_group('monitor autoscale rule', autoscale_sdk, custom_command_type=autoscale_custom) as g:267        g.custom_command('create', 'autoscale_rule_create')268        g.custom_command('list', 'autoscale_rule_list')269        g.custom_command('delete', 'autoscale_rule_delete')270        g.custom_command('copy', 'autoscale_rule_copy')271    with self.command_group('monitor autoscale-settings', autoscale_sdk, custom_command_type=autoscale_custom,272                            deprecate_info=self.deprecate(redirect='monitor autoscale', hide='2.0.34')) as g:273        g.command('create', 'create_or_update', deprecate_info='az monitor autoscale create')274        g.command('delete', 'delete', deprecate_info='az monitor autoscale delete')275        g.show_command('show', 'get', deprecate_info='az monitor autoscale show')276        g.command('list', 'list_by_resource_group', deprecate_info='az monitor autoscale list')277        g.custom_command('get-parameters-template', 'scaffold_autoscale_settings_parameters', deprecate_info='az monitor autoscale show')278        g.generic_update_command('update', deprecate_info='az monitor autoscale update')279    with self.command_group('monitor diagnostic-settings', diagnostics_sdk, custom_command_type=diagnostics_custom) as g:280        from .validators import validate_diagnostic_settings281        g.custom_command('create', 'create_diagnostics_settings', validator=validate_diagnostic_settings)282        g.show_command('show', 'get')283        g.command('list', 'list')284        g.command('delete', 'delete')285        g.generic_update_command('update')286    with self.command_group('monitor diagnostic-settings categories', diagnostics_categories_sdk) as g:287        g.show_command('show', 'get')288        g.command('list', 'list')289    with self.command_group('monitor log-profiles', log_profiles_sdk, custom_command_type=log_profiles_custom) as g:290        g.custom_command('create', 'create_log_profile_operations')291        g.command('delete', 'delete')292        g.show_command('show', 'get')293        g.command('list', 'list')294        g.generic_update_command('update')295    with self.command_group('monitor metrics') as g:296        from .transformers import metrics_table, metrics_definitions_table, metrics_namespaces_table297        g.command('list', 'list_metrics', command_type=monitor_custom, table_transformer=metrics_table)298        g.command('list-definitions', 'list', command_type=metric_definitions_sdk, table_transformer=metrics_definitions_table)299        g.command('list-namespaces', 'list', is_preview=True, command_type=metric_namespaces_sdk, table_transformer=metrics_namespaces_table)300    with self.command_group('monitor metrics alert', metric_alert_sdk, custom_command_type=alert_custom, client_factory=cf_metric_alerts) as g:301        g.custom_command('create', 'create_metric_alert')302        g.command('delete', 'delete')303        g.custom_command('list', 'list_metric_alerts', custom_command_type=alert_custom)304        g.show_command('show', 'get')305        g.generic_update_command('update', custom_func_name='update_metric_alert', custom_func_type=alert_custom)306    with self.command_group('monitor metrics alert dimension', metric_alert_sdk, custom_command_type=alert_custom) as g:307        from .validators import validate_metrics_alert_dimension308        g.custom_command('create', 'create_metric_alert_dimension', custom_command_type=alert_custom,309                         validator=validate_metrics_alert_dimension, is_preview=True)310    with self.command_group('monitor metrics alert condition', metric_alert_sdk, custom_command_type=alert_custom) as g:311        from .validators import validate_metrics_alert_condition312        g.custom_command('create', 'create_metric_alert_condition', custom_command_type=alert_custom,313                         validator=validate_metrics_alert_condition, is_preview=True)314    with self.command_group('monitor log-analytics workspace', log_analytics_workspace_sdk, custom_command_type=log_analytics_workspace_custom) as g:315        g.custom_command('create', 'create_log_analytics_workspace', supports_no_wait=True)316        g.generic_update_command('update', setter_name='begin_create_or_update', custom_func_name='update_log_analytics_workspace')317        g.show_command('show', 'get')318        g.command('delete', 'begin_delete', confirmation=True)319        g.custom_command('list', 'list_log_analytics_workspace')320        g.custom_command('list-deleted-workspaces', 'list_deleted_log_analytics_workspaces', custom_command_type=log_analytics_deleted_workspace_custom)321        g.custom_command('recover', 'recover_log_analytics_workspace', supports_no_wait=True)322        g.command('get-schema', 'get', command_type=log_analytics_workspace_schema_sdk)323        g.command('list-usages', 'list', command_type=log_analytics_workspace_usage_sdk)324        g.command('list-management-groups', 'list', command_type=log_analytics_workspace_management_groups_sdk)325        g.command('get-shared-keys', 'get_shared_keys', command_type=log_analytics_workspace_shared_keys_sdk)326    with self.command_group('monitor log-analytics workspace table', log_analytics_workspace_table_sdk, custom_command_type=log_analytics_workspace_custom, client_factory=cf_log_analytics_workspace_tables) as g:327        g.command('list', 'list_by_workspace')328        g.show_command('show', 'get')329        g.custom_command('update', 'update_log_analytics_workspace_table')330    with self.command_group('monitor log-analytics workspace data-export', log_analytics_workspace_data_exports_sdk,331                            custom_command_type=log_analytics_workspace_custom) as g:332        g.command('list', 'list_by_workspace')333        g.show_command('show', 'get')334        g.custom_command('create', 'create_log_analytics_workspace_data_exports',335                         client_factory=cf_log_analytics_workspace_data_exports)336        g.generic_update_command('update', custom_func_name='update_log_analytics_workspace_data_exports')337        g.command('delete', 'delete', confirmation=True)338    with self.command_group('monitor log-analytics workspace pack', log_analytics_workspace_intelligence_packs_sdk) as g:339        g.command('list', 'list')340        g.command('enable', 'enable')341        g.command('disable', 'disable')342    with self.command_group('monitor log-analytics workspace saved-search', log_analytics_workspace_saved_search_sdk, custom_command_type=log_analytics_workspace_custom) as g:343        g.custom_command('create', 'create_log_analytics_workspace_saved_search', client_factory=cf_log_analytics_workspace_saved_searches)344        g.generic_update_command('update', custom_func_name='update_log_analytics_workspace_saved_search', client_factory=cf_log_analytics_workspace_saved_searches)345        g.command('delete', 'delete', confirmation=True)346        g.show_command('show', 'get')347        g.command('list', 'list_by_workspace')348    with self.command_group('monitor log-analytics workspace linked-service', log_analytics_workspace_linked_service_sdk, custom_command_type=log_analytics_workspace_linked_service_custom) as g:349        g.custom_command('create', 'create_log_analytics_workspace_linked_service', supports_no_wait=True)350        g.generic_update_command('update', setter_name='begin_create_or_update', custom_func_name='update_log_analytics_workspace_linked_service', supports_no_wait=True)351        g.show_command('show', 'get')352        g.command('list', 'list_by_workspace')353        g.command('delete', 'begin_delete', confirmation=True, supports_no_wait=True)354        g.wait_command('wait')355    with self.command_group('monitor log-analytics cluster', log_analytics_cluster_sdk, custom_command_type=log_analytics_cluster_custom) as g:356        g.custom_command('create', 'create_log_analytics_cluster', supports_no_wait=True)357        g.custom_command('update', 'update_log_analytics_cluster', supports_no_wait=True)358        g.show_command('show', 'get')359        g.command('delete', 'begin_delete', confirmation=True, supports_no_wait=True)360        g.custom_command('list', 'list_log_analytics_clusters')361        g.wait_command('wait')362    with self.command_group('monitor log-analytics workspace linked-storage', log_analytics_linked_storage_sdk, custom_command_type=log_analytics_linked_storage_custom) as g:363        g.custom_command('create', 'create_log_analytics_workspace_linked_storage_accounts')364        g.custom_command('add', 'add_log_analytics_workspace_linked_storage_accounts')365        g.custom_command('remove', 'remove_log_analytics_workspace_linked_storage_accounts')366        g.command('delete', 'delete', confirmation=True)367        g.show_command('show', 'get')368        g.command('list', 'list_by_workspace')369    with self.command_group('monitor', metric_alert_sdk, custom_command_type=monitor_general_custom) as g:370        g.custom_command('clone', 'clone_existed_settings', is_preview=True)371    with self.command_group('monitor private-link-scope', private_link_scopes_sdk, custom_command_type=private_link_scope_custom, is_preview=True) as g:372        g.custom_show_command('show', 'show_private_link_scope')373        g.custom_command('list', 'list_private_link_scope')374        g.custom_command('create', 'create_private_link_scope')375        g.custom_command('update', 'update_private_link_scope')376        g.custom_command('delete', 'delete_private_link_scope', confirmation=True)377    with self.command_group('monitor private-link-scope scoped-resource', private_link_scoped_resources_sdk, custom_command_type=private_link_scope_custom, is_preview=True) as g:378        g.custom_show_command('show', 'show_private_link_scope_resource', client_factory=cf_private_link_scoped_resources)379        g.custom_command('list', 'list_private_link_scope_resource', client_factory=cf_private_link_scoped_resources)380        g.custom_command('create', 'create_private_link_scope_resource', client_factory=cf_private_link_scoped_resources)381        g.custom_command('delete', 'delete_private_link_scope_resource', client_factory=cf_private_link_scoped_resources, confirmation=True)382    with self.command_group('monitor private-link-scope private-link-resource', private_link_resources_sdk, custom_command_type=private_link_scope_custom, is_preview=True) as g:383        g.custom_show_command('show', 'show_private_link_resource', client_factory=cf_private_link_resources)384        from azure.cli.core.commands.transform import gen_dict_to_list_transform385        g.custom_command('list', 'list_private_link_resource', client_factory=cf_private_link_resources, transform=gen_dict_to_list_transform(key="value"))386    with self.command_group('monitor private-link-scope private-endpoint-connection', private_endpoint_connections_sdk, custom_command_type=private_link_scope_custom, is_preview=True) as g:387        g.custom_show_command('show', 'show_private_endpoint_connection', client_factory=cf_private_endpoint_connections,388                              validator=validate_private_endpoint_connection_id)389        g.custom_command('list', 'list_private_endpoint_connection', client_factory=cf_private_endpoint_connections)390        g.custom_command('approve', 'approve_private_endpoint_connection', client_factory=cf_private_endpoint_connections,391                         validator=validate_private_endpoint_connection_id)392        g.custom_command('reject', 'reject_private_endpoint_connection', client_factory=cf_private_endpoint_connections,393                         validator=validate_private_endpoint_connection_id)394        g.custom_command('delete', 'delete_private_endpoint_connection', client_factory=cf_private_endpoint_connections,395                         validator=validate_private_endpoint_connection_id, confirmation=True)396    with self.command_group('monitor diagnostic-settings subscription', subscription_dianostic_settings_sdk, custom_command_type=subscription_dianostic_settings_custom) as g:397        g.custom_command('create', 'create_subscription_diagnostic_settings')398        g.command('delete', 'delete', confirmation=True)399        g.show_command('show', 'get')400        g.command('list', 'list')...test_exceptions.py
Source:test_exceptions.py  
...53        with self.settings(DEBUG_PROPAGATE_EXCEPTIONS=False):54            try:55                raise APIException()56            except Exception as exc:57                response = exception_handler(exc, {})58                assert isinstance(response, Response)59                assert response.status_code == 50060    def test_exception_handler_returns_response_for_404(self):61        exception_handler = api_settings.EXCEPTION_HANDLER62        with self.settings(DEBUG_PROPAGATE_EXCEPTIONS=False):63            try:64                raise Http404()65            except Exception as exc:66                response = exception_handler(exc, {})67                assert isinstance(response, Response)68                assert response.status_code == 40469    def test_exception_handler_returns_response_for_403(self):70        exception_handler = api_settings.EXCEPTION_HANDLER71        with self.settings(DEBUG_PROPAGATE_EXCEPTIONS=False):72            try:73                raise PermissionDenied()74            except Exception as exc:75                response = exception_handler(exc, {})76                assert isinstance(response, Response)77                assert response.status_code == 40378    def test_non_api_exception_handler_returns_response(self):79        # Regular DRF exception handler does not return a Response for non-api80        # exceptions, but we do.81        exception_handler = api_settings.EXCEPTION_HANDLER82        with self.settings(DEBUG_PROPAGATE_EXCEPTIONS=False):83            try:84                raise Exception()85            except Exception as exc:86                response = exception_handler(exc, {})87                assert isinstance(response, Response)88                assert response.status_code == 50089    def test_api_exception_handler_with_propagation(self):90        exception_handler = api_settings.EXCEPTION_HANDLER91        with self.assertRaises(APIException):92            with self.settings(DEBUG_PROPAGATE_EXCEPTIONS=True):93                try:94                    raise APIException()95                except Exception as exc:96                    exception_handler(exc, {})97    def test_exception_handler_404_with_propagation(self):98        exception_handler = api_settings.EXCEPTION_HANDLER99        with self.assertRaises(Http404):100            with self.settings(DEBUG_PROPAGATE_EXCEPTIONS=True):101                try:102                    raise Http404()103                except Exception as exc:104                    exception_handler(exc, {})105    def test_exception_handler_403_with_propagation(self):106        exception_handler = api_settings.EXCEPTION_HANDLER107        with self.assertRaises(PermissionDenied):108            with self.settings(DEBUG_PROPAGATE_EXCEPTIONS=True):109                try:110                    raise PermissionDenied()111                except Exception as exc:112                    exception_handler(exc, {})113    def test_non_api_exception_handler_with_propagation(self):114        # Regular DRF exception handler does not return a Response for non-api115        # exceptions, but we do.116        exception_handler = api_settings.EXCEPTION_HANDLER117        with self.assertRaises(KeyError):118            with self.settings(DEBUG_PROPAGATE_EXCEPTIONS=True):119                try:120                    raise KeyError()121                except Exception as exc:...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
