示例#1
0
def test_internal_convert_from_with_normal_values(deserialize, import_module):
    (u'Making sure that the _convert_from function can handle values without '
     u'the __class__/__value__ special keys')

    mymodule = Mock()
    mymodule.MyClass = Mock()
    import_module.side_effect = KeyError('Owned')

    converted = ejson._convert_from({'name': 'Yuri G.'})
    converted.should.be.equal({'name': 'Yuri G.'})
示例#2
0
def test_internal_convert_from(deserialize, import_module):
    (u'Making sure that the _convert_from function can find the right '
     u'module/class described by the dotted notation in the "__class__" key')

    mymodule = Mock()
    mymodule.MyClass = Mock()
    import_module.return_value = mymodule
    deserialize.return_value = 'Awesome!'

    converted = ejson._convert_from(
        {'__class__': 'mymodule.MyClass', '__value__': {'name': 'Neil A.'}})

    import_module.assert_called_once_with('mymodule')
    converted.should.be.equals('Awesome!')
    deserialize.assert_called_once_with(
        mymodule.MyClass, {'name': 'Neil A.'})