Пример #1
0
    def test_slug_field(self):
        serializer = ExampleModelOneSerializer()

        field_repr = serializer.get_field_representation()

        self.assertEqual(field_repr["slug_field"]["display"], "verbatim")
        self.assertEqual(field_repr["slug_field"]["filter"], "text")
Пример #2
0
    def test_email_field(self):
        serializer = ExampleModelOneSerializer()

        field_repr = serializer.get_field_representation()

        self.assertEqual(field_repr["email_field"]["display"], "link:mailto")
        self.assertEqual(field_repr["email_field"]["filter"], "text")
Пример #3
0
    def test_integer_generation(self):
        serializer = ExampleModelOneSerializer()

        field_repr = serializer.get_field_representation()

        self.assertEqual(field_repr["integer_field"]["display"], "verbatim")
        self.assertEqual(field_repr["integer_field"]["filter"], "number")
Пример #4
0
    def test_many_to_many_field(self):
        model1 = ExampleModelTwoFactory.create(name="Foo")

        model2 = ExampleModelTwoFactory.create(name="Bar")

        serializer = ExampleModelOneSerializer()

        field_repr = serializer.get_field_representation()

        self.assertEqual(field_repr["many_to_many_field"]["display"],
                         "verbatim")
        self.assertEqual(field_repr["many_to_many_field"]["filter"], "choice")

        self.assertIn(
            {
                "label": model1.name,
                "value": str(model1.uuid)
            },
            field_repr["many_to_many_field"]["configuration"]["options"],
        )

        self.assertIn(
            {
                "label": model2.name,
                "value": str(model2.uuid)
            },
            field_repr["many_to_many_field"]["configuration"]["options"],
        )
Пример #5
0
    def test_time_field(self):
        serializer = ExampleModelOneSerializer()

        field_repr = serializer.get_field_representation()

        self.assertEqual(field_repr["time_field"]["display"], "datetime")
        self.assertEqual(field_repr["time_field"]["filter"], "date")
Пример #6
0
    def test_nullboolean_field(self):
        serializer = ExampleModelOneSerializer()

        field_repr = serializer.get_field_representation()

        self.assertEqual(field_repr["nullboolean_field"]["display"], "boolean")
        self.assertEqual(field_repr["nullboolean_field"]["filter"], "boolean")
Пример #7
0
    def test_sub_serializer(self):
        serializer = ExampleModelOneSerializer()

        field_repr = serializer.get_field_representation()

        self.assertIn("other_model__id", field_repr.keys())
        self.assertIn("other_model__name", field_repr.keys())
        self.assertIn("other_model__number", field_repr.keys())
Пример #8
0
    def test_choice_field(self):
        serializer = ExampleModelOneSerializer()

        field_repr = serializer.get_field_representation()

        self.assertEqual(field_repr["choice_field"]["display"], "verbatim")
        self.assertEqual(field_repr["choice_field"]["filter"], "choice")
        self.assertEqual(
            field_repr["choice_field"]["configuration"]["options"],
            [{
                "label": "Foo",
                "value": "foo"
            }, {
                "label": "Bar",
                "value": "bar"
            }],
        )
        self.assertEqual(field_repr["choice_field"]["configuration"]["mode"],
                         "options")
Пример #9
0
    def test_get_related_fields_fields(self):
        serializer = ExampleModelOneSerializer()

        related_fields = serializer.get_related_fields()

        self.assertEqual(related_fields, ["other_model"])