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)
class FooModelService(CeleryService):
    foo = ModelField(CustomFooModel)
    date = forms.DateField()
    text = forms.CharField()

    def process(self):
        pass
Beispiel #5
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 #6
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 #7
0
    def test_init_model_class_string(self):
        rv = ModelField('tests.BarModel')

        self.assertEqual(BarModel, rv.model_class)
Beispiel #8
0
    def test_init_model_class_valid(self):
        rv = ModelField(FooModel)

        self.assertEqual(FooModel, rv.model_class)
Beispiel #9
0
 def test_init_model_class_invalid(self):
     with self.assertRaisesRegexp(AssertionError, "NonModel"):
         rv = ModelField(NonModel)
Beispiel #10
0
 def test_is_not_requred(self):
     f = ModelField(FooModel, required=False)
     # should not raise any exception
     f.clean(None)