Esempio n. 1
0
 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))
Esempio n. 2
0
 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)
Esempio n. 3
0
    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)
Esempio n. 4
0
 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))
Esempio n. 5
0
    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)
Esempio n. 6
0
 def test8(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  4 Visa
     Length   :  <16
     CheckBit :  Valid
     """
     self.assertFalse(credit_card_validator("432575174663426"))
Esempio n. 7
0
 def test6(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  4 Visa
     Length   :  >16
     CheckBit :  Valid
     """
     self.assertFalse(credit_card_validator("42429602404898163"))
Esempio n. 8
0
 def test49(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  2321 MC (valid prefix)
     Length   :  16
     CheckBit :  Valid
     """
     self.assertTrue(credit_card_validator("2321686910633480"))
Esempio n. 9
0
 def test47(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  2521 MC (valid prefix)
     Length   :  16
     CheckBit :  Valid
     """
     self.assertTrue(credit_card_validator("2521131819156158"))
Esempio n. 10
0
 def test45(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  2720 MC (valid prefix)
     Length   :  16
     CheckBit :  Valid
     """
     self.assertTrue(credit_card_validator("2720996726400694"))
Esempio n. 11
0
 def test3(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  4 Visa (valid prefix)
     Length   :  16
     CheckBit :  Valid
     """
     self.assertTrue(credit_card_validator("4115587550418370"))
Esempio n. 12
0
 def test2(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  3 Visa (boundary value)
     Length   :  16
     CheckBit :  Valid
     """
     self.assertFalse(credit_card_validator("3539804460355539"))
Esempio n. 13
0
 def test34(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  37 AE (valid prefix)
     Length   :  15
     CheckBit :  Valid
     """
     self.assertTrue(credit_card_validator("377991636901261"))
Esempio n. 14
0
 def test33(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  36 AE (boundary case)
     Length   :  15
     CheckBit :  Valid
     """
     self.assertFalse(credit_card_validator("365521870151770"))
Esempio n. 15
0
 def test31(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  34 AE
     Length   :  >15
     CheckBit :  Invalid (checksum +1)
     """
     self.assertFalse(credit_card_validator("3410776572135568"))
Esempio n. 16
0
 def test42(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  53 MC (valid prefix)
     Length   :  16
     CheckBit :  Valid
     """
     self.assertTrue(credit_card_validator("5332207677321019"))
Esempio n. 17
0
 def test43(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  54 MC (valid prefix)
     Length   :  16
     CheckBit :  Valid
     """
     self.assertTrue(credit_card_validator("5453936520873338"))
Esempio n. 18
0
 def test35(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  37 AE
     Length   :  15
     CheckBit :  Invalid (checksum -1)
     """
     self.assertFalse(credit_card_validator("377881636901263"))
Esempio n. 19
0
 def test44(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  55 MC (valid prefix)
     Length   :  16
     CheckBit :  Valid
     """
     self.assertTrue(credit_card_validator("5568657899972368"))
Esempio n. 20
0
 def test35(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  37 AE
     Length   :  14
     CheckBit :  Valid
     """
     self.assertFalse(credit_card_validator("37233778147870"))
Esempio n. 21
0
 def test46(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  2621 MC (valid prefix)
     Length   :  16
     CheckBit :  Valid
     """
     self.assertTrue(credit_card_validator("2621136512752434"))
Esempio n. 22
0
 def test36(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  37 AE
     Length   :  14
     CheckBit :  Invalid (checksum +1)
     """
     self.assertFalse(credit_card_validator("37233778147871"))
Esempio n. 23
0
 def test48(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  2421 MC (valid prefix)
     Length   :  16
     CheckBit :  Valid
     """
     self.assertTrue(credit_card_validator("2421480425073427"))
Esempio n. 24
0
 def test38(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  37 AE
     Length   :  >15
     CheckBit :  Invalid (checksum -1)
     """
     self.assertFalse(credit_card_validator("3759389287537693"))
Esempio n. 25
0
 def test5(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  4 Visa
     Length   :  >16
     CheckBit :  Invalid (checksum +1)
     """
     self.assertFalse(credit_card_validator("45689647070436284"))
Esempio n. 26
0
 def test39(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  38 AE (boundary case)
     Length   :  15
     CheckBit :  Valid
     """
     self.assertFalse(credit_card_validator("384381529084162"))
Esempio n. 27
0
 def test7(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  4 Visa
     Length   :  <16
     CheckBit :  Invalid (checksum -1)
     """
     self.assertFalse(credit_card_validator("401100920910868"))
Esempio n. 28
0
 def test40(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  0000
     Length   :  16
     CheckBit :  Valid
     """
     self.assertFalse(credit_card_validator("0000000000000000"))
Esempio n. 29
0
 def test9(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  5 Visa (boundary value)
     Length   :  16
     CheckBit :  Valid
     """
     self.assertFalse(credit_card_validator("5769518937345776"))
Esempio n. 30
0
 def test41(self):
     """
     Utilizes category partition testing to assess:
     Prefix   :  52 MC (valid prefix)
     Length   :  16
     CheckBit :  Valid
     """
     self.assertTrue(credit_card_validator("5257193687554768"))