def test_observer_add_url(self): observer1 = Mock() url = URL('http://www.w3af.org/') kb.add_observer(observer1) kb.add_url(url) observer1.add_url.assert_called_once_with(url)
def test_observer_append(self): observer1 = Mock() info = MockInfo() kb.add_observer(observer1) kb.append('a', 'b', info) observer1.append.assert_called_once_with('a', 'b', info, ignore_type=False)
def test_observer_multiple_observers(self): observer1 = Mock() observer2 = Mock() kb.add_observer(None, None, observer1) kb.add_observer(None, None, observer2) kb.raw_write('a', 'b', 1) observer1.assert_called_once_with('a', 'b', 1) observer2.assert_called_once_with('a', 'b', 1)
def test_observer_multiple_observers(self): observer1 = Mock() observer2 = Mock() kb.add_observer(observer1) kb.add_observer(observer2) kb.raw_write('a', 'b', 1) observer1.append.assert_called_once_with('a', 'b', 1, ignore_type=True) observer2.append.assert_called_once_with('a', 'b', 1, ignore_type=True)
def test_observer_update(self): observer1 = Mock() info = MockInfo() kb.add_observer(observer1) kb.append('a', 'b', info) old_info = copy.deepcopy(info) info.set_name('new name') kb.update(old_info, info) observer1.update.assert_called_once_with(old_info, info)
def test_observer_all(self): observer = Mock() kb.add_observer(None, None, observer) kb.raw_write('a', 'b', 1) observer.assert_called_once_with('a', 'b', 1) observer.reset_mock() i = MockInfo() kb.append('a', 'c', i) observer.assert_called_with('a', 'c', i)
def test_observer_location_b(self): observer = Mock() kb.add_observer('a', 'b', observer) kb.raw_write('a', 'b', 1) observer.assert_called_once_with('a', 'b', 1) observer.reset_mock() # Shouldn't call the observer kb.raw_write('a', 'xyz', 1) self.assertFalse(observer.called) i = MockInfo() kb.append('a', 'b', i) observer.assert_called_with('a', 'b', i)