Exemplo n.º 1
0
 def test_chat_loads_with_recent_messages(self):
     client1 = socketio.test_client(app)
     client1.emit('chat_message', {'msg': 'Hello Room'})
     client2 = socketio.test_client(app)
     received = client2.get_received()
     recent_messages_msg = self.get_relevant('recent_messages', received)
     self.assertEqual(recent_messages_msg['name'], 'recent_messages')
Exemplo n.º 2
0
    def test_broadcast_message_when_user_joins(self):
        client1 = socketio.test_client(app)
        client1.get_received()
        client2 = socketio.test_client(app)

        received = client1.get_received()
        user_joined_msg = self.get_relevant('user_joined', received)
        assert user_joined_msg is not None

        client1.disconnect()
        client2.disconnect()
Exemplo n.º 3
0
    def test_messages_are_broadcasted(self):
        client1 = socketio.test_client(app)
        client2 = socketio.test_client(app)
        client1.get_received()
        client2.get_received()

        client1.emit('chat_message', { 'msg': "test message" })
        received1 = self.get_relevant('chat_message', client1.get_received())
        received2 = self.get_relevant('chat_message', client2.get_received())
        self.assertEqual(received1['args'][0]['msg'], "test message")
        self.assertEqual(received2['args'][0]['msg'], "test message")

        client1.disconnect()
        client2.disconnect()
Exemplo n.º 4
0
    def test_active_users_sent_on_connect(self):
        client = socketio.test_client(app)

        received = client.get_received()
        active_users_msg = self.get_relevant('active_users', received)

        assert len(active_users_msg) > 0
        client.disconnect()
Exemplo n.º 5
0
 def test_db_logs_messages(self):
     client = socketio.test_client(app)
     client.emit('chat_message', {'msg': 'Are you logging?'})
     db_msgs = redis_db.zrange('messages:global', 0, 10)
     assert len(db_msgs) == 1
     message_id = db_msgs[0].decode()
     msg_content = redis_db.hget('message:' + message_id, 'msg').decode()
     self.assertEqual(msg_content, 'Are you logging?')
     client.disconnect()
Exemplo n.º 6
0
 def test_personal_room_assigned_on_login(self):
     client = socketio.test_client(app)
     received = client.get_received()
     sid_message = self.get_relevant('testing_sid', received)
     sid = sid_message['args'][0]['sid']
     socketio.emit('test_emission', {}, room=sid)
     received = client.get_received()
     client.disconnect()
     assert self.get_relevant('test_emission', received) is not None
Exemplo n.º 7
0
 def test_asssigned_usernames_are_unique(self):
     names = set([])
     for i in range(5):
         client = socketio.test_client(app)
         received = client.get_received()
         user_joined_msg = self.get_relevant('user_joined', received)
         names.add(user_joined_msg['args'][0])
         session = socketio.server.environ[client.sid]['saved_session']
         client.disconnect()
         session['sid'] = None
     self.assertEqual(len(names), 5)
Exemplo n.º 8
0
 def test_connect(self):
     client = socketio.test_client(app)
     received = client.get_received()
     assert len(received) > 0
     client.disconnect()