Exemplo n.º 1
0
def testValidJsonPathValidateType():
    result = question._validateType({
        "path": "I am path",
        "suffix": True
    }, "jsonPath")
    assert result[0]
    assert result[1] is None
Exemplo n.º 2
0
def testInvalidProtocolValidateType():
    result = question._validateType("TCPP", "protocol")
    expectMessage = (
        "'TCPP' is not a valid protocols. Valid options are: 'dns, ssh, tcp, udp'"
    )
    assert not result[0]
    assert expectMessage == result[1]
Exemplo n.º 3
0
def testValidJsonPathValidateType():
    result = question._validateType({
        'path': 'I am path',
        'suffix': True
    }, 'jsonPath')
    assert result[0]
    assert result[1] is None
Exemplo n.º 4
0
def testInvalidComparatorValidateType():
    result = question._validateType("<==", "comparator")
    expectMessage = (
        "'<==' is not a known comparator. Valid options are: '<, <=, ==, >=, >, !='"
    )
    assert not result[0]
    assert expectMessage == result[1]
Exemplo n.º 5
0
def testSuffixNonBooleanJsonPathValidateType():
    result = question._validateType({
        'path': 'I am path',
        'suffix': 'hi'
    }, 'jsonPath')
    expectMessage = "'suffix' element of jsonPath dictionary should be a boolean"
    assert not result[0]
    assert expectMessage == result[1]
Exemplo n.º 6
0
def testSuffixNonBooleanJsonPathValidateType():
    result = question._validateType({
        "path": "I am path",
        "suffix": "hi"
    }, "jsonPath")
    expectMessage = "'suffix' element of jsonPath dictionary should be a boolean"
    assert not result[0]
    assert expectMessage == result[1]
Exemplo n.º 7
0
def testInvalidCompletionTypes():
    # TODO: simplify to COMPLETION_TYPES after VariableType.BGP_ROUTE_STATUS_SPEC is moved
    for completion_type in set(COMPLETION_TYPES +
                               [VariableType.BGP_ROUTE_STATUS_SPEC]):
        result = question._validateType(5, completion_type)
        expectMessage = "A Batfish " + completion_type + " must be a string"
        assert not result[0]
        assert result[1] == expectMessage
Exemplo n.º 8
0
def testValidCompletionTypes():
    values = {
        VariableType.IP: "1.2.3.4",
        VariableType.PREFIX: "1.2.3.4/24",
        VariableType.PROTOCOL: "ssh"
    }
    for completion_type in COMPLETION_TYPES:
        result = question._validateType(values.get(completion_type, ".*"),
                                        completion_type)
        assert result[0]
        assert result[1] is None
Exemplo n.º 9
0
def testValidCompletionTypes():
    values = {
        VariableType.IP: "1.2.3.4",
        VariableType.PREFIX: "1.2.3.4/24",
        VariableType.PROTOCOL: "ssh",
    }
    # TODO: simplify to COMPLETION_TYPES after VariableType.BGP_ROUTE_STATUS_SPEC is moved
    for completion_type in set(COMPLETION_TYPES +
                               [VariableType.BGP_ROUTE_STATUS_SPEC]):
        result = question._validateType(values.get(completion_type, ".*"),
                                        completion_type)
        assert result[0]
        assert result[1] is None
Exemplo n.º 10
0
def testValidIntegerSubRangeValidateType():
    result = question._validateType(10, "subrange")
    assert result[0]
    assert result[1] is None
Exemplo n.º 11
0
def testValidIntegerIpProtocolValidateType():
    result = question._validateType('10', 'ipProtocol')
    assert result[0]
    assert result[1] is None
Exemplo n.º 12
0
def testInvalidBooleanValidateType():
    result = question._validateType(1.5, "boolean")
    assert not result[0]
Exemplo n.º 13
0
def testInvalidTypeSubRangeValidateType():
    result = question._validateType(10.0, "subrange")
    expectMessage = "A Batfish subrange must either be a string or an integer"
    assert not result[0]
    assert expectMessage == result[1]
Exemplo n.º 14
0
def testValidProtocolValidateType():
    result = question._validateType('TCP', 'protocol')
    assert result[0]
    assert result[1] is None
Exemplo n.º 15
0
def testValidComparatorValidateType():
    result = question._validateType("<=", "comparator")
    assert result[0]
Exemplo n.º 16
0
def testInvalidNonDictionaryJsonPathValidateType():
    result = question._validateType(10, "jsonPath")
    expectMessage = "Expected a jsonPath dictionary with elements 'path' (string) and optional 'suffix' (boolean)"
    assert not result[0]
    assert expectMessage == result[1]
Exemplo n.º 17
0
def testInvalidIntegerIpProtocolValidateType():
    result = question._validateType("1000", "ipProtocol")
    expectMessage = "'1000' is not in valid ipProtocol range: 0-255"
    assert not result[0]
    assert expectMessage == result[1]
Exemplo n.º 18
0
def testValidLongValidateType():
    result = question._validateType(10, "long")
    assert result[0]
    result = question._validateType(2**40, "long")
    assert result[0]
Exemplo n.º 19
0
def testInvalidIntegerValidateType():
    result = question._validateType(1.5, "integer")
    assert not result[0]
Exemplo n.º 20
0
def testInvalidLongValidateType():
    result = question._validateType(5.3, "long")
    assert not result[0]
    result = question._validateType(2**64, "long")
    assert not result[0]
Exemplo n.º 21
0
def testValidDoubleValidateType():
    result = question._validateType(10.0, "double")
    assert result[0]
Exemplo n.º 22
0
def testValidFloatValidateType():
    result = question._validateType(10.0, "float")
    assert result[0]
Exemplo n.º 23
0
def testValidProtocolValidateType():
    result = question._validateType("TCP", "protocol")
    assert result[0]
    assert result[1] is None
Exemplo n.º 24
0
def testInvalidDictionaryJsonPathValidateType():
    result = question._validateType({"value": 10}, "jsonPath")
    expectMessage = "Missing 'path' element of jsonPath"
    assert not result[0]
    assert expectMessage == result[1]
Exemplo n.º 25
0
def testNonStringIpProtocolValidateType():
    result = question._validateType(10.0, "ipProtocol")
    expectMessage = "A Batfish ipProtocol must be a string"
    assert not result[0]
    assert expectMessage == result[1]
Exemplo n.º 26
0
def testPathNonStringJsonPathValidateType():
    result = question._validateType({"path": 10}, "jsonPath")
    expectMessage = "'path' element of jsonPath dictionary should be a string"
    assert not result[0]
    assert expectMessage == result[1]
Exemplo n.º 27
0
def testValidIntegerIpProtocolValidateType():
    result = question._validateType("10", "ipProtocol")
    assert result[0]
    assert result[1] is None
Exemplo n.º 28
0
def testValidBooleanValidateType():
    result = question._validateType(True, "boolean")
    assert result[0]
Exemplo n.º 29
0
def testInvalidJavaRegexValidateType():
    result = question._validateType(10, "javaRegex")
    expectMessage = "A Batfish javaRegex must be a string"
    assert not result[0]
    assert expectMessage == result[1]
Exemplo n.º 30
0
def testValidIntegerValidateType():
    result = question._validateType(10, "integer")
    assert result[0]