예제 #1
0
    def test_shifts_position_not_included_employee_position(self):
        # An employee cannot receive invites from shifts were shift.position is not included in employee.positions.

        self.test_user_employee, self.test_employee, _ = self._make_user(
            'employee',
            employexkwargs=dict(
                minimum_hourly_rate=9,
                rating=5,
                # stop_receiving_invites=True,
                maximum_job_distance_miles=15),
            profilekwargs=dict(latitude=40, longitude=-73),
            userkwargs=dict(
                username='******',
                email='*****@*****.**',
                is_active=True,
            ))

        starting_at = timezone.now() + timedelta(days=1)
        ending_at = starting_at + timedelta(minutes=90)

        self.test_shift_position, _, __ = self._make_shift(
            shiftkwargs=dict(status='OPEN',
                             starting_at=starting_at,
                             ending_at=ending_at,
                             minimum_hourly_rate=11.50,
                             minimum_allowed_rating=0),
            employer=self.test_employer)

        talents = []
        talents = notifier.get_talents_to_notify(self.test_shift_position)
        self.assertEquals(
            len(talents) == 0, True,
            'Employee cannot recieve invites from shifts were shift.position is not included in the employee positions'
        )
예제 #2
0
    def test_employee_stop_receiving_invites_ON(self):
        # not reciving invites

        starting_at = timezone.now() + timedelta(days=1)
        ending_at = starting_at + timedelta(minutes=90)

        self.test_shift_stop_receiving_invites_ON, _, __ = self._make_shift(
            shiftkwargs=dict(status='OPEN',
                             starting_at=starting_at,
                             ending_at=ending_at,
                             minimum_hourly_rate=11.50,
                             minimum_allowed_rating=0),
            employer=self.test_employer)

        self.test_user_employee, self.test_employee, _ = self._make_user(
            'employee',
            employexkwargs=dict(minimum_hourly_rate=9,
                                rating=5,
                                stop_receiving_invites=True,
                                maximum_job_distance_miles=15),
            profilekwargs=dict(latitude=40, longitude=-73),
            userkwargs=dict(
                username='******',
                email='*****@*****.**',
                is_active=True,
            ))

        talents = []
        talents = notifier.get_talents_to_notify(
            self.test_shift_stop_receiving_invites_ON)
        self.assertEquals(
            len(talents) == 0, True,
            'There should be 0 invites because the talent is not accepting invites but there are'
        )
예제 #3
0
    def test_shift_minimum_allowed_rating_greater_employee(self):
        # An employee cannot receive invites from shifts were shift.minimum_allowed_rating is bigger than employee.rating
        position = mixer.blend('api.Position')

        starting_at = timezone.now() + timedelta(days=1)
        ending_at = starting_at + timedelta(minutes=90)

        self.test_shift_minimum_hourly_rate_greater_employee, _, __ = self._make_shift(
            shiftkwargs=dict(status='OPEN',
                             starting_at=starting_at,
                             ending_at=ending_at,
                             position=position,
                             minimum_hourly_rate=11.50,
                             minimum_allowed_rating=3),
            employer=self.test_employer)

        self.test_user_employee, self.test_employee, _ = self._make_user(
            'employee',
            employexkwargs=dict(
                rating=1,
                total_ratings=1,
                positions=[position.id],
            ),
            userkwargs=dict(
                username='******',
                email='*****@*****.**',
                is_active=True,
            ))
        talents = []
        talents = notifier.get_talents_to_notify(
            self.test_shift_minimum_hourly_rate_greater_employee)
        self.assertEquals(
            len(talents) == 0, True,
            'There should be 0 invites because the shift have higher rating')
