Example #1
0
def test_clean_null_removing_shifts_properly():
    """Tests that old null shifts are removed from list."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )

    # Mimic initial shift detail generation
    for shift in schedule.schedule_new:
        schedule._determine_shift_details(
            shift, USER_SHIFT_CODES, STAT_HOLIDAYS
        )

    # Initial test of original number of null entries
    assert len(schedule.notification_details['null']) == 2
    assert schedule.notification_details['null'][0]['shift_code'] == 'vr'
    assert schedule.notification_details['null'][1]['shift_code'] == 'WR'

    schedule._group_schedule_by_date()
    schedule.determine_schedule_additions()
    schedule.determine_schedule_changes()

    # Manually add the WR shift to changes/additions (this normally wouldn't
    # happen as all null shifts are removed during initial processing).
    schedule.notification_details['changes'][1]['shift_codes'].append('WR')
    schedule.notification_details['additions'][1]['shift_codes'].append('WR')

    schedule.clean_null()

    null = schedule.notification_details['null']

    assert len(null) == 1
    assert null[0]['shift_code'] == 'WR'
Example #2
0
def test_determine_shift_details_missing_shift():
    """Tests handling of missing shift."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )

    shift = {
        'shift_code': 'E1',
        'start_date': date(2018, 1, 2),
        'comment': '',
    }

    schedule._determine_shift_details(shift, USER_SHIFT_CODES, STAT_HOLIDAYS)
    missing = schedule.notification_details['missing']
    missing_upload = schedule.notification_details['missing_upload']

    assert len(schedule.shifts) == 1
    assert len(missing) == 1
    assert len(missing_upload) == 1

    assert schedule.shifts[0]['shift_code'] == 'E1'
    assert schedule.shifts[0]['start_datetime'] == datetime(2018, 1, 2, 1, 0)
    assert schedule.shifts[0]['end_datetime'] == datetime(2018, 1, 2, 2, 6)
    assert schedule.shifts[0]['shift_code_fk'] is None

    assert missing[0]['date'] == date(2018, 1, 2)
    assert missing[0]['email_message'] == '2018-01-02 - E1'
    assert 'E1' in missing_upload
Example #3
0
def test_clean_missing_removes_shifts_properly():
    """Tests that old missing shifts are removed from list."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )

    # Mimic initial shift detail generation
    for shift in schedule.schedule_new:
        schedule._determine_shift_details(
            shift, USER_SHIFT_CODES, STAT_HOLIDAYS
        )

    # Initial test of original number of missing entries
    assert len(schedule.notification_details['missing']) == 4
    assert schedule.notification_details['missing'][0]['shift_code'] == 'C1F'
    assert schedule.notification_details['missing'][1]['shift_code'] == 'D1'
    assert schedule.notification_details['missing'][2]['shift_code'] == 'C2'
    assert schedule.notification_details['missing'][3]['shift_code'] == 'A1'

    schedule._group_schedule_by_date()
    schedule.determine_schedule_additions()
    schedule.determine_schedule_changes()
    schedule.clean_missing()

    missing = schedule.notification_details['missing']

    assert len(missing) == 3
    assert missing[0]['shift_code'] == 'C1F'
    assert missing[1]['shift_code'] == 'D1'
    assert missing[2]['shift_code'] == 'A1'
Example #4
0
def test_retrieve_stat_holidays_with_no_shifts():
    """Tests handling of empty schedule in retrieve_stat_holidays."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, [], USER, APP_CONFIG
    )
    stat_holidays = schedule._retrieve_stat_holidays()

    assert stat_holidays is None
Example #5
0
def test_retrieve_stat_holidays_date_conversion():
    """Tests handling of empty schedule in retrieve_stat_holidays."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )
    stat_holidays = schedule._retrieve_stat_holidays()

    assert isinstance(stat_holidays[0], datetime)
Example #6
0
def test_retrieve_shift_codes_decimal_conversions():
    """Tests that decimal conversions work properly."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )
    shift_codes = schedule._retrieve_shift_codes()

    assert isinstance(shift_codes[0]['monday_duration'], Decimal)
Example #7
0
def test_retrieve_shift_codes_time_conversions():
    """Tests that time conversions work properly."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )
    shift_codes = schedule._retrieve_shift_codes()

    assert isinstance(shift_codes[0]['monday_start'], time)
Example #8
0
def test_retrieve_shift_codes_null_shift():
    """Tests that time conversions accomodate null (None) shifts."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )
    shift_codes = schedule._retrieve_shift_codes()

    assert shift_codes[1]['monday_start'] is None
    assert shift_codes[1]['monday_duration'] is None
