Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Release History
* `az postgres flexible-server backup create`: Fix duplicate auto-generated backup names after deletions (#33684)
* `az postgres flexible-server create`: Add example to create elastic cluster with custom database name (#33712)
* `az postgres flexible-server upgrade`: Introduced `--validate-only` param for PVC (#33683)
* `az postgres flexible-server maintenance-event list`: Fix `TypeError` caused by an unsupported `--ids` argument (#33846)

2.88.0
++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ def _flexible_server_params(command_group):

with self.argument_context('{} flexible-server maintenance-event list'.format(command_group)) as c:
c.argument('maintenance_status', arg_type=maintenance_status_arg_type)
c.argument('server_name', arg_type=server_name_resource_arg_type, id_part=None)
c.ignore('ids')
Comment on lines 686 to 689

for scope in ['show', 'reschedule', 'apply-now']:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import unittest
from unittest import mock

from knack.arguments import IgnoreAction
from azure.cli.core.mock import DummyCli
from azure.cli.command_modules.postgresql import PostgreSQLCommandsLoader


def _load_command_and_arguments(command):
"""Load the PostgreSQL command loader for *command* and return the loader."""
cli = DummyCli(commands_loader_cls=PostgreSQLCommandsLoader)
loader = PostgreSQLCommandsLoader(cli)
cli.invocation = mock.MagicMock()
cli.invocation.commands_loader = loader
loader.command_name = command
loader.load_command_table(None)
loader.load_arguments(command)
loader._update_command_definitions()
return loader


class MaintenanceEventParamsTest(unittest.TestCase):
"""Regression test for https://github.com/Azure/azure-cli/issues/33846.

`az postgres flexible-server maintenance-event list` does not accept an `ids`
keyword argument in its custom command implementation, so the auto-generated
`--ids` argument must be ignored for that command. Otherwise, invoking the
command with `--ids` results in a TypeError.
"""

def test_maintenance_event_list_ignores_ids(self):
"""The ``ids`` argument for the list command must use IgnoreAction."""
loader = _load_command_and_arguments(
'postgres flexible-server maintenance-event list'
)
ids_arg = loader.argument_registry.arguments.get(
'postgres flexible-server maintenance-event list', {}
).get('ids')
self.assertIsNotNone(ids_arg, "'ids' argument not found in argument registry")
action = ids_arg.settings.get('action')
self.assertIs(
action,
IgnoreAction,
"Expected 'ids' to be registered with IgnoreAction (via c.ignore('ids')), "
"but got: {}".format(action),
)


if __name__ == '__main__':
unittest.main()