Пример #1
0
def data_list_serialize(value, **kwargs):
    return [
        json.serialize(v,
                       attributes=('name', 'date'),
                       strategies={'date': date_serialize},
                       **kwargs) for v in value
    ]
Пример #2
0
 def test_dict(self):
     obj = support.MyObject('test', date=datetime.now())
     obj.data_dict = {
         'test': support.MyObject('testing', date=datetime.now()),
     }
     d = json.serialize(obj,
                        ('name', 'date', 'data_dict'),
                        strategies={'data_dict': support.data_dict_serialize,
                                    'date': support.date_serialize})
     assert isinstance(d['dataDict']['test']['date'], str)
Пример #3
0
 def test_list(self):
     obj = support.MyObject('test', date=datetime.now())
     obj.data_list = [
         support.MyObject('testing', date=datetime.now()),
         support.MyObject('again', date=datetime.now())
     ]
     d = json.serialize(obj, ('name', 'date', 'data_list'),
                        strategies={
                                    'data_list': support.data_list_serialize,
                                    'date': support.date_serialize})
     assert isinstance(d['dataList'][0]['date'], str)
Пример #4
0
 def test_dict(self):
     obj = support.MyObject('test', date=datetime.now())
     obj.data_dict = {
         'test': support.MyObject('testing', date=datetime.now()),
     }
     d = json.serialize(obj, ('name', 'date', 'data_dict'),
                        strategies={
                            'data_dict': support.data_dict_serialize,
                            'date': support.date_serialize
                        })
     assert isinstance(d['dataDict']['test']['date'], str)
Пример #5
0
def data_dict_serialize(value, **kwargs):
    return {
        k: json.serialize(v,
                          attributes=(
                              'name',
                              'date',
                          ),
                          strategies={'date': date_serialize},
                          **kwargs)
        for k, v in value.items()
    }
Пример #6
0
 def test_list(self):
     obj = support.MyObject('test', date=datetime.now())
     obj.data_list = [
         support.MyObject('testing', date=datetime.now()),
         support.MyObject('again', date=datetime.now())
     ]
     d = json.serialize(obj, ('name', 'date', 'data_list'),
                        strategies={
                            'data_list': support.data_list_serialize,
                            'date': support.date_serialize
                        })
     assert isinstance(d['dataList'][0]['date'], str)
Пример #7
0
 def test_basic(self):
     obj = support.MyObject('test')
     d = json.serialize(obj, ('name',))
     assert d == {'name': 'test'}
Пример #8
0
 def test_none_attribute(self):
     obj = support.MyObject('test')
     d = json.serialize(obj,
                        ('name', 'date'),
                        strategies={'date': support.date_serialize})
     assert 'date' not in d
Пример #9
0
 def test_complex(self):
     obj = support.MyObject('test', date=datetime.now())
     d = json.serialize(obj, ('name', 'date'),
                        strategies={'date': support.date_serialize})
     assert isinstance(d['date'], str)
Пример #10
0
 def test_basic(self):
     obj = support.MyObject('test')
     d = json.serialize(obj, ('name', ))
     assert d == {'name': 'test'}
Пример #11
0
 def test_none_attribute(self):
     obj = support.MyObject('test')
     d = json.serialize(obj, ('name', 'date'),
                        strategies={'date': support.date_serialize})
     assert 'date' not in d
Пример #12
0
 def test_complex(self):
     obj = support.MyObject('test', date=datetime.now())
     d = json.serialize(obj, ('name', 'date'),
                        strategies={'date': support.date_serialize})
     assert isinstance(d['date'], str)
Пример #13
0
def data_dict_serialize(value, **kwargs):
    return {
        k: json.serialize(v,
                          attributes=('name', 'date',),
                          strategies={'date': date_serialize}, **kwargs)
        for k, v in value.items()}
Пример #14
0
def data_list_serialize(value, **kwargs):
    return [
        json.serialize(v,
                       attributes=('name', 'date'),
                       strategies={'date': date_serialize}, **kwargs)
        for v in value]