Пример #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
 def setUp(self):
     self.generator = MongoFormFieldGenerator()
 def setUp(self):
     self.generator = MongoFormFieldGenerator()