Exemplo n.º 1
0
def unrecognised_fields_are_ignored():
    User = dodge.data_class("User", ["username"])

    input_dict = {"username": "******", "password": "******"}
    converted_user = dodge.dict_to_obj(input_dict, User)

    expected_user = User("bob")
    assert_equal(expected_user, converted_user)
Exemplo n.º 2
0
def conversion_from_dict_to_obj_uses_items_as_constructor_args():
    User = dodge.data_class("User", ["username", "password"])

    input_dict = {"username": "******", "password": "******"}
    converted_user = dodge.dict_to_obj(input_dict, User)

    expected_user = User("bob", "password1")
    assert_equal(expected_user, converted_user)
Exemplo n.º 3
0
def arguments_with_camelcase_names_are_converted_to_use_underscores():
    User = dodge.data_class("User", ["is_root"])

    input_dict = {"isRoot": True}
    converted_user = dodge.dict_to_obj(input_dict, User)

    expected_user = User(is_root=True)
    assert_equal(expected_user, converted_user)
Exemplo n.º 4
0
def conversion_from_dict_to_obj_uses_items_as_constructor_args():
    User = dodge.data_class("User", ["username", "password"])

    input_dict = {"username": "******", "password": "******"}
    converted_user = dodge.dict_to_obj(input_dict, User)

    expected_user = User("bob", "password1")
    assert_equal(expected_user, converted_user)
Exemplo n.º 5
0
def unrecognised_fields_are_ignored():
    User = dodge.data_class("User", ["username"])

    input_dict = {"username": "******", "password": "******"}
    converted_user = dodge.dict_to_obj(input_dict, User)

    expected_user = User("bob")
    assert_equal(expected_user, converted_user)
Exemplo n.º 6
0
def arguments_with_camelcase_names_are_converted_to_use_underscores():
    User = dodge.data_class("User", ["is_root"])

    input_dict = {"isRoot": True}
    converted_user = dodge.dict_to_obj(input_dict, User)

    expected_user = User(is_root=True)
    assert_equal(expected_user, converted_user)
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
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)