def test_wrong_token_causes_incorrect_token_event(self):
        socket = Socket()
        error = {}

        def connect():
            socket.introduce_yourself('dummy token')

        socket.on_connect(connect)

        def on_incorrect_token(data):
            error['message'] = data['message']
            socket.disconnect()

        socket.on('incorrect_token', on_incorrect_token)

        socket.connect()

        self.assertEqual('Incorrect token', error['message'])
    def test_correct_token_causes_authorized_event(self):
        socket = Socket()
        result = {'event_emmited': False}
        token = api.post_user({
            'username': '******'
        }).json()['token']

        def connect():
            socket.introduce_yourself(token)

        socket.on_connect(connect)

        def on_authorized(data):
            result['event_emmited'] = True
            socket.disconnect()

        socket.on('authorized', on_authorized)

        socket.connect()

        self.assertTrue(result['event_emmited'])