def converting_object_to_dict_preserves_ordering():
    User = dodge.data_class("User", ["username", "salt", "password", "email_address"])

    user = User("bob", "!%ksdg", "password1", "*****@*****.**")
    result = dodge.obj_to_dict(user)

    assert_equal(["username", "salt", "password", "emailAddress"], list(result.keys()))
def conversion_from_obj_to_dict_converts_underscores_to_camel_case():
    User = dodge.data_class("User", ["is_root"])

    input_user = User(is_root=True)
    result = dodge.obj_to_dict(input_user)

    expected_dict = {"isRoot": True}
    assert_equal(expected_dict, result)
def conversion_from_obj_to_dict_uses_hacktastic_fields_property():
    User = dodge.data_class("User", ["username", "password"])

    user = User("bob", "password1")
    result = dodge.obj_to_dict(user)

    expected_dict = {"username": "******", "password": "******"}
    assert_equal(expected_dict, result)
def conversion_from_obj_to_dict_converts_underscores_to_camel_case():
    User = dodge.data_class("User", ["is_root"])

    input_user = User(is_root=True)
    result = dodge.obj_to_dict(input_user)

    expected_dict = {"isRoot": True}
    assert_equal(expected_dict, result)
def conversion_from_obj_to_dict_uses_hacktastic_fields_property():
    User = dodge.data_class("User", ["username", "password"])

    user = User("bob", "password1")
    result = dodge.obj_to_dict(user)

    expected_dict = {"username": "******", "password": "******"}
    assert_equal(expected_dict, result)
def converting_object_to_dict_preserves_ordering():
    User = dodge.data_class("User",
                            ["username", "salt", "password", "email_address"])

    user = User("bob", "!%ksdg", "password1", "*****@*****.**")
    result = dodge.obj_to_dict(user)

    assert_equal(["username", "salt", "password", "emailAddress"],
                 list(result.keys()))
def can_convert_nested_data_classes_to_and_from_dict():
    Profile = dodge.data_class("Profile", ["bio"])

    User = dodge.data_class("User", ["username", dodge.field("profile", type=Profile)])

    user = User("bob", Profile("I'm Bob."))
    serialised_user = dodge.obj_to_dict(user)
    unserialised_user = dodge.dict_to_obj(serialised_user, User)
    assert_equal(user, unserialised_user)
def can_convert_nested_data_classes_to_and_from_dict():
    Profile = dodge.data_class("Profile", ["bio"])

    User = dodge.data_class("User", [
        "username",
        dodge.field("profile", type=Profile),
    ])

    user = User("bob", Profile("I'm Bob."))
    serialised_user = dodge.obj_to_dict(user)
    unserialised_user = dodge.dict_to_obj(serialised_user, User)
    assert_equal(user, unserialised_user)