def test_embedded_notification_list_in_list(mgr, notification_cleanup):
    mgr.dispatch(
        to_ele("""
            <create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
              <filter>
                <embedded-foo-changed xmlns="urn:ietf:params:xml:ns:yang:test-notifications" />
              </filter>
            </create-subscription>
            """))
    assert get_embedded_list(mgr) == {}
    set_embedded_list_item(mgr, "NotificationOuter", "NotificationInner",
                           "Notification Message")
    assert get_embedded_list(mgr) == {
        "NotificationOuter": {
            "NotificationInner": "Notification Message"
        }
    }

    generate_test_notification_embedded_list_string_notif(
        "NotificationOuter", "NotificationInner", "Notification Message")
    results = find_notifications_matching(
        mgr,
        ("/notif:notification"
         "/test-notification:notification-from-list"
         "/test-notification:notification-from-list"
         "/test-notification:embedded-list"
         "/test-notification:embedded-foo-changed"
         "/test-notification:new-value"),
    )
    assert results[0].text == "Notification Message"

    clear_notification_list_item(mgr, "NotificationOuter")
    assert get_embedded_list(mgr) == {}
def test_embedded_notification_list_insert_and_delete(mgr,
                                                      notification_cleanup):
    mgr.dispatch(
        to_ele("""
            <create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
              <filter>
                <list-foo-changed 
                    xmlns="urn:ietf:params:xml:ns:yang:test-service-test-notification" 
                />
              </filter>
            </create-subscription>
            """))
    # Add a couple elements and send a notification for each
    assert get_notification_list(mgr) == {}
    set_notification_list_item(mgr, "Notification1", "Notification Message1")
    set_notification_list_item(mgr, "Notification2", "Notification Message2")
    assert get_notification_list(mgr) == {
        "Notification1": {
            "foo": "Notification Message1"
        },
        "Notification2": {
            "foo": "Notification Message2"
        },
    }
    generate_test_notification_list_foo_string_notif("Notification1",
                                                     "Notification Message")
    results = find_notifications_matching(
        mgr,
        ("/notif:notification"
         "/test-notification:notification-from-list"
         "/test-notification:notification-from-list"
         "/test-notification:list-foo-changed"
         "/test-notification:new-value"),
    )
    assert results[0].text == "Notification Message"
    generate_test_notification_list_foo_string_notif("Notification2",
                                                     "Notification Message2")
    results = find_notifications_matching(
        mgr,
        ("/notif:notification"
         "/test-notification:notification-from-list"
         "/test-notification:notification-from-list"
         "/test-notification:list-foo-changed"
         "/test-notification:new-value"),
    )
    assert results[0].text == "Notification Message2"

    # Delete the elements and try sending a notification
    clear_notification_list_item(mgr, "Notification1")
    clear_notification_list_item(mgr, "Notification2")
    assert get_notification_list(mgr) == {}
    with pytest.raises(AssertionError):
        generate_test_notification_list_foo_string_notif(
            "Notification1", "Notification Message1")

    # Add a new element and send a notification
    set_notification_list_item(mgr, "Notification99", "Notification Message")
    assert get_notification_list(mgr) == {
        "Notification99": {
            "foo": "Notification Message"
        }
    }
    generate_test_notification_list_foo_string_notif("Notification99",
                                                     "Notification Message")
    results = find_notifications_matching(
        mgr,
        ("/notif:notification"
         "/test-notification:notification-from-list"
         "/test-notification:notification-from-list"
         "/test-notification:list-foo-changed"
         "/test-notification:new-value"),
    )
    assert results[0].text == "Notification Message"
    clear_notification_list_item(mgr, "Notification99")
    assert get_notification_list(mgr) == {}

    # Add a couple elements back with the same keys and verify notifications work
    assert get_notification_list(mgr) == {}
    set_notification_list_item(mgr, "Notification1", "Notification Message1")
    set_notification_list_item(mgr, "Notification2", "Notification Message2")
    assert get_notification_list(mgr) == {
        "Notification1": {
            "foo": "Notification Message1"
        },
        "Notification2": {
            "foo": "Notification Message2"
        },
    }
    generate_test_notification_list_foo_string_notif("Notification1",
                                                     "Notification Message1")
    results = find_notifications_matching(
        mgr,
        ("/notif:notification"
         "/test-notification:notification-from-list"
         "/test-notification:notification-from-list"
         "/test-notification:list-foo-changed"
         "/test-notification:new-value"),
    )
    assert results[0].text == "Notification Message1"
    generate_test_notification_list_foo_string_notif("Notification2",
                                                     "Notification Message2")
    results = find_notifications_matching(
        mgr,
        ("/notif:notification"
         "/test-notification:notification-from-list"
         "/test-notification:notification-from-list"
         "/test-notification:list-foo-changed"
         "/test-notification:new-value"),
    )
    assert results[0].text == "Notification Message2"

    # Clear list again and verify notifications can't be sent for old elements
    clear_notification_list_item(mgr, "Notification1")
    clear_notification_list_item(mgr, "Notification2")
    assert get_notification_list(mgr) == {}
    with pytest.raises(AssertionError):
        generate_test_notification_list_foo_string_notif(
            "Notification1", "Notification Message1")