Ejemplo n.º 1
0
 def test_convert_type_list(self):
     """ParserBase - Convert Type, Invalid List"""
     schema = {
         'key': []
     }
     record = {
         'key': 'not a list'
     }
     assert_equal(ParserBase._convert_type(record, schema), False)
     assert_equal(record, {'key': 'not a list'})
Ejemplo n.º 2
0
 def test_convert_type_float_invalid(self):
     """ParserBase - Convert Type, Invalid Float"""
     schema = {
         'key': 'float'
     }
     record = {
         'key': 'not a float'
     }
     assert_equal(ParserBase._convert_type(record, schema), False)
     assert_equal(record, {'key': 'not a float'})
Ejemplo n.º 3
0
 def test_convert_type_bool(self):
     """ParserBase - Convert Type, Boolean"""
     schema = {
         'key': 'boolean'
     }
     record = {
         'key': 'True'
     }
     assert_equal(ParserBase._convert_type(record, schema), True)
     assert_equal(record, {'key': True})
Ejemplo n.º 4
0
 def test_convert_type_float(self):
     """ParserBase - Convert Type, Float"""
     schema = {
         'key': 'float'
     }
     record = {
         'key': '0.9'
     }
     assert_equal(ParserBase._convert_type(record, schema), True)
     assert_equal(record, {'key': 0.9})
Ejemplo n.º 5
0
 def test_convert_type_int_invalid(self):
     """ParserBase - Convert Type, Invalid Int"""
     schema = {
         'key': 'integer'
     }
     record = {
         'key': 'not an int'
     }
     assert_equal(ParserBase._convert_type(record, schema), False)
     assert_equal(record, {'key': 'not an int'})
Ejemplo n.º 6
0
 def test_convert_type_int(self):
     """ParserBase - Convert Type, Int"""
     schema = {
         'key': 'integer'
     }
     record = {
         'key': '100'
     }
     assert_equal(ParserBase._convert_type(record, schema), True)
     assert_equal(record, {'key': 100})
Ejemplo n.º 7
0
 def test_convert_type_unicode_str(self):
     """ParserBase - Convert Type, Unicode Str"""
     schema = {
         'key': 'string'
     }
     record = {
         'key': '\ue82a'
     }
     assert_equal(ParserBase._convert_type(record, schema), True)
     assert_equal(record, {'key': '\ue82a'})
Ejemplo n.º 8
0
 def test_convert_type_str(self):
     """ParserBase - Convert Type, Str"""
     schema = {
         'key': 'string'
     }
     record = {
         'key': 100
     }
     assert_equal(ParserBase._convert_type(record, schema), True)
     assert_equal(record, {'key': '100'})
Ejemplo n.º 9
0
 def test_convert_type_none(self, log_mock):
     """ParserBase - Convert Type, NoneType Value"""
     schema = {
         'key': 'string'
     }
     record = {
         'key': None
     }
     assert_equal(ParserBase._convert_type(record, schema), True)
     assert_equal(record, {'key': None})
     log_mock.assert_called_with('Skipping NoneType value in record for key: %s', 'key')
Ejemplo n.º 10
0
 def test_convert_type_unsupported_type(self, log_mock):
     """ParserBase - Convert Type, Unsupported Type"""
     schema = {
         'key': 'foobar'
     }
     record = {
         'key': 'foobarbaz'
     }
     assert_equal(ParserBase._convert_type(record, schema), False)
     assert_equal(record, {'key': 'foobarbaz'})
     log_mock.assert_called_with(
         'Unsupported value type in schema for key \'%s\': %s', 'key', 'foobar'
     )
Ejemplo n.º 11
0
 def test_convert_type_optionals(self, log_mock):
     """ParserBase - Convert Type, With Optionals Missing"""
     schema = {
         'required_key': 'string',
         'optional_key': 'string'
     }
     optionals = {'optional_key'}
     record = {
         'required_key': 'required_value'
     }
     assert_equal(ParserBase._convert_type(record, schema, optionals), True)
     assert_equal(record, {'required_key': 'required_value'})
     log_mock.assert_called_with(
         'Skipping optional key not found in record: %s', 'optional_key')
Ejemplo n.º 12
0
 def test_convert_type_nested(self):
     """ParserBase - Convert Type, Nested"""
     schema = {
         'key': 'string',
         'nested': {
             'key': 'integer'
         }
     }
     record = {
         'key': 'foo',
         'nested': {
             'key': '100'
         }
     }
     assert_equal(ParserBase._convert_type(record, schema), True)
     assert_equal(record, {'key': 'foo', 'nested': {'key': 100}})