def testValidJsonPathValidateType(): result = question._validateType({ "path": "I am path", "suffix": True }, "jsonPath") assert result[0] assert result[1] is None
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]
def testValidJsonPathValidateType(): result = question._validateType({ 'path': 'I am path', 'suffix': True }, 'jsonPath') assert result[0] assert result[1] is None
def testInvalidComparatorValidateType(): result = question._validateType("<==", "comparator") expectMessage = ( "'<==' is not a known comparator. Valid options are: '<, <=, ==, >=, >, !='" ) assert not result[0] assert expectMessage == result[1]
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]
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]
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
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
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
def testValidIntegerSubRangeValidateType(): result = question._validateType(10, "subrange") assert result[0] assert result[1] is None
def testValidIntegerIpProtocolValidateType(): result = question._validateType('10', 'ipProtocol') assert result[0] assert result[1] is None
def testInvalidBooleanValidateType(): result = question._validateType(1.5, "boolean") assert not result[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]
def testValidProtocolValidateType(): result = question._validateType('TCP', 'protocol') assert result[0] assert result[1] is None
def testValidComparatorValidateType(): result = question._validateType("<=", "comparator") assert result[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]
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]
def testValidLongValidateType(): result = question._validateType(10, "long") assert result[0] result = question._validateType(2**40, "long") assert result[0]
def testInvalidIntegerValidateType(): result = question._validateType(1.5, "integer") assert not result[0]
def testInvalidLongValidateType(): result = question._validateType(5.3, "long") assert not result[0] result = question._validateType(2**64, "long") assert not result[0]
def testValidDoubleValidateType(): result = question._validateType(10.0, "double") assert result[0]
def testValidFloatValidateType(): result = question._validateType(10.0, "float") assert result[0]
def testValidProtocolValidateType(): result = question._validateType("TCP", "protocol") assert result[0] assert result[1] is None
def testInvalidDictionaryJsonPathValidateType(): result = question._validateType({"value": 10}, "jsonPath") expectMessage = "Missing 'path' element of jsonPath" assert not result[0] assert expectMessage == result[1]
def testNonStringIpProtocolValidateType(): result = question._validateType(10.0, "ipProtocol") expectMessage = "A Batfish ipProtocol must be a string" assert not result[0] assert expectMessage == result[1]
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]
def testValidIntegerIpProtocolValidateType(): result = question._validateType("10", "ipProtocol") assert result[0] assert result[1] is None
def testValidBooleanValidateType(): result = question._validateType(True, "boolean") assert result[0]
def testInvalidJavaRegexValidateType(): result = question._validateType(10, "javaRegex") expectMessage = "A Batfish javaRegex must be a string" assert not result[0] assert expectMessage == result[1]
def testValidIntegerValidateType(): result = question._validateType(10, "integer") assert result[0]