def test_rand16(self): # All possible credit card prefixes prefixes = [4, 51, 55, 2221, 2720, 34, 37] length = 16 for i in range(0, 550000): # picks a random edge case chance_edge_cases = random.randint(0, 2) # keeps the edge case the same as the array if chance_edge_cases == 0: prefix = random.choice(prefixes) # generates a number -1 the picked edge case elif chance_edge_cases == 1: prefix = random.choice(prefixes) prefix -= 1 # generates a number +1 the picked edge case else: prefix = random.choice(prefixes) prefix += 1 # credit: GeeksforGeeks - Generate random string of given length # https://www.geeksforgeeks.org/python-generate-random-string-of # -given-length/ # fill the rest of the credit card number with random ints # and convert to string end_card_numbers = ''.join([ "{}".format(random.randint(0, 9)) for num in range(0, length - len(str(prefix))) ]) # convert the prefix into a string and join the string of numbers rand_creditcard = str(prefix) + end_card_numbers credit_card_validator(str(rand_creditcard))
def test1(self): for i in range(0, 100): val = random.randint(400000000000000, 499999999999999) # calculate Luhn digit and append to get a valid credit card number checksum = luhn(str(val)) card_no = str(val) + str(checksum) credit_card_validator(card_no)
def test14(self): num = 270 for i in range(0, 100): prefix = random.randint(34000000, 34999999) val = str(prefix) + str(num) + str(num) # calculate Luhn digit and append to get a valid credit card number checksum = luhn(str(val)) card_no = str(val) + str(checksum) credit_card_validator(card_no)
def test_prefix_range_mastercard(self): for x in range(0, 1000): for i in range(2221, 2721): cc_prefix = [int(d) for d in str(i)] random_val = random.randint(100000000000, 999999999999) subs_card = [int(d) for d in str(random_val)] cc_list = cc_prefix + subs_card cc_list = [str(i) for i in cc_list] cc_num = int("".join(cc_list)) credit_card_validator(str(cc_num))
def test9(self): suffix = 1111 for i in range(0, 100): prefix = random.randint(3700000000, 3799999999) val = str(prefix) + str(suffix) # calculate Luhn digit and append to get a valid credit card number checksum = luhn(str(val)) card_no = str(val) + str(checksum) credit_card_validator(card_no)
def test8(self): """ Utilizes category partition testing to assess: Prefix : 4 Visa Length : <16 CheckBit : Valid """ self.assertFalse(credit_card_validator("432575174663426"))
def test6(self): """ Utilizes category partition testing to assess: Prefix : 4 Visa Length : >16 CheckBit : Valid """ self.assertFalse(credit_card_validator("42429602404898163"))
def test49(self): """ Utilizes category partition testing to assess: Prefix : 2321 MC (valid prefix) Length : 16 CheckBit : Valid """ self.assertTrue(credit_card_validator("2321686910633480"))
def test47(self): """ Utilizes category partition testing to assess: Prefix : 2521 MC (valid prefix) Length : 16 CheckBit : Valid """ self.assertTrue(credit_card_validator("2521131819156158"))
def test45(self): """ Utilizes category partition testing to assess: Prefix : 2720 MC (valid prefix) Length : 16 CheckBit : Valid """ self.assertTrue(credit_card_validator("2720996726400694"))
def test3(self): """ Utilizes category partition testing to assess: Prefix : 4 Visa (valid prefix) Length : 16 CheckBit : Valid """ self.assertTrue(credit_card_validator("4115587550418370"))
def test2(self): """ Utilizes category partition testing to assess: Prefix : 3 Visa (boundary value) Length : 16 CheckBit : Valid """ self.assertFalse(credit_card_validator("3539804460355539"))
def test34(self): """ Utilizes category partition testing to assess: Prefix : 37 AE (valid prefix) Length : 15 CheckBit : Valid """ self.assertTrue(credit_card_validator("377991636901261"))
def test33(self): """ Utilizes category partition testing to assess: Prefix : 36 AE (boundary case) Length : 15 CheckBit : Valid """ self.assertFalse(credit_card_validator("365521870151770"))
def test31(self): """ Utilizes category partition testing to assess: Prefix : 34 AE Length : >15 CheckBit : Invalid (checksum +1) """ self.assertFalse(credit_card_validator("3410776572135568"))
def test42(self): """ Utilizes category partition testing to assess: Prefix : 53 MC (valid prefix) Length : 16 CheckBit : Valid """ self.assertTrue(credit_card_validator("5332207677321019"))
def test43(self): """ Utilizes category partition testing to assess: Prefix : 54 MC (valid prefix) Length : 16 CheckBit : Valid """ self.assertTrue(credit_card_validator("5453936520873338"))
def test35(self): """ Utilizes category partition testing to assess: Prefix : 37 AE Length : 15 CheckBit : Invalid (checksum -1) """ self.assertFalse(credit_card_validator("377881636901263"))
def test44(self): """ Utilizes category partition testing to assess: Prefix : 55 MC (valid prefix) Length : 16 CheckBit : Valid """ self.assertTrue(credit_card_validator("5568657899972368"))
def test35(self): """ Utilizes category partition testing to assess: Prefix : 37 AE Length : 14 CheckBit : Valid """ self.assertFalse(credit_card_validator("37233778147870"))
def test46(self): """ Utilizes category partition testing to assess: Prefix : 2621 MC (valid prefix) Length : 16 CheckBit : Valid """ self.assertTrue(credit_card_validator("2621136512752434"))
def test36(self): """ Utilizes category partition testing to assess: Prefix : 37 AE Length : 14 CheckBit : Invalid (checksum +1) """ self.assertFalse(credit_card_validator("37233778147871"))
def test48(self): """ Utilizes category partition testing to assess: Prefix : 2421 MC (valid prefix) Length : 16 CheckBit : Valid """ self.assertTrue(credit_card_validator("2421480425073427"))
def test38(self): """ Utilizes category partition testing to assess: Prefix : 37 AE Length : >15 CheckBit : Invalid (checksum -1) """ self.assertFalse(credit_card_validator("3759389287537693"))
def test5(self): """ Utilizes category partition testing to assess: Prefix : 4 Visa Length : >16 CheckBit : Invalid (checksum +1) """ self.assertFalse(credit_card_validator("45689647070436284"))
def test39(self): """ Utilizes category partition testing to assess: Prefix : 38 AE (boundary case) Length : 15 CheckBit : Valid """ self.assertFalse(credit_card_validator("384381529084162"))
def test7(self): """ Utilizes category partition testing to assess: Prefix : 4 Visa Length : <16 CheckBit : Invalid (checksum -1) """ self.assertFalse(credit_card_validator("401100920910868"))
def test40(self): """ Utilizes category partition testing to assess: Prefix : 0000 Length : 16 CheckBit : Valid """ self.assertFalse(credit_card_validator("0000000000000000"))
def test9(self): """ Utilizes category partition testing to assess: Prefix : 5 Visa (boundary value) Length : 16 CheckBit : Valid """ self.assertFalse(credit_card_validator("5769518937345776"))
def test41(self): """ Utilizes category partition testing to assess: Prefix : 52 MC (valid prefix) Length : 16 CheckBit : Valid """ self.assertTrue(credit_card_validator("5257193687554768"))