Exemple #1
0
    def test_integration(self):
        """
        Simple integration testing.

        Start one thread for the server, then sends a message to it and checks
        that the callback was correctly installed.
        """
        TARGET = ('localhost', 9999)
        callbacks = {'foo': Mock(), 'bar': Mock()}
        default_cb = Mock()

        # Creates the server
        RequestHandler = message.create_request_handler(callbacks, default_cb)
        server = socketserver.UDPServer(TARGET, RequestHandler)

        # Starts the server in another thread
        server_thread = threading.Thread(target=server.serve_forever)
        server_thread.start()

        # Sends the messages
        message.send(TARGET, 'foo', [1, 2, 3])
        message.send(TARGET, 'bar')
        message.send(TARGET, 'other')

        # Terminates the server thread
        server.shutdown()

        # Checks that the callbacks were called
        callbacks['foo'].assert_any_call([1, 2, 3])
        callbacks['bar'].assert_any_call(None)
        default_cb.assert_called_once_with('other', None)
Exemple #2
0
 def test_socket_is_closed(self, socket):
     socket.return_value = Mock()
     message.send(('localhost', 1234), 'foo', [1, 2, 3])
     socket.return_value.close.assert_any_call()