def test_no_data(self): form = self.get_form() assert not form.validate(), "Form was valid" ichoices = list(form.author.iter_choices()) self.assertEqual(len(ichoices), len(self.authors)) for author, (key, label, selected) in zip(self.authors, ichoices): self.assertEqual(key, KeyPropertyField._key_value(author.key))
def test_no_data(self, client): with client.context(): self.setUp() form = self.get_form() assert not form.validate(), "Form was valid" ichoices = list(form.author.iter_choices()) assert len(ichoices) == len(self.authors) for author, (key, label, selected) in zip(self.authors, ichoices): assert key == KeyPropertyField._key_value(author.key)
def test_valid_form_data(self): # Valid data data = DummyPostData( author=KeyPropertyField._key_value(self.first_author_key)) form = self.get_form(data) assert form.validate(), "Form validation failed. %r" % form.errors # Check that our first author was selected ichoices = list(form.author.iter_choices()) self.assertEqual(len(ichoices), len(self.authors)) self.assertEqual(list(x[2] for x in ichoices), [True, False, False]) self.assertEqual(form.author.data, self.first_author_key)
def test_valid_form_data(self, client): with client.context(): self.setUp() # Valid data data = DummyPostData( author=KeyPropertyField._key_value(self.first_author_key)) form = self.get_form(data) assert form.validate(), "Form validation failed. %r" % form.errors # Check that our first author was selected ichoices = list(form.author.iter_choices()) assert len(ichoices) == len(self.authors) assert [x[2] for x in ichoices] == [True, False, False] assert form.author.data == self.first_author_key
class F(Form): author = KeyPropertyField(reference_class=Author)
class F(Form): empty = KeyPropertyField(reference_class=AncestorModel)
class RastileimauksetForm(RastileimauksetBaseForm): aika = StringField('aika', validators=[InputRequired(), validateAika]) rasti = KeyPropertyField(reference_class=Rasti, get_label=rasti_label) #, validate_koodi)