Beispiel #1
0
    def test__format_display(self):
        # (value, expect, label)
        tests = [
            ('', '', 'empty string'),
            (None, '', 'none'),
            ('A1B 2C3', 'A1B 2C3', 'typical can'),
            ('a1b 2c3', 'a1b 2c3', 'typical can lowercase'),
            ('A1B2C3', 'A1B2C3', 'typical can no space'),
            ('123456789', '123456789', 'typical usa 9'),
            ('12345', '12345', 'typical usa 5'),
            ]

        for t in tests:
            postal_code = PostalCode(t[0])
            self.assertEqual(postal_code.format_display(), t[1])

        # Handle non-typical postal_code number
        value = 'Not Available'
        postal_code = PostalCode(value)
        self.assertEqual(postal_code.format_display(), value)
Beispiel #2
0
    def test__format_storage(self):
        # (value, expect, label)
        tests = [
            ('', '', 'empty string'),
            (None, '', 'none'),
            ('A1B 2C3', 'A1B2C3', 'typical can'),
            ('a1b 2c3', 'A1B2C3', 'typical can lowercase'),
            ('A1B2C3', 'A1B2C3', 'typical can no space'),
            ('123456789', '123456789', 'typical usa 9'),
            ('12345', '12345', 'typical usa 5'),
            ('abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                'lowercase letters'),
            ('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                'uppercase letters'),
            ('!@#$%^&*()<>?/|\[]{};:"_+-=', '', 'non-alphanumeric'),
            ]

        for t in tests:
            postal_code = PostalCode(t[0])
            self.assertEqual(postal_code.format_storage(), t[1])

        # Handle non-typical postal_codes
        value = 'Not Available'
        expect = 'NOTAVAILABLE'
        postal_code = PostalCode(value)
        self.assertEqual(postal_code.format_storage(), expect)
        postal_code = PostalCode(' ' + value + ' ')
        self.assertEqual(postal_code.format_storage(), expect)