コード例 #1
0
    def test_multiple_non_list(self):
        model_field = MultipleModelField(FooModel)
        obj = FooModel(one='a')
        obj.pk = 1

        with self.assertRaisesRegexp(ValidationError, "[Ii]terable"):
            cleaned_data = model_field.clean(obj)
コード例 #2
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)
コード例 #3
0
    def test_multiple_valid(self):
        model_field = MultipleModelField(FooModel)
        objects = [FooModel(one='a'), FooModel(one='b')]
        for obj in objects:
            obj.pk = 1

        cleaned_data = model_field.clean(objects)

        self.assertEqual(objects, cleaned_data)
コード例 #4
0
    def test_multiple_unsaved_false(self):
        model_field = MultipleModelField(FooModel)
        objects = [FooModel(one='a'), FooModel(one='b')]
        for obj in objects:
            obj.pk = 1
        objects.append(FooModel(one='c'))

        with self.assertRaisesRegexp(ValidationError, "[Uu]nsaved"):
            cleaned_data = model_field.clean(objects)
コード例 #5
0
    def test_multiple_invalid_type(self):
        model_field = MultipleModelField(FooModel, allow_unsaved=True)
        objects = [
            FooModel(one='a'),
            FooModel(one='b'),
            BarModel(one='c')
        ]

        with self.assertRaisesRegexp(ValidationError, "FooModel"):
            cleaned_data = model_field.clean(objects)
コード例 #6
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)
コード例 #7
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)