def test_for_wrong_answers_players_answers_are_returned(self): '''Wrong answers should return list containg players answer/s''' answer = ['Tuple', 'Set'] result = check_answer('0', answer) self.assertEqual(answer, result[0]['answer'])
def test_valid_return_for_correct_answer(self): '''Ensure a valid answer is not missed if more than one part to answer, even if order or results is mixed''' result = check_answer('0', ['Tuple', 'List', 'Set', 'Dictionary']) self.assertEqual(result[0]['result'], 'correct')
def answer(): global online global leader_board if request.method == 'POST': data = request.get_json() user = session.get('username') result = check_answer(data['questionId'], data['answer']) if result[0]['result'] == 'correct': online = update_user_online(user, online) my_users[session.get('username')]['score'] = my_users[session.get( 'username')]['score'] + 1 else: my_users[user]['wrong'].append( [result[0]['id'], result[0]['answer']]) socketio.emit('in_out_game', {'data': online}) score = my_users[user]['score'] socketio.emit('my_score', {'score': score, 'user': user}) answered_count = len(my_users[user]['answered']) if answered_count == 12: my_users[user]['game-over'] = True leader_board = get_leaderboard(my_users, leader_board) socketio.emit('leaders', {'data': leader_board}) data = {'msg': result, 'game-over': True} return jsonify(data) else: data = {'msg': result} return jsonify(data) else: return redirect(url_for('index'))
def test_id_passed_to_function(self): '''ensure id passed to function returns a list''' result = check_answer('0', ['Dictionary', 'List', 'Set', 'Tuple']) self.assertTrue(type(result) == list)
def test_valid_length_of_answer_but_wrong_answer(self): '''Ensure for multiple parts to answer if any are wrong it is picked up''' result = check_answer('0', ['Tuple', 'Set', 'Dictionary', 'array']) self.assertEqual(result[0]['result'], 'You answered wrong')
def test_valid_return_for_incorrect_answer(self): '''Ensure a wrong answer if picked up''' result = check_answer('0', ['Tuple', 'Set', 'Dictionary']) self.assertEqual(result[0]['result'], 'You answered wrong')