def test_can_be_joined5(self):

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

        data = {
            'assignation': {
                'starting_date': '2018-12-28',
                'ending_date': '2019-1-10',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': None
            }
        }
        assign1 = create_an_assignation(data, workshift_db)

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

        assert AssignationOperator.can_be_joined(assign1, assign2)
    def test_arent_compatible2(self):
        workshifts_data = [{'id': 4, 'total_workshift_days': 3}]
        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': 2
            }
        }
        assign2 = create_an_assignation(data, workshift_db)

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

        assign1 = create_an_assignation(data)

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

        assign2 = create_an_assignation(data)

        assign_list = [assign1, assign2]
        assign_generator = AssignationOperator.get_assignation_generator(
            assign_list)

        resp = AssignationOperator.get_min_starting_date(assign_generator)
        assert resp == 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_get_biggest_assign1(self):

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

        assign1 = create_an_assignation(data)

        data = {
            'assignation': {
                'starting_date': '2019-2-1',
                'ending_date': '2019-3-8'
            }
        }

        assign2 = create_an_assignation(data)

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

        assign3 = create_an_assignation(data)

        assign_list = [assign1, assign2, assign3]

        assert AssignationOperator.get_biggest_assign(assign_list) == assign2
    def test_are_multiple_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-8',
                'ending_date': '2019-1-10'
            }
        }

        assign2 = create_an_assignation(data)

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

        assign = create_an_assignation(data)

        assign_list = [assign1, assign2]

        resp = AssignationOperator.are_multiple_neighbors(assign, assign_list)
        assert resp == assign_list
Exemplo n.º 7
0
    def test_process_differences3(self):

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

        data = {
            'assignation': {
                'id': 1,
                'starting_date': '2019-2-16',
                'ending_date': '2019-2-25',
                'workshift_id': 6,
                'person_id': 1,
                'starting_day': 1
            }
        }
        assign1 = create_an_assignation(data, workshift_db)

        assignations = [assign1]
        assignation_db = AssignationDB(assignations, None)

        data = {
            'assignation': {
                'starting_date': '2019-2-19',
                'ending_date': '2019-2-22',
                'workshift_id': 6,
                'person_id': 1,
                'starting_day': 4
            }
        }
        fake_assign = create_an_assignation(data, workshift_db)

        assignation_db.unassign(fake_assign)

        data = {
            'assignation': {
                'starting_date': '2019-2-21',
                'ending_date': '2019-2-21',
                'workshift_id': 6,
                'person_id': 1,
                'starting_day': 6
            }
        }
        assign2 = create_an_assignation(data, workshift_db)

        assignation_db.assignate(assign2)

        differences_operator = DifferencesOperator(assignation_db)
        resp = differences_operator.process_differences()

        expected1 = Range(
            datetime(2019, 2, 19).date(),
            datetime(2019, 2, 20).date())

        expected2 = Range(
            datetime(2019, 2, 22).date(),
            datetime(2019, 2, 22).date())

        assert resp['1'] == [expected1, expected2]
    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]
    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)
Exemplo n.º 10
0
    def test_get_difference8(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-2-16',
                'ending_date': '2019-2-16',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 8
            }
        }
        assign = create_an_assignation(data, workshift_db)
        assign.starting_date = datetime(2019, 2, 16).date()
        assign.ending_date = datetime(2019, 2, 20).date()

        resp = assign.get_differences()

        resp_right = Range(
            datetime(2019, 2, 17).date(),
            datetime(2019, 2, 20).date())

        assert ([resp_right] == resp['was_created'] and
                resp['was_deleted'] == [])
Exemplo n.º 11
0
    def test_simulate_starting_day3(self):

        workshifts_data = [
            {
                'id': 6,
                '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-31',
                'starting_day': 2,
                'workshift_id': 6,
            }
        }

        assign = create_an_assignation(data, workshift_db)

        date_obj = datetime(2019, 1, 23).date()

        simulated_starting_day = AssignationOperator.simulate_starting_day(
            assign, date_obj)

        assert 8 == simulated_starting_day
Exemplo n.º 12
0
    def test_get_difference3(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-10',
                'ending_date': '2019-1-15',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 8
            }
        }
        assign = create_an_assignation(data, workshift_db)
        assign.starting_date = datetime(2019, 1, 10).date()
        assign.ending_date = datetime(2019, 1, 15).date()

        resp = assign.get_differences()

        assert [] == resp['was_deleted'] and resp['was_created'] == []
    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
    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)
