1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
import pytest
from wtforms.i18n import DummyTranslations
@pytest.fixture
def dummy_form():
return DummyForm()
@pytest.fixture
def dummy_field():
return DummyField()
@pytest.fixture
def dummy_field_class():
return DummyField
@pytest.fixture
def basic_widget_dummy_field(dummy_field_class):
return dummy_field_class("foo", name="bar", label="label", id="id")
@pytest.fixture
def select_dummy_field(dummy_field_class):
return dummy_field_class([("foo", "lfoo", True, {}), ("bar", "lbar", False, {})])
@pytest.fixture
def html5_dummy_field(dummy_field_class):
return dummy_field_class("42", name="bar", id="id")
@pytest.fixture
def really_lazy_proxy():
return ReallyLazyProxy()
class DummyField:
_translations = DummyTranslations()
def __init__(
self,
data=None,
name=None,
errors=(),
raw_data=None,
label=None,
id=None,
field_type="StringField",
):
self.data = data
self.name = name
self.errors = list(errors)
self.raw_data = raw_data
self.label = label
self.id = id if id else ""
self.type = field_type
def __call__(self, **other):
return self.data
def __str__(self):
return self.data
def __iter__(self):
return iter(self.data)
def _value(self):
return self.data
def iter_choices(self):
return iter(self.data)
def iter_groups(self):
return []
def has_groups(self):
return False
def gettext(self, string):
return self._translations.gettext(string)
def ngettext(self, singular, plural, n):
return self._translations.ngettext(singular, plural, n)
class DummyForm(dict):
pass
class ReallyLazyProxy:
def __str__(self):
raise Exception(
"Translator function called during form declaration: it"
" should be called at response time."
)
|