Example #1
0
def data_list_serialize(value, **kwargs):
    return [
        json.serialize(v,
                       attributes=('name', 'date'),
                       strategies={'date': date_serialize},
                       **kwargs) for v in value
    ]
Example #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)
Example #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)
Example #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)
Example #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()
    }
Example #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)
Example #7
0
 def test_basic(self):
     obj = support.MyObject('test')
     d = json.serialize(obj, ('name',))
     assert d == {'name': 'test'}
Example #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
Example #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)
Example #10
0
 def test_basic(self):
     obj = support.MyObject('test')
     d = json.serialize(obj, ('name', ))
     assert d == {'name': 'test'}
Example #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
Example #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)
Example #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()}
Example #14
0
def data_list_serialize(value, **kwargs):
    return [
        json.serialize(v,
                       attributes=('name', 'date'),
                       strategies={'date': date_serialize}, **kwargs)
        for v in value]