Exemplo n.º 15
0
    def test_add3(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-22',
                'workshift_id': 4,
                'person_id': 1,
                'starting_day': 1
            }
        }
        assign1 = create_an_assignation(data, workshift_db)

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

        assign1 += assign2

        range_obj = assign1.range_obj
        assert (assign1.starting_date == datetime(2019, 1, 1).date() and
                assign1.ending_date == datetime(2019, 1, 22).date() and
                range_obj.starting_date == datetime(2019, 1, 1).date() and
                range_obj.ending_date == datetime(2019, 1, 22).date())
    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
Exemplo n.º 17
0
    def test_cycle_date_iterator_1(self):

        workshifts_data = [{
            'id':
            6,
            'total_workshift_days':
            3,
            'workshift_type':
            'cyclic',
            'days': [{
                'day_number': 0,
                'starting_time': '08:00',
                'ending_time': '19:00'
            }, {
                'day_number': 1,
                'starting_time': '08:00',
                'ending_time': '19:00'
            }, {
                'day_number': 2,
                'starting_time': None,
                'ending_time': None
            }]
        }]
        workshifts = create_proxy_workshifts(workshifts_data)
        workshift_db = WorkShiftDB(workshifts, WorkShiftProxy)

        assignation = {
            'assignation': {
                'person_id': 1,
                'starting_day': 1,
                'starting_date': '2020-2-1',
                'ending_date': '2020-2-10',
                'workshift_id': 6,
            }
        }
        assignation = create_an_assignation(assignation, workshift_db, None)

        iterator = CycleDateIterator(assignation, 0)

        dates = []
        for date_obj in iterator:
            dates.append(date_obj)

        expected = [
            datetime(2020, 2, 1).date(),
            datetime(2020, 2, 4).date(),
            datetime(2020, 2, 7).date(),
            datetime(2020, 2, 10).date(),
        ]
        assert expected == dates
Exemplo n.º 18
0
def proxy():

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

    data = {
        'assignation': {
            'person': 5,
            'starting_date': '2019-1-1',
            'starting_day': 1,
            'ending_date': '2019-1-10',
            'workshift_id': 10,
            'fake_attr': 'badAttr'
        }
    }

    return create_an_assignation(data, workshift_db)
Exemplo n.º 19
0
    def test_process_differences7(self):

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

        data = {
            'assignation': {
                'id': 1,
                'starting_date': '2019-2-10',
                'ending_date': '2019-2-15',
                'workshift_id': 1,
                'person_id': 1,
                'starting_day': 1
            }
        }
        assign1 = create_an_assignation(data, workshift_db)

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

        assignations = [assign1, assign2]
        assignation_db = AssignationDB(assignations, None)

        data = {
            'assignation': {
                'starting_date': '2019-2-14',
                'ending_date': '2019-2-14',
                'workshift_id': 1,
                'person_id': 1,
                'starting_day': 3
            }
        }
        assign3 = create_an_assignation(data, workshift_db)
        assignation_db.assignate(assign3)

        data = {
            'assignation': {
                'starting_date': '2019-2-13',
                'ending_date': '2019-2-17',
                'workshift_id': 2,
                'person_id': 1,
                'starting_day': 3
            }
        }
        assign4 = create_an_assignation(data, workshift_db)
        assignation_db.assignate(assign4)

        data = {
            'assignation': {
                'starting_date': '2019-2-14',
                'ending_date': '2019-2-16',
                'workshift_id': 1,
                'person_id': 1,
                'starting_day': 5
            }
        }
        fake_assign = create_an_assignation(data, workshift_db)
        assignation_db.unassign(fake_assign)

        data = {
            'assignation': {
                'starting_date': '2019-2-13',
                'ending_date': '2019-2-13',
                'workshift_id': 2,
                'person_id': 1,
                'starting_day': 4
            }
        }
        fake_assign = create_an_assignation(data, workshift_db)
        assignation_db.unassign(fake_assign)

        differences_operator = DifferencesOperator(assignation_db)
        resp = differences_operator.process_differences()

        expected = Range(
            datetime(2019, 2, 13).date(),
            datetime(2019, 2, 17).date())

        assert resp['1'] == [expected]