Example #1
0
    def credit_card_number(self, card_type='visa'):
        """Generate a random credit card number.

        :param card_type: Issuing Network. Default is Visa.
        :return: Credit card number.
        :Example:
            4455 5299 1152 2450
        """
        length = 16
        regex = re.compile('(\d{4})(\d{4})(\d{4})(\d{4})')

        if card_type in ('visa', 'vi', 'v'):
            number = self.random.randint(4000, 4999)
        elif card_type in ('master_card', 'mc', 'master', 'm'):
            number = self.random.choice([
                self.random.randint(2221, 2720),
                self.random.randint(5100, 5500)
            ])
        elif card_type in ('american_express', 'amex', 'ax', 'a'):
            number = self.random.choice([34, 37])
            length = 15
            regex = re.compile('(\d{4})(\d{6})(\d{5})')
        else:
            raise NotImplementedError(
                'Card type {} is not supported.'.format(card_type))

        number = str(number)
        while len(number) < length - 1:
            number += self.random.choice(digits)

        card = ' '.join(regex.search(number + luhn_checksum(number)).groups())
        return card
Example #2
0
    def imei(self) -> str:
        """Generate a random IMEI.

        :return: IMEI.
        """
        num = self.random.choice(IMEI_TACS)
        num = num + str(self.random.randint(100000, 999999))
        return num + luhn_checksum(num)
Example #3
0
    def imei(self):
        """Generate a random IMEI (International Mobile Station Equipment Identity).

        :return: IMEI.
        :Example:
            353918052107063
        """
        num = self.random.choice(IMEI_TACS) + self.custom_code(mask='######')
        return num + luhn_checksum(num)
Example #4
0
    def credit_card_number(self, card_type: Optional[CardType] = None) -> str:
        """Generate a random credit card number.

        :param card_type: Issuing Network. Default is Visa.
        :return: Credit card number.
        :raises NotImplementedError: if cart_type is not supported.

        :Example:
            4455 5299 1152 2450
        """
        length = 16
        regex = re.compile('(\d{4})(\d{4})(\d{4})(\d{4})')

        if card_type is None:
            card_type = get_random_item(CardType, rnd=self.random)

        if card_type == CardType.VISA:
            number = self.random.randint(4000, 4999)
        elif card_type == CardType.MASTER_CARD:
            number = self.random.choice([
                self.random.randint(2221, 2720),
                self.random.randint(5100, 5500),
            ])
        elif card_type == CardType.AMERICAN_EXPRESS:
            number = self.random.choice([34, 37])
            length = 15
            regex = re.compile('(\d{4})(\d{6})(\d{5})')
        else:
            raise NonEnumerableError(CardType)

        str_num = str(number)
        while len(str_num) < length - 1:
            str_num += self.random.choice(string.digits)

        groups = regex.search(  # type: ignore
            str_num + luhn_checksum(str_num), ).groups()
        card = ' '.join(groups)
        return card
Example #5
0
def test_luhn_checksum():
    assert luhn_checksum('7992739871') == '3'