def test_remove_filter_removes_a_registered_filter(self): filter = Filter() filterer = Filterer() filterer.add_filter(filter) filterer.remove_filter(filter) self.assertEqual(filterer.filters, [])
def test_remove_filter_doesnt_raises_an_error_if_filter_not_in_filters( self): filter = Filter() filterer = Filterer() try: filterer.remove_filter(filter) except Exception as e: self.fail(f"Shouldn't raise an error. Error: {e}")
def test_add_filter_adds_filter_only_once(self): filter = Filter() filterer = Filterer() filterer.add_filter(filter) self.assertEqual(filterer.filters, [filter]) filterer.add_filter(filter) self.assertEqual(filterer.filters, [filter])
def test_filter_allows_any_records_if_filter_name_isnt_provided(self): filter = Filter() log_record = make_log_record(name="name doesn't matter") self.assertTrue(filter(log_record)) log_record = make_log_record(name="A.B") self.assertTrue(filter(log_record)) log_record = make_log_record(name="A.B.C.D") self.assertTrue(filter(log_record))
def test_filter_allows_records_with_name_equal_to_filter_name(self): filter = Filter("A.B.C") log_record = make_log_record(name="A.B.C") self.assertTrue(filter(log_record))
def test_it_disallows_records_with_name_not_starting_with_filter_name( self): filter = Filter("A.B") log_record = make_log_record(name="B.A") self.assertFalse(filter(log_record))
def test_filter_disallows_records_with_name_starting_with_filter_name_that_isnt_a_prefix( self): filter = Filter("A.B") log_record = make_log_record(name="A.BC") self.assertFalse(filter(log_record))