def test_user_info_from_dict_wrong_data():
    # If any of the dictionary fields is missing, building from dict will fail
    d1 = {"available_slots": "", "subscription_expiry": ""}
    d2 = {"available_slots": "", "appointments": ""}
    d3 = {"subscription_expiry": "", "appointments": ""}

    for d in [d1, d2, d3]:
        with pytest.raises(
                ValueError,
                match="Wrong appointment data, some fields are missing"):
            UserInfo.from_dict(d)
def test_user_info_from_dict():
    # UserInfo objects can be created from a dictionary, this is used when loading data from the database
    available_slots = 42
    subscription_expiry = 1234
    appointments = {get_random_value_hex(32): 1 for _ in range(10)}
    data = {
        "available_slots": available_slots,
        "subscription_expiry": subscription_expiry,
        "appointments": appointments,
    }

    user_info = UserInfo.from_dict(data)
    assert user_info.available_slots == available_slots
    assert user_info.subscription_expiry == subscription_expiry
    assert user_info.appointments == appointments

    # The appointments dict does not need to be populated when building from a dictionary
    data["appointments"] = {}
    user_info = UserInfo.from_dict(data)
    assert user_info.available_slots == available_slots
    assert user_info.subscription_expiry == subscription_expiry
    assert user_info.appointments == {}