def build_days_off_db(self): days_off_data = self.data['days_off'] day_off_assignations = create_proxy_day_off_assignation(days_off_data) day_off_assignations_db = DayOffAssignationDB( day_off_assignations, DayOffAssignationProxy ) return day_off_assignations_db
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_is_in_5(self): day_off_assignations_data = [{ 'person_id': 1, 'starting_date': '2019-1-1', 'ending_date': '2019-1-6', 'starting_time': '06:00', 'ending_time': '05:59' }] day_off_assignations = create_proxy_day_off_assignation( day_off_assignations_data) facade = DayOffAssignationFacade(day_off_assignations[0]) range_datetime = RangeDateTime( datetime(2019, 1, 2, 1, 10), datetime(2019, 1, 4, 2, 10), ) assert facade.is_in(range_datetime)
def test_is_not_in_6(self): day_off_assignations_data = [{ 'person_id': 1, 'starting_date': '2019-1-1', 'ending_date': '2019-1-9', 'starting_time': '20:00', 'ending_time': '08:00' }] day_off_assignations = create_proxy_day_off_assignation( day_off_assignations_data) facade = DayOffAssignationFacade(day_off_assignations[0]) range_datetime = RangeDateTime( datetime(2019, 1, 2, 20, 59), datetime(2019, 1, 3, 8, 1), ) assert not facade.is_in(range_datetime)