Example #1
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')
Example #2
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')
Example #3
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')
Example #4
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}})
Example #5
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'})
Example #6
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'})
Example #7
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})
Example #8
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})
Example #9
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'})
Example #10
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})
Example #11
0
 def test_convert_type_unicode_str(self):
     """ParserBase - Convert Type, Unicode Str"""
     schema = {'key': 'string'}
     record = {'key': u'\ue82a'}
     assert_equal(ParserBase._convert_type(record, schema), True)
     assert_equal(record, {'key': u'\ue82a'})
Example #12
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'})