Beispiel #1
0
    def test_dump_document_field_redefinition(self):
        Field = namedtuple('Field', ['name'])
        fields_own = [Field(name) for name in ["id", "char"]]
        obj_dump = Serializer.dump_document(self.obj, fields_own)
        expected_dump = {
            "id": self.obj.id,
            "char": self.obj.char,
        }
        self.assertEqual(obj_dump, expected_dump)

        Serializer.dump_document_char = staticmethod(lambda obj: None)
        obj_dump = Serializer.dump_document(self.obj, fields_own)
        expected_dump["char"] = None
        self.assertEqual(obj_dump, expected_dump)
Beispiel #2
0
    def test_dump_document_field_redefinition(self):
        Field = namedtuple('Field', ['name'])
        fields_own = [Field(name) for name in ["id", "char"]]
        obj_dump = Serializer.dump_document(self.obj, fields_own)
        expected_dump = {
            "id": self.obj.id,
            "char": self.obj.char,
        }
        self.assertEqual(obj_dump, expected_dump)

        Serializer.dump_document_char = staticmethod(lambda obj: None)
        obj_dump = Serializer.dump_document(self.obj, fields_own)
        expected_dump["char"] = None
        self.assertEqual(obj_dump, expected_dump)
Beispiel #3
0
    def test_django_fields_serialization(self):
        fields_own = [
            f for f in self.obj._meta.fields if f.serialize
        ]
        obj = Serializer.dump_document(self.obj, fields_own=fields_own)

        self.assertEqual(obj['big_integer'], self.obj.big_integer)
        self.assertEqual(obj['boolean'], self.obj.boolean)
        self.assertEqual(obj['char'], self.obj.char)
        self.assertEqual(obj['comma_separated_integer'], [
            x for x in self.obj.comma_separated_integer
        ])
        self.assertEqual(obj['date'], self.obj.date)
        self.assertEqual(obj['datetime'], self.obj.datetime)
        self.assertEqual(obj['decimal'], self.obj.decimal)
        self.assertEqual(obj['email'], self.obj.email)
        self.assertEqual(
            obj['authorfile'],
            "http://testserver{}".format(self.obj.authorfile.url))
        self.assertEqual(obj['filepath'], self.obj.filepath)
        self.assertEqual(obj['floatnum'], self.obj.floatnum)
        self.assertEqual(obj['integer'], self.obj.integer)
        self.assertEqual(obj['ip'], self.obj.ip)
        self.assertEqual(obj['generic_ip'], self.obj.generic_ip)
        self.assertEqual(obj['nullboolean'], self.obj.nullboolean)
        self.assertEqual(obj['positive_integer'], self.obj.positive_integer)
        self.assertEqual(
            obj['positive_small_integer'], self.obj.positive_small_integer)
        self.assertEqual(obj['slug'], self.obj.slug)
        self.assertEqual(obj['small_integer'], self.obj.small_integer)
        self.assertEqual(obj['text'], self.obj.text)
        self.assertEqual(obj['time'], self.obj.time)
        self.assertEqual(obj['url'], self.obj.url)
Beispiel #4
0
    def test_django_fields_serialization(self):
        fields_own = [f for f in self.obj._meta.fields if f.serialize]
        obj = Serializer.dump_document(self.obj, fields_own=fields_own)

        self.assertEqual(obj['big_integer'], self.obj.big_integer)
        self.assertEqual(obj['boolean'], self.obj.boolean)
        self.assertEqual(obj['char'], self.obj.char)
        self.assertEqual(obj['comma_separated_integer'],
                         [x for x in self.obj.comma_separated_integer])
        self.assertEqual(obj['date'], self.obj.date)
        self.assertEqual(obj['datetime'], self.obj.datetime)
        self.assertEqual(obj['decimal'], self.obj.decimal)
        self.assertEqual(obj['email'], self.obj.email)
        self.assertEqual(obj['authorfile'],
                         "http://testserver{}".format(self.obj.authorfile.url))
        self.assertEqual(obj['filepath'], self.obj.filepath)
        self.assertEqual(obj['floatnum'], self.obj.floatnum)
        self.assertEqual(obj['integer'], self.obj.integer)
        self.assertEqual(obj['ip'], self.obj.ip)
        self.assertEqual(obj['generic_ip'], self.obj.generic_ip)
        self.assertEqual(obj['nullboolean'], self.obj.nullboolean)
        self.assertEqual(obj['positive_integer'], self.obj.positive_integer)
        self.assertEqual(obj['positive_small_integer'],
                         self.obj.positive_small_integer)
        self.assertEqual(obj['slug'], self.obj.slug)
        self.assertEqual(obj['small_integer'], self.obj.small_integer)
        self.assertEqual(obj['text'], self.obj.text)
        self.assertEqual(obj['time'], self.obj.time)
        self.assertEqual(obj['url'], self.obj.url)