def test_add_two_currencies_for_same_country():
    currency = ParseJson(
        [
            {
                "country": "UK",
                "city": "London",
                "currency": "GBP",
                "amount": 12.2
            },
            {
                "country": "UK",
                "city": "London",
                "currency": "FBP",
                "amount": 10.9
            },
        ],
        NEST,
    )

    currency.parse()
    assert currency.output == {
        "GBP": {
            "UK": {
                "London": [{
                    "amount": 12.2
                }]
            }
        },
        "FBP": {
            "UK": {
                "London": [{
                    "amount": 10.9
                }]
            }
        },
    }
def test_add_two_currencies():
    currency = ParseJson(
        [
            {
                "country": "UK",
                "city": "London",
                "currency": "GBP",
                "amount": 12.2
            },
            {
                "country": "FR",
                "city": "Paris",
                "currency": "EUR",
                "amount": 20
            },
        ],
        NEST,
    )

    currency.parse()
    assert currency.output == {
        "GBP": {
            "UK": {
                "London": [{
                    "amount": 12.2
                }]
            }
        },
        "EUR": {
            "FR": {
                "Paris": [{
                    "amount": 20
                }]
            }
        },
    }
Exemple #3
0
def parse_json(json_data, nest_data):
    loaded_json = json.loads(json_data)
    convert = ParseJson(loaded_json, nest_data)
    convert.parse()
    print(json.dumps(convert.output, indent=4, sort_keys=True))
    return convert.output