Esempio n. 1
0
 def test_search_string_non_luhn(self):
     ps = PanScanner()
     n = '4111111111111113'
     test_match = ps.reqex.match(n)
     self.assertTrue(test_match)
     matches = ps.search_string(n)
     self.assertEqual(len(matches), 0)
Esempio n. 2
0
 def test_search_string_non_luhn(self):
     ps = PanScanner()
     n = '4111111111111113'
     test_match = ps.reqex.match(n)
     self.assertTrue(test_match)
     matches = ps.search_string(n)
     self.assertEqual(len(matches), 0)
Esempio n. 3
0
 def test_iter_dir_absolute_path(self):
     ps = PanScanner()
     directory = get_absolute_path('test_dir')
     self.assertEqual(
         [v for v in ps.iter_dir(directory)],
         [get_absolute_path('test_dir/binary.png'),
          get_absolute_path('test_dir/without.py'),
          get_absolute_path('test_dir/deeper/contains.log')])
Esempio n. 4
0
 def test_iter_dir_absolute_path(self):
     ps = PanScanner()
     directory = get_absolute_path('test_dir')
     self.assertEqual([v for v in ps.iter_dir(directory)], [
         get_absolute_path('test_dir/binary.png'),
         get_absolute_path('test_dir/without.py'),
         get_absolute_path('test_dir/deeper/contains.log')
     ])
Esempio n. 5
0
    def test_search_file_binary(self):
        searched_lines = []
        ps = PanScanner()
        ps.search_string = lambda l: searched_lines.append(l)

        filename = get_absolute_path('test_dir/binary.png')
        ps.search_file(filename)
        self.assertEqual(searched_lines, [])
        self.assertEqual(len(ps.failed_to_open), 0)
Esempio n. 6
0
 def test_search_string_two_match(self):
     ps = PanScanner()
     matches = ps.search_string('there is one match: 4111111111111111'
                                'no two matches (!): 4111111111111111')
     self.assertEqual(len(matches), 2)
     self.assertEqual(matches[0].span(), (20, 36))
     self.assertEqual(matches[1].span(), (56, 72))
     self.assertEqual(matches[0].group(0), '4111111111111111')
     self.assertEqual(matches[1].group(0), '4111111111111111')
Esempio n. 7
0
 def test_search_string_two_match(self):
     ps = PanScanner()
     matches = ps.search_string('there is one match: 4111111111111111'
                                'no two matches (!): 4111111111111111')
     self.assertEqual(len(matches), 2)
     self.assertEqual(matches[0].span(), (20, 36))
     self.assertEqual(matches[1].span(), (56, 72))
     self.assertEqual(matches[0].group(0), '4111111111111111')
     self.assertEqual(matches[1].group(0), '4111111111111111')
Esempio n. 8
0
    def test_search_file_binary(self):
        searched_lines = []
        ps = PanScanner()
        ps.search_string = lambda l: searched_lines.append(l)

        filename = get_absolute_path('test_dir/binary.png')
        ps.search_file(filename)
        self.assertEqual(searched_lines, [])
        self.assertEqual(len(ps.failed_to_open), 0)
Esempio n. 9
0
 def test_search_file_text(self):
     ps = PanScanner()
     filename = get_absolute_path('test_dir/deeper/contains.log')
     ps.search_file(filename)
     self.assertEqual(ps._log, [
         'Found card number in %s:\n' % filename,
         '* Card number found at line 1 in interval: (28, 44)\n',
         '* Card number found at line 2 in interval: (16, 32), (57, 73)\n'
     ])
     self.assertEqual(len(ps.failed_to_open), 0)
Esempio n. 10
0
 def test_search(self):
     directory = get_absolute_path('test_dir')
     ps = PanScanner([directory])
     ps.search()
     self.assertEqual(ps._log, [
         'Found card number in %s:\n' %
         get_absolute_path('test_dir/deeper/contains.log'),
         '* Card number found at line 1 in interval: (28, 44)\n',
         '* Card number found at line 2 in interval: (16, 32), (57, 73)\n'
     ])
Esempio n. 11
0
 def test_search_file_text(self):
     ps = PanScanner()
     filename = get_absolute_path('test_dir/deeper/contains.log')
     ps.search_file(filename)
     self.assertEqual(ps._log, [
         'Found card number in %s:\n' % filename,
         '* Card number found at line 1 in interval: (28, 44)\n',
         '* Card number found at line 2 in interval: (16, 32), (57, 73)\n'
     ])
     self.assertEqual(len(ps.failed_to_open), 0)
Esempio n. 12
0
 def test_search(self):
     directory = get_absolute_path('test_dir')
     ps = PanScanner([directory])
     ps.search()
     self.assertEqual(ps._log, [
         'Found card number in %s:\n' %
         get_absolute_path('test_dir/deeper/contains.log'),
         '* Card number found at line 1 in interval: (28, 44)\n',
         '* Card number found at line 2 in interval: (16, 32), (57, 73)\n'
     ])
Esempio n. 13
0
    def test_matches_to_string(self):
        class Match:
            def __init__(self, span):
                self._span = span

            def span(self):
                return self._span
        matches = [Match((1, 2)), Match((10, 11))]
        ps = PanScanner()
        matches_string = ps.matches_to_string(matches)
        self.assertEqual(matches_string, '(1, 2), (10, 11)')