Example #9
0
def test_retrieve_stat_holidays_404_response():
    """Tests handling of 404 response in retrieve_stat_holidays."""
    try:
        schedule = assemble_schedule.Schedule(
            OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
        )
        schedule._retrieve_stat_holidays()
    except ScheduleError:
        assert True
    else:
        assert False
Example #10
0
def test_group_schedule_by_date():
    """Tests that the extracted schedule is properly grouped by date."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )
    schedule.shifts = NEW_SCHEDULE
    schedule._group_schedule_by_date()

    assert len(schedule.schedule_new_by_date) == 7
    assert len(schedule.schedule_new_by_date['2018-01-01']) == 1
    assert len(schedule.schedule_new_by_date['2018-05-01']) == 2
    assert schedule.schedule_new_by_date['2018-05-01'][1]['shift_code'] == 'C2'
Example #11
0
def test_determine_schedule_deletions():
    """Tests identification of shift deletions."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )
    schedule.shifts = NEW_SCHEDULE
    schedule._group_schedule_by_date()
    schedule.determine_schedule_deletions()

    deletions = schedule.notification_details['deletions']
    assert len(deletions) == 1
    assert deletions[0]['date'] == '2018-06-01'
    assert deletions[0]['email_message'] == '2018-06-01 - C1'
Example #12
0
def test_determine_schedule_changes():
    """Tests identification of shift changes."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )
    schedule.shifts = NEW_SCHEDULE
    schedule._group_schedule_by_date()
    schedule.determine_schedule_changes()

    changes = schedule.notification_details['changes']

    assert len(changes) == 2
    assert changes[0]['date'] == '2018-02-01'
    assert changes[0]['email_message'] == '2018-02-01 - C1 changed to C1F'
    assert changes[1]['date'] == '2018-04-01'
    assert changes[1]['email_message'] == '2018-04-01 - C1/D1 changed to D1'
Example #13
0
def test_determine_shift_details_with_comment():
    """Tests that comments are added to a shift."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )

    shift = {
        'shift_code': 'C1',
        'start_date': date(2018, 1, 2),
        'comment': 'TEST',
    }

    schedule._determine_shift_details(shift, USER_SHIFT_CODES, STAT_HOLIDAYS)

    assert len(schedule.shifts) == 1
    assert schedule.shifts[0]['comment'] == 'TEST'
Example #14
0
def test_determine_shift_details_null_shift():
    """Tests handling of null shift."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )

    shift = {
        'shift_code': 'vr',
        'start_date': date(2018, 1, 2),
        'comment': '',
    }

    schedule._determine_shift_details(shift, USER_SHIFT_CODES, STAT_HOLIDAYS)
    null_details = schedule.notification_details['null']

    assert not schedule.shifts
    assert len(null_details) == 1
    assert null_details[0]['date'] == date(2018, 1, 2)
    assert null_details[0]['email_message'] == '2018-01-02 - vr'
Example #15
0
def test_determine_shift_details_defined_shift():
    """Tests assigning details to a defined shift."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )

    shift = {
        'shift_code': 'C1',
        'start_date': date(2018, 1, 2),
        'comment': '',
    }

    schedule._determine_shift_details(shift, USER_SHIFT_CODES, STAT_HOLIDAYS)

    assert len(schedule.shifts) == 1
    assert schedule.shifts[0]['shift_code'] == 'C1'
    assert schedule.shifts[0]['start_datetime'] == datetime(2018, 1, 2, 3, 0)
    assert schedule.shifts[0]['end_datetime'] == datetime(2018, 1, 2, 6, 18)
    assert schedule.shifts[0]['comment'] == ''
    assert schedule.shifts[0]['shift_code_fk'] == 1
Example #16
0
def test_group_schedule_by_date_x_handling():
    """Tests that the extracted schedule ignores "X" shifts."""
    schedule = assemble_schedule.Schedule(
        OLD_SCHEDULE, EXTRACTED_SCHEDULE, USER, APP_CONFIG
    )

    updated_new_schedule = NEW_SCHEDULE
    updated_new_schedule.append({
        'shift_code': 'X',
        'start_datetime': datetime(2018, 1, 1, 1, 0),
        'end_datetime': datetime(2018, 1, 1, 2, 0),
        'comment': '',
        'shift_code_fk': None,
    })
    schedule.shifts = updated_new_schedule

    schedule._group_schedule_by_date()

    assert len(schedule.schedule_new_by_date) == 7
    assert len(schedule.schedule_new_by_date['2018-01-01']) == 1