Esempio n. 1
0
def test_load_dump(engine):
    """ _load and _dump should be symmetric """
    user = User(id=uuid.uuid4(),
                name="name",
                email="*****@*****.**",
                age=25,
                joined=arrow.now())
    serialized = {
        "id": {
            "S": str(user.id)
        },
        "age": {
            "N": "25"
        },
        "name": {
            "S": "name"
        },
        "email": {
            "S": "*****@*****.**"
        },
        "j": {
            "S": user.joined.to("utc").isoformat()
        }
    }

    assert User._load(serialized, context={"engine": engine}) == user
    assert User._dump(user, context={"engine": engine}) == serialized
Esempio n. 2
0
def test_load_default_init(engine):
    """ The default model loader uses the model's __init__ method """
    User.Meta.init = Mock()
    User.Meta.init.return_value = User()

    user_id = uuid.uuid4()
    now = arrow.now()

    user = {
        "id": {
            "S": str(user_id)
        },
        "j": {
            "S": now.isoformat()
        },
        "extra_field": {
            "N": "0.125"
        }
    }

    loaded_user = User._load(user, context={"engine": engine})
    assert loaded_user.id == user_id
    assert loaded_user.joined == now
    assert not hasattr(loaded_user, "extra_field")
    # No args, kwargs provided to custom init function
    User.Meta.init.assert_called_once_with()