Esempio n. 1
0
    def test_connect_event(self, current_user):
        self.login()

        socketio_client = socketio.test_client(current_app)
        received = socketio_client.get_received()
        self.assertEqual(received[0]['name'], 'user count')
        self.assertEqual(received[0]['args'][0]['count'], 1)
        socketio_client.disconnect()
Esempio n. 2
0
    def test_new_anonymous_message_event(self, current_user):
        current_user.return_value = User.query.get(1)

        self.assertEqual(User.query.get(1).messages, [])
        self.login()
        socketio_client = socketio.test_client(current_app, namespace='/anonymous')
        socketio_client.get_received('/anonymous')
        socketio_client.emit('new message', 'Hello, Anonymous', namespace='/anonymous')
        received = socketio_client.get_received('/anonymous')
        self.assertEqual(received[0]['name'], 'new message')
        self.assertEqual(received[0]['args'][0]['message_body'], '<p>Hello, Anonymous</p>')
        self.assertEqual(User.query.get(1).messages, [])

        socketio_client.disconnect(namespace='/anonymous')
Esempio n. 3
0
    def test_new_message_event(self, current_user):
        current_user.return_value = User.query.get(1)

        self.assertEqual(User.query.get(1).messages, [])
        self.login()

        socketio_client = socketio.test_client(current_app)
        socketio_client.get_received()
        socketio_client.emit('new message', 'Hello, Test')
        received = socketio_client.get_received()
        self.assertEqual(received[0]['name'], 'new message')
        self.assertEqual(received[0]['args'][0]['message_body'], '<p>Hello, Test</p>')
        self.assertNotEqual(User.query.get(1).messages, [])
        self.assertEqual(User.query.get(1).messages[0].body, '<p>Hello, Test</p>')

        response = self.client.get(url_for('chat.home'))
        data = response.get_data(as_text=True)
        self.assertIn('Hello, Test', data)

        socketio_client.disconnect()