def test_validate_config_table_data(stc):
    input_string = get_bad_input_string()
    output_dict, err_msg = proc_func.config_table_data(json.loads(input_string))
    assert "Expected 2 elements in Start, but got 1" in err_msg
def test_config_table_data(stc):
    input_string = get_input_string()
    output_dict, err_msg = proc_func.config_table_data(json.loads(input_string))

    err_str, table_data = json_utils.load_json(output_dict["TableData"])
    assert err_str == ""
    # Two rows in the table (Bgp and Ospfv2)
    assert len(table_data) == 2

    # Check first mix with Bgp enabled
    table_dict = table_data[0]
    assert table_dict["weight"] == 10.0
    assert table_dict["useBlock"] is False
    assert table_dict["deviceTag"] == "ttEmulatedDevice"
    assert table_dict["baseTemplateFile"] == "Dual_Vlan.xml"
    assert table_dict["protocolTemplateFile"] == "AllRouters.xml"

    # Check that the interfaceList contains two network interfaces(Ipv4 and VLAN)
    interfaceList = table_dict["interfaceList"]
    assert len(interfaceList) == 2

    # Check the IPv4 interface
    ipv4 = interfaceList[0]
    assert len(ipv4) == 1

    # Check that IPv4 has two propertyModifiers(Address and Gateway)
    propModList = ipv4["stmPropertyModifierList"]
    assert len(propModList) == 2

    # Check the propertyModifier for Address
    ipv4_address = {}
    ipv4_address["tagName"] = "ttIpv4If.Address"
    ipv4_address["className"] = "Ipv4If"
    ipv4_address["propertyName"] = "Address"
    ipv4_address["parentTagName"] = "ttIpv4If"
    ipv4_address["propertyValueList"] = {}
    ipv4_address["propertyValueList"]["Start"] = "1.1.1.2"
    ipv4_address["propertyValueList"]["Step"] = "0.0.1.0"
    assert ipv4_address in propModList

    # Check the propertyModifier for Gateway
    ipv4_gateway = {}
    ipv4_gateway["tagName"] = "ttIpv4If.Gateway"
    ipv4_gateway["className"] = "Ipv4If"
    ipv4_gateway["propertyName"] = "Gateway"
    ipv4_gateway["parentTagName"] = "ttIpv4If"
    ipv4_gateway["propertyValueList"] = {}
    ipv4_gateway["propertyValueList"]["Start"] = "1.1.1.1"
    ipv4_gateway["propertyValueList"]["Step"] = "0.0.1.0"
    assert ipv4_gateway in propModList

    # Check the Vlan interface
    interface = interfaceList[1]
    assert len(interface) == 1

    # Check that the propertyModifierList contains one propertyModifier(VlanId)
    propModList = interface["stmPropertyModifierList"]
    assert len(propModList) == 1

    # Check the VlanId propertyModifier
    vlan = {}
    vlan["tagName"] = "ttVlanIf.VlanId"
    vlan["className"] = "VlanIf"
    vlan["propertyName"] = "VlanId"
    vlan["parentTagName"] = "ttVlanIf"
    vlan["propertyValueList"] = {}
    vlan["propertyValueList"]["Start"] = "100"
    vlan["propertyValueList"]["Step"] = "0"
    assert vlan in propModList

    # Check that ProtocolList contains BFD, BGP
    protocolList = table_dict["protocolList"]
    assert len(protocolList) == 2

    bgp = protocolList[0]
    assert bgp["protocolSrcTag"] == "ttBgpRouterConfig"

    # Check that BgpRouterConfig contains two propertyModifiers(AsNum and DutAsNum)
    propModList = bgp["stmPropertyModifierList"]
    assert len(propModList) == 2

    # Check the AsNum propertyModifier
    as_num = {}
    as_num["tagName"] = "ttBgpRouterConfig.AsNum"
    as_num["className"] = "BgpRouterConfig"
    as_num["propertyName"] = "AsNum"
    as_num["parentTagName"] = "ttBgpRouterConfig"
    as_num["propertyValueList"] = {}
    as_num["propertyValueList"]["Start"] = "100"
    as_num["propertyValueList"]["Step"] = "1"
    assert as_num in propModList

    # Check the DutAsNum propertyModifier
    dut_as_num = {}
    dut_as_num["tagName"] = "ttBgpRouterConfig.DutAsNum"
    dut_as_num["className"] = "BgpRouterConfig"
    dut_as_num["propertyName"] = "DutAsNum"
    dut_as_num["parentTagName"] = "ttBgpRouterConfig"
    dut_as_num["propertyValueList"] = {}
    dut_as_num["propertyValueList"]["Start"] = "100"
    dut_as_num["propertyValueList"]["Step"] = "1"
    assert dut_as_num in propModList

    # Check BgpRouterConfigs propertyValueList
    propValList = bgp["propertyValueList"]
    assert len(propValList) == 1
    propVal = propValList[0]
    assert propVal["className"] == "BgpRouterConfig"
    assert propVal["tagName"] == "ttBgpRouterConfig"
    assert propVal["propertyValueList"]["IpVersion"] == "IPV4"
    assert propVal["propertyValueList"]["EnableBfd"] == "True"

    # Check the BfdRouterConfig
    bfd = protocolList[1]

    assert bfd["protocolSrcTag"] == "ttBfdRouterConfig"

    # Check BfdRouterConfigs propertyValueList
    propValList = bfd["propertyValueList"]
    assert len(propValList) == 1
    propVal = propValList[0]
    assert propVal["className"] == "BfdRouterConfig"
    assert propVal["tagName"] == "ttBfdRouterConfig"
    assert propVal["propertyValueList"]["DetectMultiplier"] == "1"
    assert propVal["propertyValueList"]["TxInterval"] == "2"
    assert propVal["propertyValueList"]["RxInterval"] == "3"

    # Check second mix with Ospfv2 enabled
    table_dict = table_data[1]
    assert table_dict["weight"] == 20.0
    assert table_dict["useBlock"] is False
    assert table_dict["deviceTag"] == "ttEmulatedDevice"
    assert table_dict["baseTemplateFile"] == "Dual_Vlan.xml"
    assert table_dict["protocolTemplateFile"] == "AllRouters.xml"

    protocolList = table_dict["protocolList"]

    # Check the Ospfv2RouterConfig
    ospfv2 = protocolList[0]
    assert ospfv2["protocolSrcTag"] == "ttOspfv2RouterConfig"

    # Check Ospfv2RouterConfig propertyValueList
    propValList = ospfv2["propertyValueList"]
    assert len(propValList) == 1
    propVal = propValList[0]
    assert propVal["className"] == "Ospfv2RouterConfig"
    assert propVal["tagName"] == "ttOspfv2RouterConfig"
    assert propVal["propertyValueList"]["EnableBfd"] == "False"

    # Check that Ospfv2RouterConfig contains 1 propertyModifier (AreaId)
    propModList = ospfv2["stmPropertyModifierList"]
    assert len(propModList) == 1

    area_id = {}
    area_id["tagName"] = "ttOspfv2RouterConfig.AreaId"
    area_id["className"] = "Ospfv2RouterConfig"
    area_id["propertyName"] = "AreaId"
    area_id["parentTagName"] = "ttOspfv2RouterConfig"
    area_id["propertyValueList"] = {}
    area_id["propertyValueList"]["Start"] = "3"
    area_id["propertyValueList"]["Step"] = "0"
    assert area_id in propModList