コード例 #1
0
    def test_logic_add_vacation_bad_data(self):
        user = Employee.objects.all().first()

        self.assertRaises(
            ServiceException, lambda: VacationService(user=user).add_vacation(
                date_start=45,
                date_end=self.get_date(),
                comment_user='******'))

        self.assertRaises(
            ServiceException, lambda: VacationService(user=user).add_vacation(
                date_start=self.get_date(),
                date_end=45,
                comment_user='******'))

        self.assertEqual(Vacation.objects.count(), 0)
コード例 #2
0
    def test_logic_add_vacation_date_start_bigger_date_end(self):
        user = Employee.objects.all().first()

        self.assertRaises(
            ServiceException, lambda: VacationService(user=user).add_vacation(
                date_start=self.get_date(bigger=1),
                date_end=self.get_date(),
                comment_user='******'))
コード例 #3
0
    def test_logic_add_vacation_unknown(self):
        self.assertRaises(
            ServiceException, lambda: VacationService().add_vacation(
                date_start=self.get_date(),
                date_end=self.get_date(bigger=1),
                comment_user='******'))

        self.assertEqual(Vacation.objects.count(), 0)
コード例 #4
0
    def test_logic_add_vacation_summary_date_bigger_14_2_year(self):
        user = Employee.objects.all().first()

        vacation = VacationService(user=user).add_vacation(
            date_start=self.get_date(),
            date_end=self.get_date(bigger=14),
            comment_user='******')

        self.assertIsInstance(vacation, Vacation)
        self.assertEqual(Vacation.objects.count(), 1)

        vacation = VacationService(user=user).add_vacation(
            date_start=self.get_date(bigger=365),
            date_end=self.get_date(bigger=(14 + 365)),
            comment_user='******')

        self.assertIsInstance(vacation, Vacation)
        self.assertEqual(Vacation.objects.count(), 2)
コード例 #5
0
    def test_logic_add_vacation_summary_date_bigger_14(self):
        user = Employee.objects.all().first()

        vacation = VacationService(user=user).add_vacation(
            date_start=self.get_date(),
            date_end=self.get_date(bigger=14),
            comment_user='******')

        self.assertIsInstance(vacation, Vacation)
        self.assertEqual(Vacation.objects.count(), 1)

        self.assertRaises(
            ServiceException, lambda: VacationService(user=user).add_vacation(
                date_start=self.get_date(),
                date_end=self.get_date(bigger=3),
                comment_user='******'))

        self.assertEqual(Vacation.objects.count(), 1)
コード例 #6
0
    def test_logic_update_vacation_by_admin(self):
        user = Employee.objects.filter(group_code=Employee.GUSER).first()
        admin = Employee.objects.filter(group_code=Employee.GADMIN).first()

        vacation = VacationService(user=user).add_vacation(
            date_start=self.get_date(),
            date_end=self.get_date(bigger=14),
            comment_user='******')

        self.assertIsInstance(vacation, Vacation)
        self.assertEqual(Vacation.objects.count(), 1)

        VacationService(user=admin).update_vacation(
            vacation=vacation, state=Vacation.VACATION_REJECTED_BY_ADMIN)

        self.assertEqual(
            Vacation.objects.get(pk=vacation.id).state,
            Vacation.VACATION_REJECTED_BY_ADMIN)
コード例 #7
0
ファイル: vacation.py プロジェクト: pr0d1gy-/vacation
 def update(self, instance, validated_data):
     service = VacationService(user=self.context['request'].user)
     try:
         return service.update_vacation(
             self.instance,
             self.validated_data.get('state', None),
             self.validated_data.get('comment_admin', None)
         )
     except ServiceException as e:
         raise ValidationError({'error': e.args[0]})
コード例 #8
0
ファイル: vacation.py プロジェクト: pr0d1gy-/vacation
 def create(self, validated_data):
     service = VacationService(user=self.context['request'].user)
     try:
         return service.add_vacation(
             date_start=validated_data['date_start'],
             date_end=validated_data['date_end'],
             comment_user=validated_data.get('comment_user', None)
         )
     except ServiceException as e:
         raise ValidationError({'error': e.args[0]})
コード例 #9
0
    def test_logic_update_vacation_by_user(self):
        user = Employee.objects.filter(group_code=Employee.GUSER).first()

        vacation = VacationService(user=user).add_vacation(
            date_start=self.get_date(),
            date_end=self.get_date(bigger=14),
            comment_user='******')

        self.assertIsInstance(vacation, Vacation)
        self.assertEqual(Vacation.objects.count(), 1)

        self.assertRaises(
            ServiceException, lambda: VacationService(user=user).
            update_vacation(vacation=vacation,
                            state=Vacation.VACATION_APPROVED_BY_MANAGER))

        self.assertRaises(
            ServiceException,
            lambda: VacationService(user=user).update_vacation(
                vacation=vacation, state=Vacation.VACATION_APPROVED_BY_ADMIN))