def test_auto_fields(self):
        class FooModelService(ModelService):
            class Meta:
                model = FooModel
                fields = '__all__'

            def process(self):
                pass

        f = FooModelService()

        field_names = list(six.iterkeys(f.fields))
        self.assertEqual(1, len(field_names))
        self.assertEqual('one', field_names[0])
    def test_extra_fields(self):
        class FooModelService(ModelService):
            two = forms.CharField()

            class Meta:
                model = FooModel
                fields = '__all__'

            def process(self):
                pass

        f = FooModelService()

        field_names = list(six.iterkeys(f.fields))
        self.assertEqual(2, len(field_names))
        self.assertEqual('one', field_names[0])
        self.assertEqual('two', field_names[1])
Beispiel #3
0
    def test_cleaned_data_pickling(self):
        service = FooModelService(self.initial_data)
        service.is_valid()

        # Check deflated ModelField format
        deflated_models = self.initial_data.copy()
        deflated_models["foo"] = (CustomFooModel, self.foo.pk)

        self.assertEqual(CeleryService._deflate_models(service.cleaned_data),
                         deflated_models)

        # Check deflate/inflate invariant
        self.assertEqual(
            CeleryService._inflate_models(
                CeleryService._deflate_models(service.cleaned_data)),
            service.cleaned_data,
        )

        # Check deflated data picklable invariant
        deflated_data = CeleryService._deflate_models(service.cleaned_data)
        self.assertEqual(pickle.loads(pickle.dumps(deflated_data)),
                         deflated_data)