def create_quizzes(self):
     """
     Generate the quizzes that the students will take, including subject and difficulty
     """
     quiz = Quiz()
     self.quizzes = quiz.generate_quiz()
     print('\033[44m' + '***********QUIZZeS*************' + '\033[0m')
     pprint(self.quizzes)
Esempio n. 2
0
    def test_assign_quiz_to_student(self):
        self.student = Student(name='ramadan')
        self.quiz1 = Quiz()
        self.quiz2 = Quiz()

        self.assertEqual([], self.student.quizzes)

        Teacher.assign_quiz_to_student(self.student, self.quiz1)
        self.assertEqual([self.quiz1], self.student.quizzes)

        Teacher.assign_quiz_to_student(self.student, self.quiz2)
        self.assertEqual([self.quiz1, self.quiz2], self.student.quizzes)
Esempio n. 3
0
def create_quiz(user):
    """
    Description: Create, play the quiz and save user and high score info

    Parameters:
        user: The user playing the quiz

    """
    # Ask the user to choose a category
    cat = choose_category()
    # Ask the user to choose the question difficulty
    diff = choose_difficulty()
    # Create the questions and answers based on user requested category/difficulty
    questions, answers = create_questions(cat, diff)

    # Tell the user their previous scores and number of attempts at this category/difficulty
    print("\nYou've had {} attempts at this category/difficulty and your current high score is {}\n" \
          .format(user.get_plays(cat, diff), user.get_high_score(cat, diff)))
    # Create a Quiz object by passing in the questions and answers to play
    quiz = Quiz(questions, answers)
    # Play the quiz
    quiz.play()
    # Increment the number of play counts for the user for the category/difficulty level
    user.add_play(cat, diff)
    # Check and add any user high score updates for the category/difficulty level
    user.add_high_score(cat, diff, quiz.score)

    # Load the all time high score table
    scores = load_highscores()

    if not scores:
        # No all time high scores yet created, so create one
        scores = HighScores()

    # Check and add the score if a new record
    scores.add_high_score(cat, diff, quiz.score, user)

    # Save the high score table
    save_highscores(scores)

    # Update user plays and high score info
    update_user(user)
Esempio n. 4
0
def new_quiz():
	if not session.get('logged_in'):
		return redirect(url_for('login'))

	courseID = int(request.args.get('courseID'))
	db = get_db()	
	course = Course.getCourseFromDB(courseID,db)
	sections = course.getSections(db)
	questions = course.getQuestions(db)

	if request.method == 'POST':
		if request.form['action'] == 'save':
			title = request.form['title']
			description = request.form['description']
			sectionIds = request.form.getlist('section')
			questionIds = request.form.getlist('question')
			Quiz.newQuiz(title, description, sectionIds, questionIds, db)
			flash("Quiz saved!")
		return redirect(url_for('show_quizzes', courseID=courseID))

	return render_template('new_quiz.html', courseID = courseID, sections = sections, questions = questions)
Esempio n. 5
0
def create_quiz(class_id):
    if request.method == "POST":
        db = current_app.config["db"]
        form_quiz_title = request.form["title"]
        form_quiz_time = request.form["time"]
        new_quiz = Quiz(" ", form_quiz_title, form_quiz_time, class_id)
        quiz_id = db.add_quiz(new_quiz)
        quest_id = 1
        form_question = request.form["question"]
        form_A = request.form["A"]
        form_B = request.form["B"]
        form_C = request.form["C"]
        form_D = request.form["D"]
        correct = request.form["correct"]
        new_question = Question(quest_id, quiz_id, form_question, form_A,
                                form_B, form_C, form_D, correct)
        db.add_question_into_quiz(quiz_id, new_question)

        i = 1
        while True:
            i += 1
            quest_id += 1
            if f"question-{i}" not in request.form:
                break
            form_question = request.form[f"question-{i}"]
            form_A = request.form[f"A-{i}"]
            form_B = request.form[f"B-{i}"]
            form_C = request.form[f"C-{i}"]
            form_D = request.form[f"D-{i}"]
            correct = request.form[f"correct-{i}"]
            new_question = Question(quest_id, quiz_id, form_question, form_A,
                                    form_B, form_C, form_D, correct)
            db.add_question_into_quiz(quiz_id, new_question)

        return redirect(
            url_for("main_quizzes", class_id=class_id, quiz_key=quiz_id))
    else:
        return render_template("create_quiz.html", class_id=class_id)
