Ejemplo n.º 1
0
    def test_find_by_name(self):
        params = {'year': 2017, 'employee_name': 'empl'}
        plans = PlanCtrl.find(params)
        self.assertEqual(len(plans), 1)

        params = {'year': 2017, 'employee_name': '-empl'}
        plans = PlanCtrl.find(params)
        self.assertEqual(len(plans), 0)
Ejemplo n.º 2
0
    def test_generate_question_plan_finished(self):
        """
    Месячный план ВЫПОЛНЕН
    """
        employee = Employee.get(1)
        PlanCtrl.create(employee.n, today.year, today.month, 1, 1)

        question = QuestionCtrl.generate_question(employee.name)
        assert question.n == 0  # question.n=0 пустой вопрос, означает нет вопроса
Ejemplo n.º 3
0
    def test_generate_question_day_finish(self):
        """
    План НЕ ВЫПОЛНЕН. Дневной план ВЫПОЛНЕН
    """
        employee = Employee.get(1)
        PlanCtrl.create(employee.n, today.year, today.month, 2, 1)

        question = QuestionCtrl.generate_question(employee.name)
        # print(question)
        assert question.n == 0  # question.n=0 пустой вопрос, означает нет вопроса
Ejemplo n.º 4
0
    def test_delete_month(self):
        # Проверка , что лишнее не удаляется
        PlanCtrl.delete_month(3000, 12)
        plan = Plan.get(1)
        self.assertEqual(plan.n, 1)

        # А вот теперь должно удалиться
        PlanCtrl.delete_month(2017, 12)
        plans = PlanCtrl.find({})
        self.assertEqual(len(plans), 0)
Ejemplo n.º 5
0
    def test_generate_question_day_not_finish(self):
        """
    План НЕ ВЫПОЛНЕН. Дневной план НЕ ВЫПОЛНЕН
    """
        employee = Employee.get(1)
        PlanCtrl.create(employee.n, today.year, today.month, 2, 3)

        question = QuestionCtrl.generate_question(employee.name)
        # print(question)
        assert question.n != 0  # question.n=0 пустой вопрос, означает нет вопроса
        ANSWERED_QUESTION_N = 21  # номер отвеченного вопроса из фикстуры
        assert question.n != ANSWERED_QUESTION_N
Ejemplo n.º 6
0
 def delete(self):
     """
 Удаление планов на год/месяц
 """
     print(self.context.year, self.context.month)
     try:
         PlanCtrl.delete_month(self.context.year, self.context.month)
     except Exception as e:
         error_message = 'Error delete year={} month={}. Error: {}'.format(
             self.context.year, self.context.month, e)
         self.log.warning(error_message)
         return MessageJSON(error_message)
     return {'status': 'success'}
Ejemplo n.º 7
0
 def generate_question(employee_name):
     """
 Получение след.вопроса в зависимости от плана и уже отвеченных вопросов
 """
     null_question = Question(n=0)
     today = date.today()
     year = today.year
     month = today.month
     employee = EmployeeCtrl.find_by_name(employee_name)
     plan = PlanCtrl.get_current_plan(employee_name, year, month)
     qty_answered = ResultCtrl.count_answered(employee, year,
                                              month)  # уже отвечено
     if plan.qty_question > qty_answered:
         qty_day = plan.qty_question // plan.qty_work + 1  # к-во вопросов в день
         # print('qty_day = %s' % (qty_day,))
         # print(plan)
         params = {'employee_n': employee.n, 'date': today}
         results = ResultCtrl.find(params)  # отвечено сегодня
         # print('results = %s' % (results,))
         if len(results) < qty_day:  # если план на день еще не выполнен
             subquery = Session.query(
                 Result.question_n).filter(Result.employee_n == employee.n)
             q = Session.query(Question).filter(
                 not_(Question.n.in_(subquery)))
             questions = q.all()
             # print(questions)
             if len(questions) == 0 or questions is None:
                 return QuestionCtrl.get_repeat(employee)
             return questions[0]
         else:
             return null_question
     else:
         # План по вопросам сделан
         return null_question
