From b475c10c934a96a4ec3a50550f3c21e7597aa9bb Mon Sep 17 00:00:00 2001 From: themylogin Date: Tue, 26 Nov 2024 12:49:49 +0100 Subject: [PATCH] Fix cloud backup tests --- src/middlewared/middlewared/api/base/types/base/string.py | 2 +- src/middlewared/middlewared/api/v25_04_0/cloud_backup.py | 4 ++-- .../middlewared/pytest/unit/api/base/types/test_base.py | 8 ++++++++ tests/api2/test_account_privilege_role_private_fields.py | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/middlewared/middlewared/api/base/types/base/string.py b/src/middlewared/middlewared/api/base/types/base/string.py index c0204d50ea2a..827d263e6c98 100644 --- a/src/middlewared/middlewared/api/base/types/base/string.py +++ b/src/middlewared/middlewared/api/base/types/base/string.py @@ -51,7 +51,7 @@ def __get_pydantic_core_schema__( LongString = Annotated[ LongStringWrapper, BeforeValidator(LongStringWrapper), - PlainSerializer(lambda x: undefined if x == undefined else x.value), + PlainSerializer(lambda x: x.value if isinstance(x, LongStringWrapper) else x), ] NonEmptyString = Annotated[str, Field(min_length=1)] diff --git a/src/middlewared/middlewared/api/v25_04_0/cloud_backup.py b/src/middlewared/middlewared/api/v25_04_0/cloud_backup.py index a5f80b22662f..d67155c15db4 100644 --- a/src/middlewared/middlewared/api/v25_04_0/cloud_backup.py +++ b/src/middlewared/middlewared/api/v25_04_0/cloud_backup.py @@ -31,8 +31,8 @@ class CloudBackupCreate(BaseModel): pre_script: LongString = "" post_script: LongString = "" snapshot: bool = False - include: list[NonEmptyString] - exclude: list[NonEmptyString] + include: list[NonEmptyString] = [] + exclude: list[NonEmptyString] = [] args: LongString = "" enabled: bool = True diff --git a/src/middlewared/middlewared/pytest/unit/api/base/types/test_base.py b/src/middlewared/middlewared/pytest/unit/api/base/types/test_base.py index 966e80d3e1f8..7d917ac56e5a 100644 --- a/src/middlewared/middlewared/pytest/unit/api/base/types/test_base.py +++ b/src/middlewared/middlewared/pytest/unit/api/base/types/test_base.py @@ -40,3 +40,11 @@ class SecretLongStringMethodArgs(BaseModel): def test_secret_long_string(): assert accept_params(SecretLongStringMethodArgs, ["test"]) == ["test"] + + +class LongStringDefaultMethodArgs(BaseModel): + str: LongString = "" + + +def test_long_string_default(): + assert accept_params(LongStringDefaultMethodArgs, []) == [""] diff --git a/tests/api2/test_account_privilege_role_private_fields.py b/tests/api2/test_account_privilege_role_private_fields.py index 91df0f1f3b47..40db7537c047 100644 --- a/tests/api2/test_account_privilege_role_private_fields.py +++ b/tests/api2/test_account_privilege_role_private_fields.py @@ -168,7 +168,7 @@ def vmware(): ("acme.dns.authenticator", dns_authenticator, {}, ["attributes"]), ("certificate", 1, {}, ["privatekey", "issuer"]), ("certificateauthority", certificateauthority, {}, ["privatekey", "issuer"]), - ("cloud_backup", cloudbackup, {}, ["credentials.provider", "password"]), + ("cloud_backup", cloudbackup, {}, ["credentials.provider.pass", "password"]), ("cloudsync.credentials", cloudsync_credential, {}, ["provider.pass"]), ("cloudsync", cloudsync, {}, ["credentials.provider", "encryption_password"]), ("disk", disk, {"extra": {"passwords": True}}, ["passwd"]),