예제 #1
0
def game():
    global online
    global leader_board

    idType = id_type()

    if 'username' in session:
        user = session.get('username')

        if user in my_users:

            del my_users[user]['username']
            my_users[user] = set_up_new_user(user)

            if not user in online:
                online = add_user_online(my_users, user, online)
            else:
                online = remove_user_online(user, online)
                online = add_user_online(my_users, user, online)

            leader_board = get_leaderboard(my_users, leader_board)

            socketio.emit('in_out_game', {'data': online})
            socketio.emit('leaders', {'data': leader_board})

            return render_template('game.html',
                                   username=user,
                                   type_id=idType,
                                   on_line=online,
                                   leader=leader_board[:3])
        else:
            user = session.get('username')
            my_users[user] = set_up_new_user(user)

            if not user in online:
                online = add_user_online(my_users, user, online)

            else:
                online = remove_user_online(user, online)
                online = add_user_online(my_users, user, online)

            leader_board = get_leaderboard(my_users, leader_board)

            socketio.emit('in_out_game', {'data': online})
            socketio.emit('leaders', {'data': leader_board})

            return render_template('game.html',
                                   username=user,
                                   type_id=idType,
                                   on_line=online,
                                   leader=leader_board[:3])
    else:
        return redirect(url_for('index'))
예제 #2
0
    def test_key_answered_and_wrong_are_lists(self):
        '''Test to ensure key values answered and wrong are of type list'''

        user = '******'
        new_user = set_up_new_user(user)

        self.assertTrue(type(new_user['answered']) is list)
        self.assertTrue(type(new_user['wrong']) is list)
예제 #3
0
    def test_has_key_answered_and_wrong_score(self):
        '''Test to see it has key answered and wrong score'''

        user = '******'
        new_user = set_up_new_user(user)

        self.assertIn('answered', new_user)
        self.assertIn('wrong', new_user)
        self.assertIn('score', new_user)
        self.assertIn('game-over', new_user)
예제 #4
0
def questions():
    socketio.emit('leaders', {'data': leader_board})
    if 'username' in session:
        if session.get('username') not in my_users:
            user = session.get('username')
            my_users[user] = set_up_new_user(user)

        if request.method == 'POST':
            data = request.get_json()

            my_quest = get_question(data['quest_id'])

            my_users[session.get('username')]['answered'].append(
                data['quest_id'])

            return jsonify(my_quest)
        else:
            return redirect(url_for('index'))
예제 #5
0
def index():
    session.permanent = True
    username = ''

    if 'username' in session:
        username = session.get('username')

    if request.method == 'POST':
        username = request.form['username']

        if 'username' in session:
            if session.get('username') == username:
                return redirect(url_for('game'))
        else:
            session['username'] = username
            my_users[username] = set_up_new_user(username)

            return redirect(url_for('game'))

    return render_template('index.html',
                           username=username,
                           url=config.SECRET_CONFIG['url'])
예제 #6
0
    def test_returns_dict_length_4(self):
        '''Test to check the size of dict returned is 4'''

        user = '******'
        new_user = set_up_new_user(user)
        self.assertEqual(len(new_user), 5)
예제 #7
0
    def test_it_sets_username_to_user(self):
        ''' Test to ensure user passed to function is the value for key username'''

        user = '******'
        users = set_up_new_user(user)
        self.assertEqual(users['username'], 'John_L3')
예제 #8
0
    def test_returns_a_dictionary(self):
        '''Test is to ensure we return a dictionary'''

        user = '******'
        users = set_up_new_user(user)
        self.assertTrue(type(users) is dict)