示例#1
0
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))
示例#2
0
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))
示例#3
0
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))
示例#4
0
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)
示例#6
0
 def setUp(self):
     self.generator = MongoFormFieldGenerator()
示例#7
0
def generate_field(field):
    generator = MongoFormFieldGenerator()
    return generator.generate(field)
示例#8
0
 def setUp(self):
     self.generator = MongoFormFieldGenerator()