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)
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)
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
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)
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)
def test_init_model_class_string(self): rv = ModelField('tests.BarModel') self.assertEqual(BarModel, rv.model_class)
def test_init_model_class_valid(self): rv = ModelField(FooModel) self.assertEqual(FooModel, rv.model_class)
def test_init_model_class_invalid(self): with self.assertRaisesRegexp(AssertionError, "NonModel"): rv = ModelField(NonModel)
def test_is_not_requred(self): f = ModelField(FooModel, required=False) # should not raise any exception f.clean(None)