Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from __future__ import annotations

import contextlib
import importlib
import logging
from collections.abc import MutableMapping
from functools import cache
Expand Down Expand Up @@ -130,26 +132,67 @@ def mock_any_of(allowed_values: list) -> HookMetaService.MockEnum:
"""Mock for wtforms.validators.any_of."""
return HookMetaService.MockEnum(allowed_values)

with (
mock.patch("wtforms.StringField", HookMetaService.MockStringField),
mock.patch("wtforms.fields.StringField", HookMetaService.MockStringField),
mock.patch("wtforms.fields.simple.StringField", HookMetaService.MockStringField),
mock.patch("wtforms.IntegerField", HookMetaService.MockIntegerField),
mock.patch("wtforms.fields.IntegerField", HookMetaService.MockIntegerField),
mock.patch("wtforms.PasswordField", HookMetaService.MockPasswordField),
mock.patch("wtforms.BooleanField", HookMetaService.MockBooleanField),
mock.patch("wtforms.fields.BooleanField", HookMetaService.MockBooleanField),
mock.patch("wtforms.fields.simple.BooleanField", HookMetaService.MockBooleanField),
mock.patch("flask_babel.lazy_gettext", mock_lazy_gettext),
mock.patch("flask_appbuilder.fieldwidgets.BS3TextFieldWidget", HookMetaService.MockAnyWidget),
mock.patch("flask_appbuilder.fieldwidgets.BS3TextAreaFieldWidget", HookMetaService.MockAnyWidget),
mock.patch("flask_appbuilder.fieldwidgets.BS3PasswordFieldWidget", HookMetaService.MockAnyWidget),
mock.patch("wtforms.validators.Optional", HookMetaService.MockOptional),
mock.patch("wtforms.validators.any_of", mock_any_of),
):
with contextlib.ExitStack() as stack:
try:
importlib.import_module("wtforms")
stack.enter_context(mock.patch("wtforms.StringField", HookMetaService.MockStringField))
stack.enter_context(mock.patch("wtforms.fields.StringField", HookMetaService.MockStringField))
stack.enter_context(
mock.patch("wtforms.fields.simple.StringField", HookMetaService.MockStringField)
)

stack.enter_context(mock.patch("wtforms.IntegerField", HookMetaService.MockIntegerField))
stack.enter_context(
mock.patch("wtforms.fields.IntegerField", HookMetaService.MockIntegerField)
)
stack.enter_context(mock.patch("wtforms.PasswordField", HookMetaService.MockPasswordField))
stack.enter_context(mock.patch("wtforms.BooleanField", HookMetaService.MockBooleanField))
stack.enter_context(
mock.patch("wtforms.fields.BooleanField", HookMetaService.MockBooleanField)
)
stack.enter_context(
mock.patch("wtforms.fields.simple.BooleanField", HookMetaService.MockBooleanField)
)
stack.enter_context(mock.patch("wtforms.validators.Optional", HookMetaService.MockOptional))
stack.enter_context(mock.patch("wtforms.validators.any_of", mock_any_of))
except ImportError:
pass

try:
importlib.import_module("flask_babel")
stack.enter_context(mock.patch("flask_babel.lazy_gettext", mock_lazy_gettext))
except ImportError:
pass

try:
importlib.import_module("flask_appbuilder")
stack.enter_context(
mock.patch(
"flask_appbuilder.fieldwidgets.BS3TextFieldWidget", HookMetaService.MockAnyWidget
)
)
stack.enter_context(
mock.patch(
"flask_appbuilder.fieldwidgets.BS3TextAreaFieldWidget", HookMetaService.MockAnyWidget
)
)
stack.enter_context(
mock.patch(
"flask_appbuilder.fieldwidgets.BS3PasswordFieldWidget", HookMetaService.MockAnyWidget
)
)
except ImportError:
pass

pm = ProvidersManager()
return pm.hooks, pm.connection_form_widgets, pm.field_behaviours

return (
{},
{},
{},
) # Make mypy happy, should never been reached https://github.com/python/mypy/issues/7726

@staticmethod
def _make_standard_fields(field_behaviour: dict | None) -> StandardHookFields | None:
if not field_behaviour:
Expand Down