def test_addressgroup_construction_empty():
    """Check that we construct empty address groups properly."""
    empty_group = AddressGroup("g1", addresses=[], childGroupNames=[])

    assert AddressGroup("g1") == empty_group
    assert AddressGroup("g1", addresses=None,
                        childGroupNames=None) == empty_group
def test_addressgroup_construction_list():
    """Check that we construct address groups where sub-props are lists."""
    group = AddressGroup("g1", addresses=["ag"], childGroupNames=["cg"])

    assert group.name == "g1"
    assert group.addresses == ["ag"]
    assert group.childGroupNames == ["cg"]
def test_addressgroup_deser_only_addresses():
    """Test deserialization for a reference library with address groups."""
    dict = {"name": "ag1", "addresses": ["1.1.1.1/24", "2.2.2.2"]}

    address_group = AddressGroup.from_dict(dict)

    assert len(address_group.addresses) == 2
    assert len(address_group.childGroupNames) == 0
def test_addressgroup_deser_none_subfields():
    """Test deserialization for a reference library with address groups."""
    dict = {"name": "ag1"}

    address_group = AddressGroup.from_dict(dict)

    assert len(address_group.addresses) == 0
    assert len(address_group.childGroupNames) == 0
def test_referencebook_construction_addressgroup_badtype():
    """Check that we throw an error when address group is wrong type."""
    with pytest.raises(ValueError):
        ReferenceBook("book1", addressGroups="ag")
    with pytest.raises(ValueError):
        ReferenceBook("book1", addressGroups=["ag"])
    with pytest.raises(ValueError):
        ReferenceBook("book1", addressGroups=["ag", AddressGroup("ag1")])
def test_addressgroup_construction_badtype():
    """Check that we throw an error when address group is built with wrong type."""
    with pytest.raises(ValueError):
        AddressGroup("g1", addresses=AddressGroup("g1"))
    with pytest.raises(ValueError):
        AddressGroup("g1", childGroupNames=AddressGroup("g1"))
    with pytest.raises(ValueError):
        AddressGroup("book1", addresses=["ag", AddressGroup("ag1")])
    with pytest.raises(ValueError):
        AddressGroup("book1", childGroupNames=["ag", AddressGroup("ag1")])
def test_addressgroup_construction_item():
    """Check that we construct address groups when sub-props are not a list."""
    assert AddressGroup("g1", addresses="ag") == AddressGroup("g1",
                                                              addresses=["ag"])
    assert AddressGroup("g1", childGroupNames="ag") == AddressGroup(
        "g1", childGroupNames=["ag"])
def test_referencebook_construction_addressgroup_list():
    """Check that we construct reference books where address group is a list."""
    ref_book = ReferenceBook("book1", addressGroups=[AddressGroup("ag")])

    assert ref_book.name == "book1"
    assert ref_book.addressGroups == [AddressGroup("ag")]