コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)