def test_sets_dates_in_future_to_none(self): simple_row = { 'Something': '2060-02-24' } schema = OrderedDict([ ('Something', { 'type': 'Date' }) ]) actual = Caster.cast(simple_row, schema) self.assertEqual(actual, { 'Something': None, })
def test_strips_whitespace(self): simple_row = { 'Something': ' padded ' } schema = OrderedDict([ ('Something', { 'type': 'String' }) ]) actual = Caster.cast(simple_row, schema) self.assertEqual(actual, { 'Something': 'padded', })
def test_returns_none_for_missing_schema_items(self): simple_row = { 'Something': 'does not get removed' } schema = OrderedDict([ ('Missing', { 'type': 'String' }) ]) actual = Caster.cast(simple_row, schema) self.assertEqual(actual, { 'Something': 'does not get removed', 'Missing': None })
def test_can_cast_to_string_and_truncate(self): number = 12345 simple_row = { 'OrgId': number } schema = OrderedDict([ ('OrgId', { 'type': 'String', 'length': 2 }) ]) actual = Caster.cast(simple_row, schema) self.assertEqual(actual, { 'OrgId': '12' })
def test_output_format(self): number = 12345 simple_row = { 'OrgId': number, 'StationId': 'ABC-abc' } schema = OrderedDict([ ('OrgId', { 'type': 'String', 'length': 2 }), ('StationId', { 'type': 'String' }) ]) actual = Caster.cast(simple_row, schema) self.assertEqual(actual, { 'OrgId': '12', 'StationId': 'ABC-abc' })