예제 #4
0
    def test_shifts_minimum_hourly_rate_lesser_employee(self):
        # An employee cannot receive invites from shifts.minimum_hourly_rate that pay less than its employee. minimum_hourly_rate
        position = mixer.blend('api.Position')
        starting_at = timezone.now() + timedelta(days=1)
        ending_at = starting_at + timedelta(minutes=90)

        self.test_shift_minimum_hourly_rate_lesser_employee, _, __ = self._make_shift(
            shiftkwargs=dict(status='OPEN',
                             starting_at=starting_at,
                             ending_at=ending_at,
                             position=position,
                             minimum_hourly_rate=9,
                             minimum_allowed_rating=0),
            employer=self.test_employer)

        self.test_user_employee, self.test_employee, _ = self._make_user(
            'employee',
            employexkwargs=dict(minimum_hourly_rate=10,
                                positions=[position.id]),
            userkwargs=dict(
                username='******',
                email='*****@*****.**',
                is_active=True,
            ))
        talents = []

        talents = notifier.get_talents_to_notify(
            self.test_shift_minimum_hourly_rate_lesser_employee)
        self.assertEquals(
            len(talents) == 0, True,
            'There should be 0 invites because the minimum shifts minimum hourly rate is lesser than employee'
        )
예제 #5
0
    def test_shift_same_time_applied_other_shift(self):
        # An employee cannot receive invites from shifts that occur (shift.starting_at, shift.ending_at) at within the time that other shifts were the employee is already an employee of.
        position = mixer.blend('api.Position')

        starting_at = timezone.now()
        ending_at = starting_at + timedelta(minutes=120)

        self.test_user_employee, self.test_employee, _ = self._make_user(
            'employee',
            employexkwargs=dict(minimum_hourly_rate=9,
                                rating=5,
                                positions=[position.id],
                                stop_receiving_invites=False,
                                maximum_job_distance_miles=15),
            profilekwargs=dict(latitude=40, longitude=-73),
            userkwargs=dict(
                username='******',
                email='*****@*****.**',
                is_active=True,
            ))
        mixer.blend('api.AvailabilityBlock',
                    employee=self.test_employee,
                    starting_at=starting_at - timedelta(minutes=200),
                    ending_at=starting_at + timedelta(minutes=200),
                    allday=True)

        #this one available to be sent because is outside the range of the applied shift
        self.test_shift_pending_outrange, _, __ = self._make_shift(
            shiftkwargs=dict(status='OPEN',
                             starting_at=starting_at - timedelta(minutes=125),
                             ending_at=starting_at - timedelta(minutes=5),
                             position=position,
                             minimum_hourly_rate=10,
                             minimum_allowed_rating=1),
            venuekwargs=dict(latitude=40, longitude=-73),
            employer=self.test_employer)

        self.test_shift_accepted_employees, _, __ = self._make_shift(
            shiftkwargs=dict(employees=self.test_employee,
                             status='OPEN',
                             starting_at=starting_at,
                             ending_at=ending_at,
                             position=position,
                             minimum_hourly_rate=11.50,
                             minimum_allowed_rating=0),
            venuekwargs=dict(latitude=40, longitude=-73),
            employer=self.test_employer)
        talents = []
        talents = notifier.get_talents_to_notify(
            self.test_shift_pending_outrange)
        self.assertEquals(
            len(talents) > 0, True,
            'There should be more than 0 invites because the talent is accepting invites outside the same timeframe'
        )
예제 #6
0
    def create(self, validated_data):
        
        shift = super(ShiftPostSerializer, self).create(validated_data)
        shift.status = "OPEN"
        shift.save()

        talents = notifier.get_talents_to_notify(shift)
        for talent in talents:
            invite = ShiftInvite(employee=talent, sender=self.context['request'].user.profile, shift=shift)
            invite.save()
            notifier.notify_single_shift_invite(invite)

        return shift
