Beispiel #1
0
    def test_is_requred(self):
        f = ModelField(FooModel)
        with self.assertRaises(ValidationError) as cm:
            f.clean(None)

        self.assertEqual('Input is required. Expected model but got None.',
                         cm.exception.message)
Beispiel #2
0
    def test_allow_unsaved_true(self):
        model_field = ModelField(FooModel, allow_unsaved=True)
        model = FooModel(one='Z')

        cleaned_data = model_field.clean(model)

        self.assertTrue(model, cleaned_data)
Beispiel #3
0
    def test_model_valid_type(self):
        model_field = ModelField(FooModel)
        model = FooModel(one='Z')
        model.pk = 1

        cleaned_data = model_field.clean(model)

        self.assertTrue(model, cleaned_data)
Beispiel #4
0
    def test_allow_unsaved_false(self):
        model_field = ModelField(FooModel)
        model = FooModel(one='Z')

        with self.assertRaisesRegexp(ValidationError, "[Uu]nsaved"):
            cleaned_data = model_field.clean(model)
Beispiel #5
0
    def test_model_invalid_type(self):
        model_field = ModelField(FooModel)
        model = BarModel(one='Z')

        with self.assertRaisesRegexp(ValidationError, "FooModel"):
            cleaned_data = model_field.clean(model)
Beispiel #6
0
 def test_is_not_requred(self):
     f = ModelField(FooModel, required=False)
     # should not raise any exception
     f.clean(None)