Exemplo n.º 1
0
 def get_quiz(quiz_id):
     sql = "Select * from quizzes where id=%s"
     cursor = connection.cursor()
     cursor.execute(sql, [quiz_id])
     record = cursor.fetchone()
     quiz = Quizzes(id=record[0], name=record[1], course_id=record[2])
     quiz.questions = QuestionDaoImpl.get_all_questions_for_quiz(quiz.id)
     return quiz
Exemplo n.º 2
0
    def get_all_quizzes_for_course(course_id):
        sql = "Select * from quizzes where course_id=%s"
        cursor = connection.cursor()
        cursor.execute(sql, [course_id])
        records = cursor.fetchall()
        quizzes = []

        for record in records:
            quiz = Quizzes(id=record[0], name=record[1], course_id=record[2])
            quiz.questions = QuestionDaoImpl.get_all_questions_for_quiz(
                quiz.id)
            quizzes.append(quiz)
        return quizzes
Exemplo n.º 3
0
    def get_all_reviews_for_course_for_student(course_id, student_id):
        sql = "Select * from quizzes where course_id=%s"
        cursor = connection.cursor()
        cursor.execute(sql, [course_id])
        records = cursor.fetchall()
        quizzes = []

        for record in records:
            quiz = Quizzes(id=record[0], name=record[1], course_id=record[2])
            review = QuizzesDaoImpl.get_quiz_review(quiz.id, student_id)
            if review.grade is None:
                continue
            quizzes.append(review)
        return quizzes
Exemplo n.º 4
0
 def submit_quiz(student_id):
     quiz = Quizzes.json_parse(request.json)
     return jsonify(QuizService.submit_quiz(quiz, student_id))
Exemplo n.º 5
0
 def create_quiz():
     quiz = Quizzes.json_parse(request.json)
     if QuizService.create_quiz(quiz):
         return "You did it!", 200
     else:
         return "Oops"
Exemplo n.º 6
0
from unittest.mock import MagicMock

from models.questions import Questions
from daos.questions_dao import QuestionsDAO
from daos.daos_impl.questions_dao_impl import QuestionDaoImpl
from service.questions_services import QuestionsServices

from models.quizzes import Quizzes
from daos.quizzes_dao import QuizesDAO
from daos.daos_impl.quizzes_dao_impl import QuizzesDaoImpl
from service.quiz_service import QuizService

question = Questions(1, 1, 'What is the speed of light?')
question2 = Questions(0, 'What is a test')
questions = [question, question2]
quiz = Quizzes(1, 'Light Quiz', 1)

mock_question_dao = QuestionDaoImpl()
mock_question_dao.get_all_questions_for_quiz = MagicMock(
    return_value=questions)
mock_quizzes_dao = QuizzesDaoImpl()
mock_quizzes_dao.get_quiz = MagicMock(return_value=quiz)

questions_service = QuestionsServices()


class QuestionsTest(unittest.TestCase):
    def test_service_get_all_questions_for_quiz(self):
        retrieved_question = questions_service.get_all_questions(quiz.id)
        assert all(retrieved_question)
Exemplo n.º 7
0
import unittest
from models.quizzes import Quizzes
from daos.quizzes_dao import QuizesDAO
from daos.daos_impl.quizzes_dao_impl import QuizzesDaoImpl

quizzes_dao = QuizzesDaoImpl()

test_quiz = Quizzes(1, 'Light Quiz', 1)
test_quiz2 = Quizzes(0, 'TEST QUIZ', 0)


class QuizzesTest(unittest.TestCase):

    def test_get_all_quizzes_for_course(self):
        retrieved_quiz = quizzes_dao.get_all_quizzes_for_course(
            test_quiz.course_id)
        assert all(retrieved_quiz)

    def test_get_quiz(self):
        retrieved_quiz = quizzes_dao.get_quiz(test_quiz.id)
        assert test_quiz.name == retrieved_quiz.name

    def test_create_quiz(self):
        new_quiz = quizzes_dao.create_quiz(test_quiz2)
        assert new_quiz == True
Exemplo n.º 8
0
import unittest
from unittest.mock import MagicMock
from models.quizzes import Quizzes
from daos.quizzes_dao import QuizesDAO
from daos.daos_impl.quizzes_dao_impl import QuizzesDaoImpl
from service.quiz_service import QuizService

quiz1 = Quizzes(1, 'Light Quiz', 1)
quiz2 = Quizzes(0, 'TEST QUIZ', 0)

quizzes = [quiz1, quiz2]

mock_quiz_dao = QuizzesDaoImpl()
mock_quiz_dao.get_all_quizzes_for_course = MagicMock(
    return_value=quizzes)
quiz_service = QuizService()


class QuizzesTest(unittest.TestCase):

    def test_service_get_all_quizzes_for_course(self):
        retrieved_quiz = quiz_service.get_all_quizzes_for_course(
            quiz1.course_id)
        assert all(retrieved_quiz)

    def test_service_get_quiz(self):
        retrieved_quiz = quiz_service.get_quiz(quiz1.id)
        print(retrieved_quiz)
        assert all(retrieved_quiz)

    def test_service_create_quiz(self):