Esempio n. 6
0
def edit_quiz():
	if not session.get('logged_in'):
		return redirect(url_for('login'))

	courseID = int(request.args.get('courseID'))
	quizID = int(request.args.get('quizID'))
	db = get_db()
	quiz = Quiz.getQuizFromDB(quizID,db)
	course = Course.getCourseFromDB(courseID,db)
	sections = course.getSections(db)
	questions = course.getQuestions(db)

	if request.method == 'POST':
		if request.form['action'] == 'save':
			quiz.title = request.form['title']
			quiz.description = request.form['description']
			sectionIds = request.form.getlist('section')
			questionIds = request.form.getlist('question')
			quiz.saveChanges(sectionIds, questionIds, db)
			flash("Quiz saved!")
		return redirect(url_for('show_quizzes', courseID=courseID))
	else:
		selectedSecIds = quiz.getSectionIds(db)
		for section in sections:
			section.check = 0
			for secId in selectedSecIds:
				if section.id == secId:
					section.check = 1

		selectedQIds = quiz.getQuestionIds(db)
		for question in questions:
			question.check = 0
			for qId in selectedQIds:
				if question.id == qId:
					question.check = 1

	return render_template('edit_quiz.html', courseID = courseID, quiz = quiz, sections = sections, questions = questions)
Esempio n. 7
0
 def setUp(self):
     self.student = Student(name='ramadan')
     self.quiz = Quiz()
Esempio n. 8
0
 def setUp(self):
     self.quiz = Quiz()
     self.question1 = Question('question_text', ['ch1', 'ch2'], 'sol')
     self.question2 = Question('question_text', ['ch1', 'ch2'], 'sol')
     self.question3 = Question('question_text', ['ch1', 'ch2'], 'sol')
Esempio n. 9
0
class TestQuiz(TestCase):
    def setUp(self):
        self.quiz = Quiz()
        self.question1 = Question('question_text', ['ch1', 'ch2'], 'sol')
        self.question2 = Question('question_text', ['ch1', 'ch2'], 'sol')
        self.question3 = Question('question_text', ['ch1', 'ch2'], 'sol')

    def test_created(self):
        self.assertEqual([], self.quiz.questions)

    def test_add_question(self):
        self.assertEqual([], self.quiz.questions)

        self.quiz.add_question(self.question1)
        self.assertEqual([self.question1], self.quiz.questions)

        self.quiz.add_question(self.question2)
        self.assertEqual([self.question1, self.question2], self.quiz.questions)

        self.quiz.add_question(self.question3)
        self.assertEqual([self.question1, self.question2, self.question3],
                         self.quiz.questions)

    def test_get_grade(self):
        # no questions
        self.assertEqual(0, self.quiz.get_grade())

        self.question1.student_solution = 'sol'
        self.question2.student_solution = 'sol'
        self.question3.student_solution = 'sol'
        self.quiz.questions.append(self.question1)
        self.quiz.questions.append(self.question2)
        self.quiz.questions.append(self.question3)
        self.assertEqual(3, self.quiz.get_grade())

        self.question1.student_solution = 'ch1'
        self.assertEqual(2, self.quiz.get_grade())

        self.question2.student_solution = 'ch1'
        self.assertEqual(1, self.quiz.get_grade())

        self.question3.student_solution = 'ch1'
        self.assertEqual(0, self.quiz.get_grade())

    @patch('classes.Question.solve', autospec=True)
    def test_solve_question(self, solve):
        # no quizzes
        self.assertFalse(self.quiz.solve_question('', ''))

        self.quiz.questions.append(self.question1)

        # wrong quiz id
        self.assertFalse(self.quiz.solve_question('', ''))
        self.assertFalse(solve.called)

        # correct quiz id
        self.assertTrue(self.quiz.solve_question(self.question1.id,
                                                 'solution'))
        solve.assert_called_with(self.question1, 'solution')