Esempio n. 1
0
 def test_authenticate_calledWithUserCommandRepositoryWhichRaisesCommandError_raiseServiceError(
         self):
     self.stub_auth_token_service.generate_auth_token.return_value = "fake"
     self.stub_user_command_repository.update_user_auth_token.side_effect = CommandError(
     )
     self.assertRaises(ServiceError, self.sut.authenticate,
                       "666f6f2d6261722d71757578")
 def test_createExercise_calledWithCommandRepositoryWhichThrowsCommandError_throwServiceError(
         self):
     self.stub_exercise_command_repository.create_exercise.side_effect = CommandError(
     )
     self.assertRaises(ServiceError,
                       self.sut.create_exercise,
                       exercise=self.__get_exercise_test_instance())
 def increment_exercise_evaluation_attempts(self, exercise_evaluation):
     try:
         self.db.evaluations.update(
             {'_id': exercise_evaluation.get_id()},
             {'$set': {
                 'attempt': exercise_evaluation.get_attempt() + 1
             }})
     except Exception as qe:
         raise CommandError(str(qe))
 def update_exercise_evaluation_as_solved(self, exercise_evaluation, score):
     try:
         self.db.evaluations.update({'_id': exercise_evaluation.get_id()}, {
             '$set': {
                 'score': score,
                 'status': ExerciseEvaluation.STATUS_SOLVED
             }
         })
     except Exception as qe:
         raise CommandError(str(qe))
 def create_exercise_evaluation(self, exercise_evaluation):
     try:
         self.db.evaluations.insert_one(exercise_evaluation.to_json_dict())
     except Exception as qe:
         raise CommandError(str(qe))
 def increment_user_score(self, user_id, score):
     try:
         self.db.users.update_one({"_id": user_id}, {"$inc": {"score": score}})
     except Exception as e:
         raise CommandError(str(e))
 def create_user(self, user):
     try:
         self.db.users.insert_one(user.to_json_dict())
     except Exception as e:
         raise CommandError(str(e))
Esempio n. 8
0
 def test_incrementUserScore_calledWithCommandRepositoryWhichRaisesCommandError_raiseServiceError(self):
     self.stub_user_command_repository.increment_user_score.side_effect = CommandError()
     self.assertRaises(ServiceError, self.sut.increment_user_score, user_id='test', score=10)
Esempio n. 9
0
 def test_createUser_calledWithCommandRepositoryWhichRaisesCommandError_raiseServiceError(self):
     self.stub_user_command_repository.create_user.side_effect = CommandError()
     self.assertRaises(ServiceError, self.sut.create_user, self.__get_user_test_instance())
 def test_incrementExerciseEvaluationAttempts_calledWithCommandRepositoryWhichThrowsCommandError_throwServiceError(
         self):
     self.stub_exercise_evaluation_command_repository.increment_exercise_evaluation_attempts.side_effect = CommandError(
     )
     self.assertRaises(ServiceError,
                       self.sut.increment_exercise_evaluation_attempts,
                       self.__get_exercise_evaluation_test_instance())
 def test_updateExerciseEvaluationAsSolved_calledWithCommandRepositoryWhichThrowsCommandError_throwServiceError(
         self):
     self.stub_exercise_evaluation_query_repository.get_exercise_evaluation.return_value = self.__get_exercise_evaluation_test_instance(
     )
     self.stub_exercise_evaluation_command_repository.update_exercise_evaluation_as_solved.side_effect = CommandError(
     )
     self.assertRaises(ServiceError,
                       self.sut.update_exercise_evaluation_as_solved,
                       'fake', 'fake', 200)
 def create_exercise(self, exercise):
     try:
         self.db.exercises.insert_one(exercise.to_json_dict())
     except Exception as qe:
         raise CommandError(str(qe))