예제 #1
0
    def testPersonnummerSex(self):
        for item in test_data:
            for format in availableListFormats:
                if not item['valid']:
                    return

                self.assertEqual(
                    personnummer.parse(item[format]).isMale(), item['isMale'])
                self.assertEqual(
                    personnummer.parse(item[format]).isFemale(),
                    item['isFemale'])
예제 #2
0
 def testPersonnummerFormat(self):
     for item in test_data:
         for format in availableListFormats:
             if format != 'short_format' and item['separated_format'].find(
                     '+') != -1:
                 self.assertEqual(
                     personnummer.parse(item[format]).format(),
                     item['separated_format'])
                 self.assertEqual(
                     personnummer.parse(item[format]).format(True),
                     item['long_format'])
예제 #3
0
    def testPersonnummerError(self):
        for item in test_data:
            for format in availableListFormats:
                if item['valid']:
                    return

                try:
                    personnummer.parse(item[format])
                    self.assertTrue(False)
                except:
                    self.assertTrue(True)
예제 #4
0
def format_personnummer(personnummer):
    """
    Format personnummer into the long format.

    If personnummer is a T-number, no formating is done
    """
    try:
        parsed_personnummer = pn.parse(personnummer)
        # Format the personnummer into the long format
        return parsed_personnummer.format(True)
    except pn.PersonnummerException:
        # This exception occurs if the personnummer is a t-number.
        # All logic regarding the t-numbers are handled in the
        # personnummer validator so here we just return the personnummer.
        return personnummer
예제 #5
0
    def testPersonnummerAge(self):
        for item in test_data:
            for format in availableListFormats:
                if format != 'short_format' and item['separated_format'].find(
                        '+') != -1:
                    pin = item['separated_long']
                    year = int(pin[0:4])
                    month = int(pin[4:6])
                    day = int(pin[6:8])

                    if item['type'] == 'con':
                        day = day - 60

                    date = datetime(year=year, month=month, day=day)
                    p = personnummer.parse(item[format])

                    with mock.patch(
                            'personnummer.personnummer.get_current_datetime',
                            mock.Mock(return_value=date)):
                        self.assertEqual(0, p.get_age())