Example #1
0
    def test_listener_calls_callback_when_message_matches(self):
        match = mock.Mock()
        match.return_value = True
        callback = mock.Mock()
        listener = JobCompleteListener(match, callback)
        message = mock.Mock()
        message.message.return_value = 'test message'

        listener.message(None, message)
        match.assert_called_with(message.message)
        self.assertEqual(callback.call_count, 1)
Example #2
0
    def test_listener_does_not_call_callback(self):
        match = mock.Mock()
        match.return_value = False
        callback = mock.Mock()
        listener = JobCompleteListener(match, callback)
        message = mock.Mock()
        message.message.return_value = 'test message'

        listener.message(None, message)
        match.assert_called_with(message.message)
        self.assertEqual(callback.call_count, 0)
Example #3
0
def setup_listener_status_mocks(status_category):
    match = mock.Mock()
    callback = mock.Mock()
    disconnect = mock.Mock()
    listener = JobCompleteListener(match, callback, disconnect)
    status = mock.Mock()
    status.category = status_category
    return match, callback, disconnect, listener, status