class PciFormatterTests(TestCase): def setUp(self): self.formatter = PciFormatter() def test_a_basic_string_is_unchanged(self): msg = 'some string' record = self.create_log_record(msg) self.assertEquals(msg, self.formatter.format(record)) bankcard_strings = lambda: [ ('here is my bankcard 1000010000000007', 'here is my bankcard XXXX-XXXX-XXXX-XXXX'), ('here is my bankcard 1000-0100-0000-0007', 'here is my bankcard XXXX-XXXX-XXXX-XXXX'), ('here is my bankcard 1000 0100 0000 0007', 'here is my bankcard XXXX-XXXX-XXXX-XXXX'), ('here is my bankcard 10 00 01-00 0-000-0007', 'here is my bankcard XXXX-XXXX-XXXX-XXXX'), ] @dataProvider(bankcard_strings) def test_a_sensitive_strings_are_filtered(self, sensitive, filtered): record = self.create_log_record(sensitive) self.assertEquals(filtered, self.formatter.format(record)) def create_log_record(self, msg): return LogRecord(name=None, level=None, pathname='', lineno=0, msg=msg, args=None, exc_info=None)
class PciFormatterTests(TestCase): def setUp(self): self.formatter = PciFormatter() def test_a_basic_string_is_unchanged(self): msg = 'some string' record = self.create_log_record(msg) self.assertEquals(msg, self.formatter.format(record)) bankcard_strings = lambda: [('here is my bankcard 1000010000000007', 'here is my bankcard XXXX-XXXX-XXXX-XXXX'), ('here is my bankcard 1000-0100-0000-0007', 'here is my bankcard XXXX-XXXX-XXXX-XXXX'), ('here is my bankcard 1000 0100 0000 0007', 'here is my bankcard XXXX-XXXX-XXXX-XXXX'), ('here is my bankcard 10 00 01-00 0-000-0007', 'here is my bankcard XXXX-XXXX-XXXX-XXXX'), ] @dataProvider(bankcard_strings) def test_a_sensitive_strings_are_filtered(self, sensitive, filtered): record = self.create_log_record(sensitive) self.assertEquals(filtered, self.formatter.format(record)) def create_log_record(self, msg): return LogRecord(name=None, level=None, pathname='', lineno=0, msg=msg, args=None, exc_info=None)
def test_pci_formatter(self): """PCI logging formatter """ for string, expected in self.data: formatter = PciFormatter() record = LogRecord( name=None, level=None, pathname='', lineno=0, msg=string, args=None, exc_info=None) self.assertEqual(formatter.format(record), expected)
def assert_message_filtered_correctly(string, expected): formatter = PciFormatter() record = LogRecord(name=None, level=None, pathname='', lineno=0, msg=string, args=None, exc_info=None) assert formatter.format(record) == expected
def setUp(self): self.formatter = PciFormatter()
def assert_message_filtered_correctly(string, expected): formatter = PciFormatter() record = LogRecord( name=None, level=None, pathname='', lineno=0, msg=string, args=None, exc_info=None) nose.tools.eq_(formatter.format(record), expected)