def test_arent_compatible1(self):

        workshifts_data = [{'id': 4, 'total_workshift_days': 6}]
        workshifts = create_proxy_workshifts(workshifts_data)
        workshift_db = WorkShiftDB(workshifts, WorkShiftProxy)

        data = {
            'assignation': {
                'starting_date': '2019-1-1',
                'ending_date': '2019-1-3',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 1
            }
        }

        assign1 = create_an_assignation(data, workshift_db)

        data = {
            'assignation': {
                'starting_date': '2019-1-4',
                'ending_date': '2019-1-6',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 3
            }
        }

        assign2 = create_an_assignation(data, workshift_db)

        assert not AssignationOperator.can_be_joined(assign1, assign2)
    def test_get_assignation_generator1(self):
        data = {
            'assignation': {
                'starting_date': '2019-1-1',
                'ending_date': '2019-1-5'
            }
        }

        assign1 = create_an_assignation(data)

        data = {
            'assignation': {
                'starting_date': '2019-1-5',
                'ending_date': '2019-1-10'
            }
        }

        assign2 = create_an_assignation(data)

        assign_list = [assign1, assign2]

        assign_generator = AssignationOperator.get_assignation_generator(
            assign_list)

        all_assign = True
        for idx, assign in enumerate(assign_generator):
            if assign != assign_list[idx]:
                all_assign = False
                break

        assert all_assign and isinstance(assign_generator, types.GeneratorType)
    def test_are_multiple_neighbors3(self):
        data = {
            'assignation': {
                'starting_date': '2019-1-1',
                'ending_date': '2019-1-5'
            }
        }

        assign1 = create_an_assignation(data)

        data = {
            'assignation': {
                'starting_date': '2019-1-9',
                'ending_date': '2019-1-10'
            }
        }

        assign2 = create_an_assignation(data)

        data = {
            'assignation': {
                'starting_date': '2019-1-7',
                'ending_date': '2019-1-7'
            }
        }

        assign = create_an_assignation(data)

        assign_list = [assign1, assign2]

        resp = AssignationOperator.are_multiple_neighbors(assign, assign_list)
        assert resp == []
    def test_remove3(self):

        workshifts_data = [{'id': 4, 'total_workshift_days': 8}]
        workshifts = create_proxy_workshifts(workshifts_data)
        workshift_db = WorkShiftDB(workshifts, WorkShiftProxy)

        data = {
            'assignation': {
                'starting_date': '2019-1-1',
                'ending_date': '2019-1-10',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 6
            }
        }
        assign = create_an_assignation(data, workshift_db)

        resp = AssignationOperator.remove(assign,
                                          datetime(2019, 1, 4).date(),
                                          datetime(2019, 1, 14).date())

        resp_assign = resp['update']

        assert (resp_assign.starting_date == datetime(2019, 1, 1).date()
                and resp_assign.ending_date == datetime(2019, 1, 3).date()
                and resp_assign.starting_day == 6 and resp['update'] == assign
                and resp['create'] is None and resp['delete'] is None)
    def test_get_candidates3(self):

        workshifts_data = [{'id': 4, 'total_workshift_days': 8}]
        workshifts = create_proxy_workshifts(workshifts_data)
        workshift_db = WorkShiftDB(workshifts, WorkShiftProxy)

        data = {
            'assignation': {
                'starting_date': '2019-1-1',
                'ending_date': '2019-1-5',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 6
            }
        }
        assign1 = create_an_assignation(data, workshift_db)

        data = {
            'assignation': {
                'starting_date': '2019-1-7',
                'ending_date': '2019-1-11',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 4
            }
        }
        assign2 = create_an_assignation(data, workshift_db)

        data = {
            'assignation': {
                'starting_date': '2019-1-13',
                'ending_date': '2019-1-16',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 2
            }
        }
        assign3 = create_an_assignation(data, workshift_db)

        data = {
            'assignation': {
                'starting_date': '2019-1-12',
                'ending_date': '2019-1-12',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 1
            }
        }
        assign = create_an_assignation(data, workshift_db)

        assign_list = [assign1, assign2, assign3]

        best, others = AssignationOperator.get_candidates(assign, assign_list)

        assert best == assign2 and others == [assign3]