예제 #7
0
    def test_shift_minimum_allowed_rating_lesser_employee(self):
        # An employee can receive invites from shifts were shift.minimum_allowed_rating is smaller than employee.rating
        position = mixer.blend('api.Position')

        starting_at = timezone.now() + timedelta(days=1)
        ending_at = starting_at + timedelta(minutes=90)

        self.test_shift_minimum_hourly_rate_lesser_employee, _, __ = self._make_shift(
            shiftkwargs=dict(status='OPEN',
                             starting_at=starting_at,
                             ending_at=ending_at,
                             position=position,
                             minimum_hourly_rate=11.50,
                             minimum_allowed_rating=3),
            venuekwargs=dict(latitude=40, longitude=-73),
            employer=self.test_employer)

        self.test_user_employee, self.test_employee, _ = self._make_user(
            'employee',
            employexkwargs=dict(
                rating=5,
                total_ratings=5,
                positions=[position.id],
            ),
            profilekwargs=dict(latitude=40, longitude=-73),
            userkwargs=dict(
                username='******',
                email='*****@*****.**',
                is_active=True,
            ))

        mixer.blend('api.AvailabilityBlock',
                    employee=self.test_employee,
                    starting_at=starting_at,
                    ending_at=ending_at,
                    allday=True)

        talents = []
        talents = notifier.get_talents_to_notify(
            self.test_shift_minimum_hourly_rate_lesser_employee)

        self.assertEquals(
            len(talents) > 0, True,
            'There should be 1 invites because the shift have smaller rating')
예제 #8
0
    def test_employee_stop_receiving_invites_OFF(self):
        position = mixer.blend('api.Position')
        starting_at = timezone.now() + timedelta(days=1)
        ending_at = starting_at + timedelta(minutes=90)

        self.test_shift_stop_receiving_invites_OFF, _, __ = self._make_shift(
            shiftkwargs=dict(status='OPEN',
                             starting_at=starting_at,
                             ending_at=ending_at,
                             position=position,
                             minimum_hourly_rate=11.50,
                             minimum_allowed_rating=0),
            venuekwargs=dict(latitude=40, longitude=-73),
            employer=self.test_employer)

        self.test_user_employee, self.test_employee, _ = self._make_user(
            'employee',
            employexkwargs=dict(minimum_hourly_rate=9,
                                rating=5,
                                stop_receiving_invites=False,
                                maximum_job_distance_miles=15,
                                positions=[position.id]),
            profilekwargs=dict(latitude=40, longitude=-73),
            userkwargs=dict(
                username='******',
                email='*****@*****.**',
                is_active=True,
            ))
        mixer.blend('api.AvailabilityBlock',
                    employee=self.test_employee,
                    starting_at=starting_at,
                    ending_at=ending_at,
                    allday=True)

        talents = []
        talents = notifier.get_talents_to_notify(
            self.test_shift_stop_receiving_invites_OFF)

        self.assertEquals(
            len(talents) > 0, True,
            'There should be more than 0 invites because the talent is accepting invites'
        )
예제 #9
0
    def test_shifts_position_included_employee_position(self):
        # An employee cannot receive invites from shifts were shift.position is not included in employee.positions.
        position = mixer.blend('api.Position')

        starting_at = timezone.now() + timedelta(days=1)
        ending_at = starting_at + timedelta(minutes=90)

        self.test_shift_position, _, __ = self._make_shift(
            shiftkwargs=dict(status='OPEN',
                             starting_at=starting_at,
                             ending_at=ending_at,
                             position=position,
                             minimum_hourly_rate=11.50,
                             minimum_allowed_rating=0),
            venuekwargs=dict(latitude=40, longitude=-73),
            employer=self.test_employer)

        self.test_user_employee, self.test_employee, _ = self._make_user(
            'employee',
            employexkwargs=dict(minimum_hourly_rate=9,
                                rating=5,
                                positions=[position.id],
                                stop_receiving_invites=False,
                                maximum_job_distance_miles=15),
            profilekwargs=dict(latitude=40, longitude=-73),
            userkwargs=dict(
                username='******',
                email='*****@*****.**',
                is_active=True,
            ))
        mixer.blend('api.AvailabilityBlock',
                    employee=self.test_employee,
                    starting_at=starting_at,
                    ending_at=ending_at,
                    allday=True)

        talents = []
        talents = notifier.get_talents_to_notify(self.test_shift_position)
        self.assertEquals(
            len(talents) > 0, True,
            'Employee should receive invite from shift because shift.position is included in the employee positions'
        )
