Exemplo n.º 1
0
    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,
        })
Exemplo n.º 2
0
    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',
        })
Exemplo n.º 3
0
    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
        })
Exemplo n.º 4
0
    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'
        })
Exemplo n.º 5
0
    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'
        })
Exemplo n.º 6
0
    def test_convert_numbers_to_strings(self):
        input = {'num': 1.2345}
        actual = Caster.cast_for_sql(input)

        self.assertEqual(actual['num'], '1.2345')
Exemplo n.º 7
0
    def test_null_for_none(self):
        input = {'test': None}
        actual = Caster.cast_for_sql(input)

        self.assertEqual(actual['test'], 'Null')
Exemplo n.º 8
0
    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)")
Exemplo n.º 9
0
    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'")
Exemplo n.º 10
0
    def test_doesnt_touch_shape(self):
        input = {'Shape': 'blah'}
        actual = Caster.cast_for_sql(input)

        self.assertEqual(actual['Shape'], 'blah')