class _FieldRenderTestCase(MongoengineTestCase): # mongoengine field instance to test field_class = None # widget rendering result (most common value) rendered_widget = '<input name="test_field" type="text" />' # hook for not implemented fields is_not_implemented = False def setUp(self): self.generator = MongoFormFieldGenerator() def get_field(self): class TestDocument(Document): test_field = self.field_class() return TestDocument._fields['test_field'] def get_form_field(self): return self.generator.generate('test_field', self.get_field()) def runTest(self): if self.is_not_implemented: self.assertRaises(NotImplementedError, self.get_form_field) else: self.assertMultiLineEqual( self.rendered_widget, self.get_form_field().widget.render('test_field', None))
class _FieldValidateTestCase(MongoengineTestCase): # mongoengine field instance to test field_class = None # list of correct sample field values before and after clean correct_samples = () # list of incorrect sample field values before clean incorrect_samples = () # hook for not implemented fields is_not_implemented = False def setUp(self): self.generator = MongoFormFieldGenerator() def get_field(self): class TestDocument(Document): test_field = self.field_class() return TestDocument._fields['test_field'] def get_form_field(self): return self.generator.generate('test_field', self.get_field()) def runTest(self): # skip test as we have already tested this in render tests if self.is_not_implemented: return # test for correct samples for dirty_value, clean_value in self.correct_samples: self.assertEqual( clean_value, self.get_form_field().validate(dirty_value)) # test for incorrect samples for value in self.incorrect_samples: self.assertRaises( ValidationError, lambda: self.get_form_field().validate(value))
class _FieldValidateTestCase(MongoengineTestCase): # mongoengine field instance to test field_class = None # list of correct sample field values before and after clean correct_samples = () # list of incorrect sample field values before clean incorrect_samples = () # hook for not implemented fields is_not_implemented = False def setUp(self): self.generator = MongoFormFieldGenerator() def get_field(self): class TestDocument(Document): test_field = self.field_class() return TestDocument._fields['test_field'] def get_form_field(self): return self.generator.generate('test_field', self.get_field()) def runTest(self): # skip test as we have already tested this in render tests if self.is_not_implemented: return # test for correct samples for dirty_value, clean_value in self.correct_samples: self.assertEqual(clean_value, self.get_form_field().validate(dirty_value)) # test for incorrect samples for value in self.incorrect_samples: self.assertRaises(ValidationError, lambda: self.get_form_field().validate(value))
def generate_field(field): generator = MongoFormFieldGenerator() return generator.generate(field)
def setUp(self): self.generator = MongoFormFieldGenerator()