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' })
def test_convert_numbers_to_strings(self): input = {'num': 1.2345} actual = Caster.cast_for_sql(input) self.assertEqual(actual['num'], '1.2345')
def test_null_for_none(self): input = {'test': None} actual = Caster.cast_for_sql(input) self.assertEqual(actual['test'], 'Null')
def test_casts_old_dates(self): input = {'date': datetime.datetime(1800, 8, 11)} actual = Caster.cast_for_sql(input) self.assertEqual(actual['date'], "Cast('1800-08-11' as datetime)")
def test_escape_quotes_in_strings(self): input = {'hello': 'bl\'ah', 'hello2': 'bl\'\'ah2'} actual = Caster.cast_for_sql(input) self.assertEqual(actual['hello'], "'bl''ah'") self.assertEqual(actual['hello2'], "'bl''''ah2'")
def test_doesnt_touch_shape(self): input = {'Shape': 'blah'} actual = Caster.cast_for_sql(input) self.assertEqual(actual['Shape'], 'blah')