Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
    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)
Example #8
0
    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)
Example #9
0
    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)
Example #10
0
 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)
Example #11
0
 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)