示例#6
0
    def __add__(self, other_assign):
        if AssignationOperator.can_be_joined(self, other_assign):
            starting_date = self.range_obj.starting_date
            other_starting_date = other_assign.range_obj.starting_date

            if starting_date > other_starting_date:
                starting_day = other_assign.starting_day
                self.starting_day = starting_day

            self.range_obj += other_assign.range_obj

        return self
示例#7
0
    def unassign(self, fake_assign: AssignationProxy) -> None:
        """
        The main method to unassign. In this case, the fake_assign
        is just an AssignationMaper that represent the attributes
        of the range to remove in a specific workshift of a person
        """

        db_assigns = self.get_assigns(fake_assign)
        compatibe_assigns = AssignationOperator.are_multiple_compatible(
            fake_assign, db_assigns)

        for compatibe_assign in compatibe_assigns:
            resp = AssignationOperator.remove(
                compatibe_assign, fake_assign.range_obj.starting_date,
                fake_assign.range_obj.ending_date)

            if resp['update']:
                self.update(resp['update'])

            if resp['create']:
                self.add(resp['create'])

            if resp['delete']:
                self.remove(resp['delete'])
    def test_can_be_joined4(self):

        workshifts_data = [{'id': 4, 'total_workshift_days': 8}]
        workshifts = create_proxy_workshifts(workshifts_data)
        workshift_db = WorkShiftDB(workshifts, WorkShiftProxy)

        data = {
            'assignation': {
                'starting_date': '2019-1-1',
                'ending_date': '2019-1-5',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 6
            }
        }
        assign1 = create_an_assignation(data, workshift_db)

        data = {
            'assignation': {
                'starting_date': '2019-1-7',
                'ending_date': '2019-1-11',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 4
            }
        }
        assign2 = create_an_assignation(data, workshift_db)

        data = {
            'assignation': {
                'starting_date': '2018-12-31',
                'ending_date': '2019-1-8',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 5
            }
        }
        assign = create_an_assignation(data, workshift_db)

        list_assigns = [assign1, assign2]

        resp = AssignationOperator.are_multiple_compatible(
            assign, list_assigns)

        assert resp == list_assigns
示例#9
0
    def assignate(self, new_assign: AssignationProxy) -> None:
        """
        The main method to assign
        """

        db_assigns = self.get_assigns(new_assign)

        best, others = AssignationOperator.get_candidates(
            new_assign, db_assigns)

        if best:
            best += new_assign
            for other in others:
                best = best + other
                self.remove(other)
            if best.has_change():
                self.update(best)
        else:
            self.add(new_assign)
    def test_are_neighbors1(self):
        data = {
            'assignation': {
                'starting_date': '2019-1-1',
                'ending_date': '2019-1-5'
            }
        }
        assign1 = create_an_assignation(data)

        data = {
            'assignation': {
                'starting_date': '2019-1-5',
                'ending_date': '2019-1-10'
            }
        }

        assign2 = create_an_assignation(data)

        assert AssignationOperator.are_neighbors(assign1, assign2)
    def test_get_biggest_assign3(self):
        data = {
            'assignation': {
                'starting_date': '2018-12-31',
                'ending_date': '2019-1-8'
            }
        }

        assign1 = create_an_assignation(data)

        data = {
            'assignation': {
                'starting_date': '2018-12-31',
                'ending_date': '2019-1-8'
            }
        }

        assign2 = create_an_assignation(data)

        assign_list = [assign1, assign2]

        assert AssignationOperator.get_biggest_assign(assign_list) == assign1
    def test_sort_desc_starting_date3(self):
        data = {
            'assignation': {
                'starting_date': '2019-1-1',
                'ending_date': '2019-1-10'
            }
        }
        assign1 = create_an_assignation(data)

        data = {
            'assignation': {
                'starting_date': '2019-1-4',
                'ending_date': '2019-1-18'
            }
        }
        assign2 = create_an_assignation(data)

        assigns = [assign2, assign1]

        resp = AssignationOperator.sort_desc_starting_date(assigns)

        assert resp == assigns