Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slawande2 committed Sep 26, 2024
1 parent 0b739ed commit 1cd93d5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
8 changes: 5 additions & 3 deletions python/az/aro/azext_aro/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def validate_client_id(namespace):

if namespace.client_secret is None or not str(namespace.client_secret):
raise RequiredArgumentMissingError('Must specify --client-secret with --client-id.') # pylint: disable=line-too-long
raise RequiredArgumentMissingError('--client-id must be not set with --upgradeable-to.') # pylint: disable=line-too-long
if namespace.upgradeable_to is not None:
raise RequiredArgumentMissingError('--client-id must be not set with --upgradeable-to.') # pylint: disable=line-too-long


def validate_client_secret(isCreate):
Expand All @@ -65,7 +66,8 @@ def _validate_client_secret(namespace):
raise MutuallyExclusiveArgumentError('Must not specify --client-secret when --assign-platform-workload-identity is used') # pylint: disable=line-too-long
if isCreate and (namespace.client_id is None or not str(namespace.client_id)):
raise RequiredArgumentMissingError('Must specify --client-id with --client-secret.')
raise RequiredArgumentMissingError('--client-secret must be not set with --upgradeable-to.') # pylint: disable=line-too-long
if namespace.upgradeable_to is not None:
raise RequiredArgumentMissingError('--client-secret must be not set with --upgradeable-to.') # pylint: disable=line-too-long

return _validate_client_secret

Expand Down Expand Up @@ -292,7 +294,7 @@ def validate_version_format(namespace):
def validate_upgradeable_to_format(namespace):
if not namespace.upgradeable_to:
return
if not re.match(r'^[4-9]{1}\.[0-9]{1,2}\.[0-9]{1,2}$', namespace.upgradeable_to):
if not re.match(r'^[4-9]{1}\.(1[4-9]|[1-9][0-9])\.[0-9]{1,2}$', namespace.upgradeable_to):
raise InvalidArgumentValueError('--upgradeable-to format is invalid')


Expand Down
32 changes: 16 additions & 16 deletions python/az/aro/azext_aro/tests/latest/unit/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_validate_cidr(test_description, dummyclass, attribute_to_get_from_objec
),
(
"should not raise any exception when namespace.client_id is a valid input for creating a UUID and namespace.client_secret has a valid str representation",
Mock(client_id="12345678123456781234567812345678", platform_workload_identities=None, client_secret="12345"),
Mock(upgradeable_to=None, client_id="12345678123456781234567812345678", platform_workload_identities=None, client_secret="12345"),
None
)
]
Expand Down Expand Up @@ -172,15 +172,27 @@ def test_validate_client_id(test_description, namespace, expected_exception):
(
"should not raise any exception when isCreate is true and all arguments valid",
True,
Mock(client_id="12345678123456781234567812345678", client_secret="123", platform_workload_identities=None),
Mock(upgradeable_to=None, client_id="12345678123456781234567812345678", client_secret="123", platform_workload_identities=None),
None
),
(
"should not raise any exception when isCreate is false and all arguments valid",
False,
Mock(client_secret="123", platform_workload_identities=None),
Mock(upgradeable_to=None, client_secret="123", platform_workload_identities=None),
None
),
(
"should raise any exception when isCreate is true and upgradeable_to, client_id and client_secret are present",
True,
Mock(upgradeable_to="4.14.2", client_id="12345678123456781234567812345678", client_secret="123", platform_workload_identities=None),
RequiredArgumentMissingError
),
(
"should raise any exception when isCreate is false and upgradeable_to, client_id and client_secret are present",
False,
Mock(upgradeable_to="4.14.2", client_id="12345678123456781234567812345678", client_secret="123", platform_workload_identities=None),
RequiredArgumentMissingError
),
]


Expand Down Expand Up @@ -1286,18 +1298,6 @@ def test_validate_cluster_identity(test_description, namespace, expected_excepti
None, None
),

(
"should raise RequiredArgumentMissingError Exception because namespace.client_id is present",
Mock(upgradeable_to="4.14.5", client_id="client_id_456", client_secret=None),
RequiredArgumentMissingError, '--client-id must be not set with --upgradeable-to.'
),

(
"should raise RequiredArgumentMissingError Exception because namespace.client_secret is present",
Mock(upgradeable_to="4.14.5", client_id=None, client_secret="secret_123"),
RequiredArgumentMissingError, '--client-secret must be not set with --upgradeable-to.'
),

(
"should raise InvalidArgumentValueError Exception because upgradeable_to format is invalid",
Mock(upgradeable_to="a", client_id=None, client_secret=None),
Expand All @@ -1308,7 +1308,7 @@ def test_validate_cluster_identity(test_description, namespace, expected_excepti
"Should raise InvalidArgumentValueError when --upgradeable-to < 4.14.0",
Mock(upgradeable_to="4.0.4",
client_id=None, client_secret=None),
InvalidArgumentValueError, 'Enabling managed identity requires --upgradeable-to >= 4.14.z'
InvalidArgumentValueError, 'Enabling managed identity requires --upgradeable-to >= 4.14.0'
),

]
Expand Down

0 comments on commit 1cd93d5

Please sign in to comment.