def test_autocomplete(db, socket): UserFactory(display='t_one_t') UserFactory(display='name') UserFactory(display='some_one') svc = UserService(db, socket) users = svc.execute('autocomplete', {'query': 'one'}) assert len(users) == 2
def test_profile(db, socket): user = UserFactory(is_online=True) svc = UserService(db, socket) profile = svc.execute('profile', {'user_id': user.id}) assert profile.get('id') == user.id assert profile.get('last_activity_at') == user.last_activity_at.isoformat() assert profile.get('is_online') == user.is_online assert profile.get('rating') == user.rating assert profile.get('display') == user.display assert profile.get('info_text_html') == user.info_text_html
def _finish_game(self, game): if game.is_demo or game.stage != 'finished': return if game.board.moves_played <= game.board.size: game.result = 'aborted' if game.is_ranked: RatingService(self.db).update_ratings(game) self.socket.publish('game_finished', game.to_frontend()) self._publish_game_data(game) UserService(self.db, self.socket, game.black_user).publish_status() UserService(self.db, self.socket, game.white_user).publish_status() if game.is_correspondence: CorrespondenceService(self.db, self.socket).notify_game_finished(game)
def disconnect(self): self._delete_connection() self._check_is_online() if self.user: self.db.query(Automatch).filter((Automatch.user == self.user) & ( Automatch.preset != 'correspondence')).delete() UserService(self.db, self.socket, self.user).publish_status() RoomService(self.db, self.socket, self.user).publish_user_rooms() GameService(self.db, self.socket, self.user).publish_demos()
def connect(self): self.socket.send('connection_data', self._connection_data()) self.socket.subscribe('game_started') self.socket.subscribe('game_finished') self.socket.subscribe('user_status') if self.user: self.socket.subscribe('direct_message/' + str(self.user.id)) self.socket.subscribe('automatch_status/' + str(self.user.id)) self.socket.subscribe('challenges/' + str(self.user.id)) self._join_open_rooms_and_games() self._insert_connection() self._check_is_online() UserService(self.db, self.socket, self.user).publish_status() RoomService(self.db, self.socket, self.user).publish_user_rooms() GameService(self.db, self.socket, self.user).publish_demos()