def build_assignations_db(self): assignations_database_data = self.data['assignations_database'] database_assignations = create_assignations( assignations_database_data, self.workshift_db, self.day_off_assignations_db ) assignation_db = AssignationDB(database_assignations, None) return assignation_db
def test_process_differences2(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-20', 'ending_date': '2019-2-22', 'workshift_id': 6, 'person_id': 1, 'starting_day': 5 } } fake_assign = create_an_assignation(data, workshift_db) assignation_db.unassign(fake_assign) differences_operator = DifferencesOperator(assignation_db) resp = differences_operator.process_differences() expected1 = Range( datetime(2019, 2, 20).date(), datetime(2019, 2, 22).date()) assert resp['1'] == [expected1]
def assignation_moves(data): workshifts_data = data['workshifts'] workshifts = create_proxy_workshifts(workshifts_data) workshift_db = WorkShiftDB(workshifts, WorkShiftProxy) days_off_data = data['days_off'] day_off_assignations = create_proxy_day_off_assignation(days_off_data) day_off_assignations_db = DayOffAssignationDB(day_off_assignations, DayOffAssignationProxy) assignations_database_data = data['assignations_database'] database_assignations = create_assignations(assignations_database_data, workshift_db, day_off_assignations_db) assignation_db = AssignationDB(database_assignations, None) moves = data['moves'] assignations_data = moves['assignations'] assignations = create_assignations(assignations_data, workshift_db, day_off_assignations_db) deallocates_data = moves['deallocates'] deallocates = create_assignations(deallocates_data, workshift_db, day_off_assignations_db) for deallocate in deallocates: assignation_db.unassign(deallocate) for assignation in assignations: if not check_collisions(assignation, assignation_db): assignation_db.assignate(assignation) else: # Tiene colisiones, entonces lo ignoramos pass response = {'create': [], 'update': [], 'delete': []} for new_assignation in assignation_db.to_be_created: response['create'].append({ 'person_id': new_assignation.person_id, 'workshift_id': new_assignation.person_id, 'starting_date': f"{new_assignation.starting_date}", 'ending_date': f"{new_assignation.ending_date}", 'starting_day': new_assignation.starting_day, }) for update_assignation in assignation_db.to_be_updated: response['update'].append({ 'id': assignation.id, 'starting_date': f"{update_assignation.starting_date}", 'ending_date': f"{update_assignation.ending_date}", }) for delete_assignation in assignation_db.to_be_deleted: response['delete'].append(delete_assignation.id) return response
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]