Exemplo n.º 1
0
    def get_question_test(cls, self):
        print "Testing DataAccess: get_question"

        question = "Platypuses lay eggs"
        target_question = Question(question, ["true", "false"], 0, "other")

        question_obj = DataAccessTest.data_access.get_question(
            question=question)[0]

        self.assertEquals(target_question.question, question_obj.question)
        self.assertEquals(target_question.options, question_obj.options)
        self.assertEquals(target_question.answer, question_obj.answer)

        question = re.compile("^Platypus")

        question_obj = DataAccessTest.data_access.get_question(
            question=question)[0]

        self.assertEquals(target_question.question, question_obj.question)
        self.assertEquals(target_question.options, question_obj.options)
        self.assertEquals(target_question.answer, question_obj.answer)

        question = re.compile(".*Platypus.*")

        question_obj = DataAccessTest.data_access.get_question(
            question=question)[0]

        self.assertEquals(target_question.question, question_obj.question)
        self.assertEquals(target_question.options, question_obj.options)
        self.assertEquals(target_question.answer, question_obj.answer)
Exemplo n.º 2
0
 def setUp(self):
     self.question = "What's my favorite color?"
     self.options = ["blue", "green", "red"]
     self.category = "other"
     self.answer = 0
     self.question_obj = Question(self.question, self.options, self.answer,
                                  self.category)
Exemplo n.º 3
0
 def test_failure(self):
     print "Testing Question: Invalid Args"
     try:
         Question()
         self.fail("Expected typeError")
     except TypeError:
         pass
Exemplo n.º 4
0
    def get_all_questions(self):
        result = []

        for doc in self.mongo.questions.find():
            DataAccessObject.clean(doc)
            result.append(Question(doc["question"],\
                                   doc["options"],\
                                   doc["answer"],\
                                   doc["category"]))

        return result
    def test_get_question(self):
        print "Testing AccessQuestions: get_question"
        question = "Platypuses lay eggs"
        target_question = Question(question, ["true", "false"], 0, "animals")

        question_obj = self.access_questions.get_question(question=question)[0]

        self.assertEquals(target_question.question, question_obj.question)
        self.assertEquals(target_question.options, question_obj.options)
        self.assertEquals(target_question.answer, question_obj.answer)

        question = re.compile("^Platypus")

        question_obj = self.access_questions.get_question(question=question)[0]

        self.assertEquals(target_question.question, question_obj.question)
        self.assertEquals(target_question.options, question_obj.options)
        self.assertEquals(target_question.answer, question_obj.answer)
Exemplo n.º 6
0
    def get_random_question(self, category=None):
        result = None
        doc = None

        if category is None or category == "all":
            category_filter = {}
            num_qs = self.get_num_questions()
        else:
            category_filter = {"category": category}
            num_qs = self.mongo.questions.count(category_filter)

        rq_num = random.randint(0, num_qs - 1) if num_qs > 0 else 0

        doc_cursor = self.mongo.questions.find(category_filter).skip(rq_num)

        if doc_cursor.count() > 0:
            doc = doc_cursor[0]
            DataAccessObject.clean(doc)
            result = Question(doc["question"], doc["options"], doc["answer"],
                              doc["category"])

        return result
Exemplo n.º 7
0
 def insert_question(self, question, options, answer, category):
     self.questions.append(Question(question, options, answer, category))
     return True