예제 #1
0
def test_typemap():
    typemap = {
        Path: (
            lambda value: str(value).lstrip('/'),
            lambda data: Path('/' + data.lstrip('/')),
        ),
    }
    assert dumps(Path('/foo/bar'), typemap) == '"foo/bar"'
    assert loads(Path, '"foo/bar"', typemap) == Path('/foo/bar')
예제 #2
0
def test_obj():
    class Foo:
        def __init__(self, uuid, path, dt):
            self.path = path
            self.uuid = uuid
            self.dt = dt

        def __jsondump__(self):
            return dump(self.__dict__)

        @classmethod
        def __jsonload__(cls, data):
            return cls(
                dt=load(datetime, data['dt']),
                path=load(Path, data['path']),
                uuid=load(UUID, data['uuid']),
            )

    obj = Foo(uuid4(), Path('/bar'), datetime.now())
    result = loads(Foo, dumps(obj))
    assert obj.path == result.path
    assert obj.uuid == result.uuid
    assert obj.dt == result.dt
예제 #3
0
def test_moar_nesting():
    obj = YourClassList([YourClass(), YourClass()])
    encoded = dumps(obj)
    decoded = loads(YourClassList, encoded)
    assert obj[0] == decoded[0]
    assert obj[1] == decoded[1]
예제 #4
0
def test_uuid():
    obj = uuid4()
    encoded = dumps(obj)
    decoded = loads(UUID, encoded)
    assert obj == decoded
예제 #5
0
def test_your_class_and_nesting():
    obj = YourClass()
    encoded = dumps(obj)
    decoded = loads(YourClass, encoded)
    assert obj == decoded
예제 #6
0
def test_decimal():
    obj = Decimal('3.14')
    assert loads(Decimal, dumps(obj)) == obj
예제 #7
0
def test_path():
    obj = Path('/foo')
    assert loads(Path, dumps(obj)) == obj
예제 #8
0
def test_datetime():
    obj = datetime.now()
    assert loads(datetime, dumps(obj)) == obj
예제 #9
0
def convert_kwargs(apps, schema_editor):
    Caller = apps.get_model('djcall', 'Caller')
    for caller in Caller.objects.all():
        caller.kwargs = jsonlight.dumps(caller.old_kwargs)
        caller.save()