Пример #1
0
def test_nested_list():
    data = {
        "firstName": "Anakin",
        "lastName": "Skywalker",
        "children": [{"firstName": "Luke"},
                     {"firstName": "Leia"}],
    }
    expected = {
        "first_name": "Anakin",
        "last_name": "Skywalker",
        "children": [{"first_name": "Luke"},
                     {"first_name": "Leia"}],
    }
    assert snake_case_keys(data) == expected
Пример #2
0
def test_list_in_list():
    data = {
        "random": [
            "Luke",
            [
                "blowing up the death star",
                {"skillName": "bulls-eye womprats",
                 "skillParameters": "with my T47"},
            ],
        ]
    }
    expected = {
        "random": [
            "Luke",
            [
                "blowing up the death star",
                {"skill_name": "bulls-eye womprats",
                 "skill_parameters": "with my T47"},
            ],
        ]
    }
    assert snake_case_keys(data) == expected
Пример #3
0
def test_nested_object():
    data = {
        "darthVader": {
            "firstName": "Anakin",
            "lastName": "Skywalker",
            "appearance": {
                "helmetColor": "black",
                "armorColor": "black",
                "capeColor": "black",
            },
        }
    }
    expected = {
        "darth_vader": {
            "first_name": "Anakin",
            "last_name": "Skywalker",
            "appearance": {
                "helmet_color": "black",
                "armor_color": "black",
                "cape_color": "black",
            },
        }
    }
    assert snake_case_keys(data) == expected
Пример #4
0
def test_no_transform():
    data = {"star": "wars"}
    assert snake_case_keys(data) == data
Пример #5
0
def test_multi_first_level_keys():
    data = {"firstName": "Han", "lastName": "Solo"}
    expected = {"first_name": "Han", "last_name": "Solo"}
    assert snake_case_keys(data) == expected
Пример #6
0
def test_multi_digit():
    data = {"executeOrder66": "yes sir!"}
    expected = {"execute_order_66": "yes sir!"}
    assert snake_case_keys(data) == expected
Пример #7
0
def test_single_digit():
    data = {"emperorsNumber2": "Darth Vader"}
    expected = {"emperors_number_2": "Darth Vader"}
    assert snake_case_keys(data) == expected
Пример #8
0
def test_acronyms():
    data = {"numTIEFighters": 1e5}
    expected = {"num_t_i_e_fighters": 1e5}
    assert snake_case_keys(data) == expected
Пример #9
0
def test_transform_kebab_case():
    data = {"darth-vader": "James Earl Jones"}
    expected = {"darth_vader": "James Earl Jones"}
    assert snake_case_keys(data) == expected
Пример #10
0
def test_empty_object():
    data = {}
    assert snake_case_keys(data) == data
Пример #11
0
def test_snake_case_stays():
    data = {"darth_vader": "James Earl Jones"}
    assert snake_case_keys(data) == data
Пример #12
0
def test_leading_capital():
    data = {"DarthVader": "James Earl Jones"}
    expected = {"darth_vader": "James Earl Jones"}
    assert snake_case_keys(data) == expected
Пример #13
0
def test_single_key_transform():
    data = {"starWars": "is awesome"}
    expected = {"star_wars": "is awesome"}
    assert snake_case_keys(data) == expected