Ejemplo n.º 1
0
class PendingApprovalsTest(SettingUpDB):


    def setUp(self):
        super(PendingApprovalsTest, self).setUp()
        #bob want a week of holiday from 01/01/2016 to 08/01/2016
        self.bob_holiday = DaysOut(employee=self.bob_employee, initial_date=date(2016, 1, 1),
                                   final_date=date(2016, 1, 8),type=1)
        self.bob_holiday.save()
        self.bob_holiday.need_to_validate.add(self.boss_employee)
        self.bob_holiday.save()

        #alice want a week of holiday from 07/01/2016 to 14/01/2016
        self.alice_holiday = DaysOut(employee=self.alice_employee, initial_date=date(2016, 1, 7),
                                     final_date=date(2016, 1, 14), type=1)
        self.alice_holiday.save()
        self.alice_holiday.need_to_validate.add(self.another_boss_employee)
        self.alice_holiday.save()

    def test_details(self):
        request = self.factory.get(reverse('my_profile:pending'))
        #bob is not a team leader, so there is no reason he could see the pending approvals page
        request.user = self.bob_user
        response = PendingApprovals.as_view()(request, year='2016', month='01')
        self.assertEqual(response.status_code, 302) #bob is redirected to his profile
        #...but boss is a team leader
        request.user = self.boss_user
        response = PendingApprovals.as_view()(request, year='2016', month='01').render()
        self.assertIn(b'<h2>Requests</h2>', response.content)
        #... and therefore he can see the request from bob
        self.assertIn(b'<th>bob dylan</th>', response.content)
        self.assertIn(b'<th>Jan. 1, 2016</th>', response.content)
        self.assertIn(b'<th>Jan. 8, 2016</th>', response.content)
        #...but not the one from alice (he is not responsible of her)
        self.assertNotIn(b'<th>alice wonderland</th>', response.content)
Ejemplo n.º 2
0
    def setUp(self):
        super(DaysOutApprovalTest, self).setUp()
        #bob want a week of holiday from 01/01/2016 to 08/01/2016
        self.bob_holiday = DaysOut(employee=self.bob_employee, initial_date=date(2016, 1, 1),
                                   final_date=date(2016, 1, 8),type=1)
        self.bob_holiday.save()
        self.bob_holiday.need_to_validate.add(self.boss_employee, self.ceo_employee)
        self.bob_holiday.save()

        #alice want a week of holiday from 07/01/2016 to 14/01/2016
        self.alice_holiday = DaysOut(employee=self.alice_employee, initial_date=date(2016, 1, 7),
                                     final_date=date(2016, 1, 14), type=1)
        self.alice_holiday.save()
        self.alice_holiday.need_to_validate.add(self.another_boss_employee, self.ceo_employee)
        self.alice_holiday.save()
