Exemplo n.º 1
0
 def test_parsed_value(self):
     """
     Tests that the parsed value from the string value is placed on
     the parsed_value property.
     """
     self.assertEqual(
         FieldValue('true', FieldTypes.BOOLEAN).parsed_value,
         True,
     )
     self.assertEqual(
         FieldValue('4.5', FieldTypes.FLOAT).parsed_value,
         4.5,
     )
     self.assertEqual(
         FieldValue('10.43.23.43', FieldTypes.IP_ADDR).parsed_value,
         '10.43.23.43',
     )
Exemplo n.º 2
0
    def test_parsing_error(self):
        """
        Tests that a FieldValueParserError message is added to the list
        of FieldValue messages if the exception is raised during parsing.
        """
        field_value = FieldValue('blah', FieldTypes.BOOLEAN)

        self.assertEqual(len(field_value.errors), 1)
        self.assertEqual(
            field_value.errors[0],
            FieldValueParsers.INVALID_BOOLEAN_CHOICE,
        )
Exemplo n.º 3
0
    def test_empty_value(self):
        """
        Tests that an EMPTY_VALUE error message is added to the error
        messages if the string value is empty.
        """
        field_value = FieldValue('', FieldTypes.BOOLEAN)

        self.assertEqual(len(field_value.errors), 1)
        self.assertEqual(
            field_value.errors[0],
            FieldValue.EMPTY_VALUE,
        )
Exemplo n.º 4
0
    def test_missing_parser(self):
        """
        Tests that a MISSING_PARSER error message is added to the error
        messages if there is no assigned FieldValueParser parser to the
        known field_type.
        """
        field_value = FieldValue('test', FieldTypes.LIST)

        self.assertEqual(len(field_value.errors), 1)
        self.assertEqual(
            field_value.errors[0],
            FieldValue.MISSING_PARSER.format(FieldTypes.LIST),
        )
Exemplo n.º 5
0
    def test_raises_invalid_field(self):
        """
        Tests that an INVALID_FIELD_TYPE error message is added to
        the error messages if the field_type is not in the known list of
        field types.
        """
        field_value = FieldValue('test', 'test')

        self.assertEqual(len(field_value.errors), 1)
        self.assertEqual(
            field_value.errors[0],
            FieldValue.INVALID_FIELD_TYPE.format('test'),
        )