def fixture():
     return [
         ExerciseEvaluation(exercise_id="4d128b6ea794fc13a8000003",
                            user_id="4d128b6ea794fc13a8000002",
                            _id="666f6f2d6261722d71757578",
                            score=123),
         ExerciseEvaluation(exercise_id="507f1f77bcf86cd799439011",
                            user_id="4cdfb11e1f3c000000007822",
                            _id="54759eb3c090d83494e2d804",
                            score=123)
     ]
 def test_incrementExerciseEvaluationAttempts_calledWithExerciseEvaluation_attemptNumberCorrectlyUpdated(
         self):
     exercise_evaluation = self.__create_and_insert_exercise_evaluation_test_instance(
     )
     self.sut.increment_exercise_evaluation_attempts(exercise_evaluation)
     actual = ExerciseEvaluation.from_json(
         self.db.evaluations.find_one({'_id': exercise_evaluation.get_id()
                                       })).get_attempt()
     expected = 2
     self.assertEqual(actual, expected)
 def get_exercise_evaluation(self, user_id, exercise_id):
     query_result = self.db.evaluations.find_one(
         {
             'user_id': ObjectId(user_id),
             'exercise_id': ObjectId(exercise_id)
         }, self.ITEM_REQUIRED_FIELDS)
     if query_result is not None:
         exercise = ExerciseEvaluation.from_json(query_result)
         return exercise
     else:
         return None
 def test_updateExerciseEvaluationAsSolved_calledWithValidParams_exerciseEvaluationCorrectlyUpdated(
         self):
     exercise_evaluation = self.__create_and_insert_exercise_evaluation_test_instance(
     )
     self.sut.update_exercise_evaluation_as_solved(exercise_evaluation, 200)
     exercise_evaluation_returned_from_db = ExerciseEvaluation.from_json(
         self.db.evaluations.find_one({'_id':
                                       exercise_evaluation.get_id()}))
     actual_score = exercise_evaluation_returned_from_db.get_score()
     expected_score = 200
     actual_status = exercise_evaluation_returned_from_db.get_status()
     expected_status = ExerciseEvaluation.STATUS_SOLVED
     self.assertEqual(actual_score, expected_score)
     self.assertEqual(actual_status, expected_status)
示例#5
0
 def get_unsolved_exercises_by_user_id(self, user_id):
     if user_id is None:
         raise ValueError('user id cannot be None')
     exercises_list = self.__exercise_query_repository.get_exercises_list()
     unsolved_exercises_list = []
     for exercise in exercises_list:
         exercise_evaluation = self.__exercise_evaluation_service.get_exercise_evaluation(
             user_id=user_id, exercise_id=exercise.get_id())
         if exercise_evaluation is not None:
             if exercise_evaluation.get_status(
             ) == ExerciseEvaluation.STATUS_UNSOLVED:
                 self.__exercise_evaluation_service.increment_exercise_evaluation_attempts(
                     exercise_evaluation)
                 unsolved_exercises_list.append(exercise)
         else:
             self.__exercise_evaluation_service.create_exercise_evaluation(
                 ExerciseEvaluation(user_id, exercise.get_id()))
             unsolved_exercises_list.append(exercise)
     return unsolved_exercises_list
 def __get_exercise_evaluation_test_instance(self):
     return ExerciseEvaluation(ObjectId('54759eb3c090d83494e2d804'),
                               ObjectId('507f1f77bcf86cd799439011'),
                               _id=ObjectId("666f6f2d6261722d71757578"))
 def __get_exercise_evaluation_test_instance(self):
     return ExerciseEvaluation('fake_user_id', 'fake_exercise_id')