def test_leave_room(db, socket): user = UserFactory() room = RoomFactory() svc = RoomService(db, socket, user) svc.join_room(room.id) svc.leave_room(room.id) assert db.query(RoomUser).count() == 0
def test_join_room(db, socket): user = UserFactory() room = RoomFactory() svc = RoomService(db, socket, user) socket.subscribe('room_user/' + str(room.id)) svc.join_room(room.id) assert db.query(RoomUser).count() == 1 ru = db.query(RoomUser).first() assert ru.room == room assert ru.user == user assert len(socket.sent_messages) == 1 assert socket.sent_messages[0]['method'] == 'room_user' assert socket.sent_messages[0]['data']['user_id'] == user.id assert socket.sent_messages[0]['data']['user_display'] == user.display assert socket.sent_messages[0]['data']['user_rating'] == user.rating
def test_users_max(db, socket): room = RoomFactory() svc = RoomService(db, socket, UserFactory()) svc.join_room(room.id) assert room.users_max == 1 svc = RoomService(db, socket, UserFactory()) svc.join_room(room.id) assert room.users_max == 2 svc.leave_room(room.id) assert room.users_max == 2 svc = RoomService(db, socket, UserFactory(is_online=False)) svc.join_room(room.id) assert room.users_max == 2