Esempio n. 14
0
    def test_matches_to_string(self):
        class Match:
            def __init__(self, span):
                self._span = span

            def span(self):
                return self._span

        matches = [Match((1, 2)), Match((10, 11))]
        ps = PanScanner()
        matches_string = ps.matches_to_string(matches)
        self.assertEqual(matches_string, '(1, 2), (10, 11)')
Esempio n. 15
0
 def test_search_missing_file(self):
     ps = PanScanner()
     path = get_absolute_path('test_dir/does_not_exist.txt')
     ps.search_file(path)
     self.assertEqual(ps.failed_to_open, [path])
Esempio n. 16
0
 def test_search_string_no_matches(self):
     ps = PanScanner()
     matches = ps.search_string('there is no match :(')
     self.assertEqual(len(matches), 0)
Esempio n. 17
0
 def test_search_string_one_match(self):
     ps = PanScanner()
     matches = ps.search_string('there is one match: 4111111111111111')
     self.assertEqual(len(matches), 1)
     self.assertEqual(matches[0].span(), (20, 36))
     self.assertEqual(matches[0].group(0), '4111111111111111')
Esempio n. 18
0
 def test_search_string_ignore_test_card_numbers(self):
     ps = PanScanner(ignore_test_card_numbers=True)
     matches = ps.search_string('4111111111111111')
     self.assertEqual(len(matches), 0)
     matches = ps.search_string('4716334938933348')
     self.assertEqual(len(matches), 1)
Esempio n. 19
0
 def test_search_string_number_surrounded(self):
     ps = PanScanner()
     matches = ps.search_string('3334111111111111111333')
     self.assertEqual(len(matches), 0)
Esempio n. 20
0
 def test_search_string_letter_surrounded(self):
     ps = PanScanner()
     matches = ps.search_string('asd4111111111111111asd')
     self.assertEqual(len(matches), 1)
     self.assertEqual(matches[0].group(0), '4111111111111111')
Esempio n. 21
0
 def test_search_string_comma_surrounded(self):
     ps = PanScanner()
     matches = ps.search_string(',4111111111111111')
     self.assertEqual(len(matches), 0)
     matches = ps.search_string('4111111111111111,')
     self.assertEqual(len(matches), 0)
Esempio n. 22
0
 def test_search_string_number_surrounded(self):
     ps = PanScanner()
     matches = ps.search_string('3334111111111111111333')
     self.assertEqual(len(matches), 0)
Esempio n. 23
0
 def test_search_string_comma_surrounded(self):
     ps = PanScanner()
     matches = ps.search_string(',4111111111111111')
     self.assertEqual(len(matches), 0)
     matches = ps.search_string('4111111111111111,')
     self.assertEqual(len(matches), 0)
Esempio n. 24
0
 def test_search_string_letter_surrounded(self):
     ps = PanScanner()
     matches = ps.search_string('asd4111111111111111asd')
     self.assertEqual(len(matches), 1)
     self.assertEqual(matches[0].group(0), '4111111111111111')
Esempio n. 25
0
 def test_search_string_no_matches(self):
     ps = PanScanner()
     matches = ps.search_string('there is no match :(')
     self.assertEqual(len(matches), 0)
Esempio n. 26
0
 def test_search_string_one_match(self):
     ps = PanScanner()
     matches = ps.search_string('there is one match: 4111111111111111')
     self.assertEqual(len(matches), 1)
     self.assertEqual(matches[0].span(), (20, 36))
     self.assertEqual(matches[0].group(0), '4111111111111111')
Esempio n. 27
0
 def test_log_failed_to_open_none(self):
     ps = PanScanner()
     ps.failed_to_open = []
     ps.log_failed_to_open()
     self.assertEqual(len(ps._log), 0)
Esempio n. 28
0
 def test_log_failed_to_open_none(self):
     ps = PanScanner()
     ps.failed_to_open = []
     ps.log_failed_to_open()
     self.assertEqual(len(ps._log), 0)
Esempio n. 29
0
 def test_search_string_ignore_test_card_numbers(self):
     ps = PanScanner(ignore_test_card_numbers=True)
     matches = ps.search_string('4111111111111111')
     self.assertEqual(len(matches), 0)
     matches = ps.search_string('4716334938933348')
     self.assertEqual(len(matches), 1)
Esempio n. 30
0
 def test_search_missing_file(self):
     ps = PanScanner()
     path = get_absolute_path('test_dir/does_not_exist.txt')
     ps.search_file(path)
     self.assertEqual(ps.failed_to_open, [path])
Esempio n. 31
0
 def test_log_failed_to_open_one(self):
     ps = PanScanner()
     ps.failed_to_open = ['/testfile.txt']
     ps.log_failed_to_open()
     self.assertEqual(ps._log, ["Failed to open:\n* /testfile.txt\n"])
Esempio n. 32
0
 def test_log_failed_to_open_one(self):
     ps = PanScanner()
     ps.failed_to_open = ['/testfile.txt']
     ps.log_failed_to_open()
     self.assertEqual(ps._log, ["Failed to open:\n* /testfile.txt\n"])