예제 #10
0
    def test_limitation_for_employees_in_favoritelist(self):
        position = mixer.blend('api.Position')

        starting_at = timezone.now() + timedelta(days=1)
        ending_at = starting_at + timedelta(minutes=90)

        self.test_shift_favlist, _, __ = self._make_shift(
            shiftkwargs=dict(status='OPEN',
                             starting_at=starting_at,
                             ending_at=ending_at,
                             position=position,
                             minimum_hourly_rate=9,
                             minimum_allowed_rating=3),
            employer=self.test_employer)

        self.test_user_employee, self.test_employee, _ = self._make_user(
            'employee',
            employexkwargs=dict(
                minimum_hourly_rate=10,
                rating=1,
                positions=[position.id],
                stop_receiving_invites=False,
            ),
            userkwargs=dict(
                username='******',
                email='*****@*****.**',
                is_active=True,
            ))

        mixer.blend('api.FavoriteList',
                    employer=self.test_employer,
                    auto_accept_employees_on_this_list=True,
                    employees=[self.test_employee])

        talents = []
        talents = notifier.get_talents_to_notify(self.test_shift_favlist)
        self.assertEquals(
            len(talents) == 0, True,
            'There should be more than 0 invites because the only favorite employe dont pass any of the requierement'
        )
예제 #11
0
    def create(self, validated_data):

        shift = super(ShiftPostSerializer, self).create(validated_data)
        shift.maximum_clockin_delta_minutes = shift.employer.maximum_clockin_delta_minutes
        shift.maximum_clockout_delay_minutes = shift.employer.maximum_clockout_delay_minutes
        shift.save()

        # print(validated_data)
        # if 'employees' in validated_data:
        #     for employee in validated_data['employees']:
        #         ShiftEmployee.objects.create(employee=employee, shift=shift)

        talents = []
        includeEmailNotification = False
        if shift.application_restriction == 'SPECIFIC_PEOPLE':
            talents = Employee.objects.filter(id__in=[
                talent['value']
                for talent in self.context['request'].data['pending_invites']
            ])
            includeEmailNotification = True
        else:
            includeEmailNotification = (
                BROADCAST_NOTIFICATIONS_BY_EMAIL == 'TRUE')
            talents = notifier.get_talents_to_notify(shift)

        manual_invitations = (
            shift.application_restriction == 'SPECIFIC_PEOPLE')

        for talent in talents:
            invite = ShiftInvite(manually_created=manual_invitations,
                                 employee=talent,
                                 sender=self.context['request'].user.profile,
                                 shift=shift)
            invite.save()
            notifier.notify_single_shift_invite(
                invite, withEmail=includeEmailNotification)

        log_debug("shifts", "Created shift: " + str(shift))

        return shift
예제 #12
0
    def test_shift_not_in_availability_block_allday(self):
        # An employee cannot receive invites from shifts that occur (shift.starting_at, shift.ending_at) outside of its availability blocks (employee.availabilit_block_set).
        position = mixer.blend('api.Position')
        shift_starting_at = timezone.now() + timedelta(days=1)
        shift_ending_at = shift_starting_at + timedelta(minutes=90)
        # employee_available_starting_at = shift_starting_at
        # employee_available_ending_at = shift_ending_at

        self.test_shift_availability_block, _, __ = self._make_shift(
            shiftkwargs=dict(status='OPEN',
                             starting_at=shift_starting_at,
                             ending_at=shift_ending_at,
                             position=position,
                             minimum_hourly_rate=11.50,
                             minimum_allowed_rating=0),
            employer=self.test_employer)

        self.test_user_employee, self.test_employee, _ = self._make_user(
            'employee',
            userkwargs=dict(
                username='******',
                email='*****@*****.**',
                is_active=True,
                positions=[position.id],
            ))
        mixer.blend('api.AvailabilityBlock',
                    employee=self.test_employee,
                    starting_at=shift_starting_at,
                    ending_at=shift_ending_at,
                    allday=True)

        talents = []
        talents = notifier.get_talents_to_notify(
            self.test_shift_availability_block)
        self.assertEquals(
            len(talents) == 0, True,
            'Employee can get invite if the employee starting at is lesser than shift starting at or the employee ending at is greater than the shift endingt at '
        )