def test_referencelibrary_deser_empty():
    """Check proper deserialization for a reference library dict."""
    dict = {}
    reference_library = ReferenceLibrary(**dict)
    assert len(reference_library.books) == 0

    dict = {"books": []}
    reference_library = ReferenceLibrary(**dict)
    assert len(reference_library.books) == 0
def test_referencelibrary_deser_interfacegroups():
    """Test deserialization for a reference library with interface groups."""
    dict = {
        "books": [{
            "name":
            "book1",
            "interfaceGroups": [{
                "name":
                "g1",
                "interfaces": [{
                    "hostname": "h1",
                    "interface": "i1"
                }, {
                    "hostname": "h2",
                    "interface": "i2"
                }]
            }, {
                "name": "g2"
            }]
        }, {
            "name": "book2",
        }]
    }
    reference_library = ReferenceLibrary.from_dict(dict)

    assert len(reference_library.books) == 2
    assert reference_library.books[0].name == "book1"
    assert len(reference_library.books[0].interfaceGroups) == 2
    assert reference_library.books[0].interfaceGroups[0].name == "g1"
    assert len(reference_library.books[0].interfaceGroups[0].interfaces) == 2
Example #3
0
def test_referencelibrary_deser_addressgroups():
    """Test deserialization for a reference library with address groups."""
    dict = {
        "books": [
            {
                "name":
                "book1",
                "addressGroups": [
                    {
                        "name": "ag1",
                        "addresses":
                        ["1.1.1.1/24", "2.2.2.2", "3.3.3.3:0.0.0.8"],
                    },
                    {
                        "name": "ag2"
                    },
                ],
            },
            {
                "name": "book2"
            },
        ]
    }
    reference_library = ReferenceLibrary.from_dict(dict)

    assert len(reference_library.books) == 2
    assert reference_library.books[0].name == "book1"
    assert len(reference_library.books[0].addressGroups) == 2
    assert reference_library.books[0].addressGroups[0].name == "ag1"
    assert len(reference_library.books[0].addressGroups[0].addresses) == 3
def test_non_empty_referencelibrary():
    """Check proper deserialization for a reference library dict."""
    dict = {
        "books": [{
            "name":
            "book1",
            "addressGroups": [{
                "name":
                "ag1",
                "addresses": ["1.1.1.1/24", "2.2.2.2", "3.3.3.3:0.0.0.8"]
            }, {
                "name": "ag2"
            }]
        }, {
            "name": "book2",
        }]
    }
    reference_library = ReferenceLibrary.from_dict(dict)

    assert len(reference_library.books) == 2
    assert reference_library.books[0].name == "book1"
    assert len(reference_library.books[0].addressGroups) == 2
    assert reference_library.books[0].addressGroups[0].name == "ag1"
    assert len(reference_library.books[0].addressGroups[0].addresses) == 3
Example #5
0
def bf_get_reference_library():
    # type: () -> ReferenceLibrary
    """Returns the reference library for the active network."""
    return ReferenceLibrary.from_dict(
        restv2helper.get_reference_library(bf_session))
def test_referencelibrary_construction_list():
    """Check that we construct reference library where sub-props are lists."""
    book = ReferenceBook("a")
    library = ReferenceLibrary(books=[book])

    assert library.books == [book]
def test_referencelibrary_construction_item():
    """Check that we construct reference library when sub-props are not a list."""
    book = ReferenceBook("a")
    library = ReferenceLibrary(books=[book])
    assert ReferenceLibrary(books=book) == library
def test_referencelibrary_construction_badtype():
    """Check that we throw an error when reference library is built with wrong type."""
    with pytest.raises(ValueError):
        ReferenceLibrary(books="i1")
    with pytest.raises(ValueError):
        ReferenceLibrary(books=["ag", ReferenceBook("a")])
def test_referencelibrary_construction_empty():
    """Check that we construct empty reference library properly."""
    empty = ReferenceLibrary(books=[])

    assert ReferenceLibrary() == empty
    assert ReferenceLibrary(None) == empty