Ejemplo n.º 3
0
class DaysOutApprovalTest(SettingUpDB):


    def setUp(self):
        super(DaysOutApprovalTest, self).setUp()
        #bob want a week of holiday from 01/01/2016 to 08/01/2016
        self.bob_holiday = DaysOut(employee=self.bob_employee, initial_date=date(2016, 1, 1),
                                   final_date=date(2016, 1, 8),type=1)
        self.bob_holiday.save()
        self.bob_holiday.need_to_validate.add(self.boss_employee, self.ceo_employee)
        self.bob_holiday.save()

        #alice want a week of holiday from 07/01/2016 to 14/01/2016
        self.alice_holiday = DaysOut(employee=self.alice_employee, initial_date=date(2016, 1, 7),
                                     final_date=date(2016, 1, 14), type=1)
        self.alice_holiday.save()
        self.alice_holiday.need_to_validate.add(self.another_boss_employee, self.ceo_employee)
        self.alice_holiday.save()

    def test_details(self):
        #bob request is not yet approved
        self.assertEqual(len(self.bob_holiday.need_to_validate.all()), 2)
        request = self.factory.get(reverse('my_profile:approved', kwargs={'id': 1, 'answer': 'approved'}))
        # bob is not a team leader so he cannot approve himself his holiday
        request.user = self.bob_user
        response = DaysOutApproval.as_view()(request, year='2016', month='01', id=1, answer='approved')
        self.assertEqual(response.status_code, 302) #bob is redirected to his profile
        #boss and ceo connect to approve bob request
        request.user = self.boss_user
        response = DaysOutApproval.as_view()(request, year='2016', month='01', id=1, answer='approved')
        self.assertEqual(len(self.bob_holiday.need_to_validate.all()), 1)
        request.user = self.ceo_user
        response = DaysOutApproval.as_view()(request, year='2016', month='01', id=1, answer='approved')
        self.assertEqual(len(self.bob_holiday.need_to_validate.all()), 0)

        #another boss refuses holiday request from alice, therefore the request is deleted.
        self.alice_holiday = DaysOut.objects.filter(employee=self.alice_employee)
        self.assertEqual(len(self.alice_holiday.all()), 1)
        request = self.factory.get(reverse('my_profile:approved', kwargs={'id': 2, 'answer': 'not_approved'}))
        request.user = self.another_boss_user
        response = DaysOutApproval.as_view()(request, year='2016', month='01', id=2, answer='not_approved')
        self.assertEqual(len(self.alice_holiday.all()), 0)
Ejemplo n.º 4
0
class StatusTest(SettingUpDB):


    def setUp(self):
        super(StatusTest, self).setUp()
        #bob want a week of holiday from 01/01/2016 to 08/01/2016
        self.bob_holiday = DaysOut(employee=self.bob_employee, initial_date=date(2016, 1, 1),
                                   final_date=date(2016, 1, 8),type=1)
        self.bob_holiday.save()
        self.bob_holiday.need_to_validate.add(self.boss_employee, self.ceo_employee)
        self.bob_holiday.save()

        #alice want a week of holiday from 07/01/2016 to 14/01/2016
        self.alice_holiday = DaysOut(employee=self.alice_employee, initial_date=date(2016, 1, 7),
                                     final_date=date(2016, 1, 14), type=1)
        self.alice_holiday.save()
        self.alice_holiday.need_to_validate.add(self.boss_employee, self.ceo_employee)
        self.alice_holiday.save()


    def test_details(self):
        #bob can see that his request has been saved
        request = self.factory.get(reverse('my_profile:status'))
        request.user = self.bob_user
        response = Status.as_view()(request, year='2016', month='01').render()
        self.assertIn(b'<th>from Jan. 1, 2016 to Jan. 8, 2016</th>', response.content)
        #...but this has not been approved so far
        self.assertIn(b'no', response.content)
        #...bob cannot see the request of alice
        self.assertNotIn(b'<th>from Jan. 7, 2016 to Jan. 14, 2016</th>', response.content)
        #...boss and ceo both approve the holiday of bob
        self.bob_holiday.need_to_validate.remove(self.boss_employee, self.ceo_employee)
        self.bob_holiday.save()
        response = Status.as_view()(request, year='2016', month='01').render()
        self.assertIn(b'yes', response.content)

        #alice logs in
        request = self.factory.get(reverse('my_profile:status'))
        request.user = self.alice_user
        response = Status.as_view()(request, year='2016', month='01').render()
        self.assertIn(b'<th>from Jan. 7, 2016 to Jan. 14, 2016</th>', response.content)
        self.assertIn(b'no', response.content)
        #...boss approve the holiday of alice but not ceo
        self.alice_holiday.need_to_validate.remove(self.boss_employee)
        self.alice_holiday.save()
        response = Status.as_view()(request, year='2016', month='01').render()
        self.assertIn(b'no', response.content)
        self.alice_holiday.delete()
        response = Status.as_view()(request, year='2016', month='01').render()
        self.assertNotIn(b'<th>from Jan. 7, 2016 to Jan. 14, 2016</th>', response.content)