Beispiel #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,
        })
Beispiel #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',
        })
Beispiel #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
        })
Beispiel #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'
        })
Beispiel #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'
        })