Ejemplo n.º 8
0
 def test_create(self):
     plan = PlanCtrl.create(1, 2000, 2, 10, 20)
     self.assertEqual(plan.n, 2)
     self.assertEqual(plan.employee_n, 1)
     self.assertEqual(plan.year, 2000)
     self.assertEqual(plan.month, 2)
     self.assertEqual(plan.qty_work, 10)
     self.assertEqual(plan.qty_question, 20)
Ejemplo n.º 9
0
 def test_create_on_month(self):
     plans = PlanCtrl.create_on_month(2000, 12)
     self.assertEqual(len(plans), 2)
     for plan in plans:
         self.assertEqual(plan.year, 2000)
         self.assertEqual(plan.month, 12)
         self.assertEqual(plan.qty_question, 0)
         self.assertEqual(plan.qty_work, 0)
     self.assertEqual(plans[0].employee.n, 1)
     self.assertEqual(plans[1].employee.n, 2)
Ejemplo n.º 10
0
 def append_plans(self, report):
     """
 Добавить плановое по к-во вопросов в отчет
 """
     plans = PlanCtrl.get_on_month(self.year, self.month)
     for r in report:
         plan = find(plans, lambda p: p.employee.name == r['employee_name'])
         if plan is not None:
             r['qty_plan'] = plan.qty_question
     return report
Ejemplo n.º 11
0
    def test_find_by_date(self):
        params = {'year': 2017}
        plans = PlanCtrl.find(params)
        self.assertEqual(len(plans), 1)

        params = {'year': 2000}
        plans = PlanCtrl.find(params)
        self.assertEqual(len(plans), 0)

        params = {'month': 12}
        plans = PlanCtrl.find(params)
        self.assertEqual(len(plans), 1)

        params = {'year': 2000, 'month': 12}
        plans = PlanCtrl.find(params)
        self.assertEqual(len(plans), 0)

        params = {'year': 2017, 'month': 12}
        plans = PlanCtrl.find(params)
        self.assertEqual(len(plans), 1)
Ejemplo n.º 12
0
 def test_create_for_params(self):
     params = {
         'employee_n': 1,
         'year': 2000,
         'month': 2,
         'qty_work': 10,
         'qty_question': 20
     }
     plan = PlanCtrl.create(**params)
     self.assertEqual(plan.n, 2)
     self.assertEqual(plan.employee_n, 1)
     self.assertEqual(plan.year, 2000)
     self.assertEqual(plan.month, 2)
     self.assertEqual(plan.qty_work, 10)
     self.assertEqual(plan.qty_question, 20)
Ejemplo n.º 13
0
 def test_create_for_arr_employees(self):
     nn_employees = [1, 2]
     plans = PlanCtrl.create_for_employees(nn_employees, 2000, 2, 10, 20)
     self.assertEqual(len(plans), 2)
Ejemplo n.º 14
0
 def test_get_current_plan(self):
     plan = PlanCtrl.get_current_plan('EMPLOYEE1', 2017, 12)
     self.assertEqual(plan.year, 2017)
     self.assertEqual(plan.month, 12)
     self.assertEqual(plan.employee.name, 'EMPLOYEE1')
Ejemplo n.º 15
0
 def test_get_on_month_NOT_create(self):
     # Планы НЕ создаются
     plans = PlanCtrl.get_on_month(2017, 12)
     self.assertEqual(len(plans), 1)
Ejemplo n.º 16
0
 def test_update(self):
     plan = PlanCtrl.update_qty(1, {'qty_work': 3})
     self.assertEqual(plan.qty_work, 3)
Ejemplo n.º 17
0
 def get(self):
     """
 Получение планов на год/месяц
 """
     plans = PlanCtrl.get_on_month(self.context.year, self.context.month)
     return self.serializator.dump(plans, many=True).data
Ejemplo n.º 18
0
 def test_get_on_month_create(self):
     # Планы создаются, если не созданы
     plans = PlanCtrl.get_on_month(3000, 12)
     self.assertEqual(len(plans), 2)
Ejemplo n.º 19
0
 def update(self):
   return self.serializator.dump(PlanCtrl.update_qty(self.context.n, self.request.json_body)).data