def fields(self, fields): fields.text_input_field = Field(label='A TextInput') fields.password_field = Field(label='A PasswordInput') fields.text_area_field = Field(label='A TextArea') fields.text_input_without_label = Field(label='A TextInput without a label') fields.cue_field = Field(label='A TextInput in a CueInput') fields.choice_field = ChoiceField([Choice(False, BooleanField(label='None selected')), ChoiceGroup('Numbers', [Choice(1, IntegerField(label='One')), Choice(2, IntegerField(label='Two')), Choice(3, IntegerField(label='Three'))]), ChoiceGroup('Colours', [Choice('r', Field(label='Red')), Choice('g', Field(label='Green'))]) ], label='A SelectInput') fields.multi_choice_field = MultiChoiceField([Choice(1, IntegerField(label='One')), Choice(2, IntegerField(label='Two')), Choice(3, IntegerField(label='Three'))], label='A SelectInput allowing multiple choices') fields.another_multi_choice_field = MultiChoiceField([Choice('a', Field(label='Newton')), Choice('b', Field(label='Archimedes')), Choice('c', Field(label='Einstein')), ], default=['a', 'c'], label='A CheckboxInput allowing multiple choices') fields.boolean_field = BooleanField(label='A CheckboxInput to toggle') fields.radio_choice_field = ChoiceField([Choice(1, IntegerField(label='One')), Choice(2, IntegerField(label='Two')), Choice(3, IntegerField(label='Three'))], label='A RadioButtonSelectInput') fields.fuzzy_date_field = DateField(label='A fuzzy TextInput for a Date')
def test_date_marshalling(fixture): """A DateField marshalls human readable date representation to a datetime.date object. (It tolerates non-precise input.) """ field = DateField() obj = fixture.model_object field.bind('date_value', obj) # From input for input_string in ['10 November 2012', '10/11/2012']: field.from_input(input_string) assert obj.date_value == datetime.date(2012, 11, 10) # As input obj.date_value = datetime.date(2010, 11, 10) actual_output = field.as_input() assert actual_output == '10 Nov 2010'
def fields(self, fields): fields.a_field = DateField()
def test_date_validation(fixture): """A DateField can validate its input based on a min or max value and expects fuzzy but sensible input.""" field = DateField() obj = fixture.model_object field.bind('date_value', obj) # Case invalid with expected(DateConstraint): field.set_user_input('sdfdf') # Case valid with expected(NoException): field.set_user_input('13 Dec') limit_date = datetime.date(2012, 11, 13) before_limit = '12 Nov 2012' after_limit = '14 Nov 2012' # Case Max field = DateField(max_value=limit_date) with expected(MaxValueConstraint): field.set_user_input(after_limit) # Case Min field = DateField(min_value=limit_date) with expected(MinValueConstraint): field.set_user_input(before_limit)
def new_field(self, label='the label'): return DateField(label=label)