def test_clean(self): inner = forms.DecimalField() f = LookupChoiceField(inner, [('gt', 'gt'), ('lt', 'lt')], required=False) self.assertEqual( f.clean(['12.34', 'lt']), Lookup(to_d(12.34), 'lt')) self.assertEqual( f.clean([]), None) with self.assertRaisesMessage(forms.ValidationError, 'Select a lookup.'): f.clean(['12.34', ''])
def test_render_used_html5(self): inner = forms.DecimalField() f = LookupChoiceField(inner, [('gt', 'gt'), ('lt', 'lt')], empty_label=None) self.assertHTMLEqual(f.widget.render('price', ''), """ <input type="number" step="any" name="price" /> <select name="price_lookup"> <option value="gt">gt</option> <option value="lt">lt</option> </select>""") self.assertHTMLEqual(f.widget.render('price', ['abc', 'lt']), """ <input type="number" step="any" name="price" value="abc" /> <select name="price_lookup"> <option value="gt">gt</option> <option selected="selected" value="lt">lt</option> </select>""")
def test_clean(self): inner = forms.DecimalField() f = LookupChoiceField(inner, [('gt', 'gt'), ('lt', 'lt')], required=False) self.assertEqual(f.clean(['12.34', 'lt']), Lookup(to_d(12.34), 'lt')) self.assertEqual(f.clean([]), None) with self.assertRaisesMessage(forms.ValidationError, 'Select a lookup.'): f.clean(['12.34', ''])
def test_field(self): inner = forms.DecimalField() f = LookupChoiceField(inner, [('gt', 'gt'), ('lt', 'lt')]) self.assertEqual(len(f.fields), 2)