예제 #1
0
def test_must_contact():
    dept1 = Department(name='Dept1', description='Dept1')
    dept2 = Department(name='Dept2', description='Dept2')

    poc_dept1 = Attendee(
        paid=c.NEED_NOT_PAY, first_name='Poc', last_name='Dept1')
    poc_dept2 = Attendee(
        paid=c.NEED_NOT_PAY, first_name='Poc', last_name='Dept2')
    poc_both = Attendee(
        paid=c.NEED_NOT_PAY, first_name='Poc', last_name='Both')

    poc_dept1.dept_memberships = [DeptMembership(
        department=dept1,
        is_poc=True)]

    poc_dept2.dept_memberships = [DeptMembership(
        department=dept2,
        is_poc=True)]

    poc_both.dept_memberships = [
        DeptMembership(
            department=dept1,
            is_poc=True),
        DeptMembership(
            department=dept2,
            is_poc=True)]

    start_time = datetime.now(tz=pytz.UTC)

    job1 = Job(
        name='Job1',
        description='Job1',
        start_time=start_time,
        duration=1,
        weight=1,
        slots=1,
        department=dept1)

    job2 = Job(
        name='Job2',
        description='Job2',
        start_time=start_time,
        duration=1,
        weight=1,
        slots=1,
        department=dept2)

    volunteer = Attendee(paid=c.HAS_PAID, first_name='V', last_name='One')

    job1.shifts = [Shift(attendee=volunteer, job=job1)]
    job2.shifts = [Shift(attendee=volunteer, job=job2)]

    with Session() as session:
        session.add_all([
            dept1, dept2, poc_dept1, poc_dept2, poc_both, job1, job2,
            volunteer])
        session.commit()
        assert volunteer.must_contact == '(Dept1) Poc Both / Poc Dept1<br/>(Dept2) Poc Both / Poc Dept2'
예제 #2
0
def time_conflicts(job):
    if not job.is_new:
        original_hours = Job(start_time=job.orig_value_of('start_time'), duration=job.orig_value_of('duration')).hours
        for shift in job.shifts:
            if job.hours.intersection(shift.attendee.hours - original_hours):
                return 'You cannot change this job to this time, because {} is already working a shift then'.format(
                    shift.attendee.full_name)
예제 #3
0
def import_jobs(session):
    job_locs, _ = zip(*c.JOB_LOCATION_OPTS)
    for j in dump['jobs']:
        if j['location'] in job_locs:
            j.pop('restricted', '')
            j['department_id'] = _dept_id_from_location(j.pop('location', ''))
            j['start_time'] = offset_to_datetime(j['start_time'])
            shifts = j.pop('shifts')
            job = Job(**j)
            session.add(job)
            for secret_id in shifts:
                job.shifts.append(Shift(attendee=attendees[secret_id]))
예제 #4
0
def test_must_contact():
    dept1 = Department(name='Dept1', description='Dept1')
    dept2 = Department(name='Dept2', description='Dept2')

    poc_dept1 = Attendee(
        paid=c.NEED_NOT_PAY, first_name='Poc', last_name='Dept1')
    poc_dept2 = Attendee(
        paid=c.NEED_NOT_PAY, first_name='Poc', last_name='Dept2')
    poc_both = Attendee(
        paid=c.NEED_NOT_PAY, first_name='Poc', last_name='Both')

    poc_dept1.dept_memberships = [DeptMembership(
        department=dept1,
        is_poc=True)]

    poc_dept2.dept_memberships = [DeptMembership(
        department=dept2,
        is_poc=True)]

    poc_both.dept_memberships = [
        DeptMembership(
            department=dept1,
            is_poc=True),
        DeptMembership(
            department=dept2,
            is_poc=True)]

    start_time = datetime.now(tz=pytz.UTC)

    job1 = Job(
        name='Job1',
        description='Job1',
        start_time=start_time,
        duration=1,
        weight=1,
        slots=1,
        department=dept1)

    job2 = Job(
        name='Job2',
        description='Job2',
        start_time=start_time,
        duration=1,
        weight=1,
        slots=1,
        department=dept2)

    volunteer = Attendee(paid=c.HAS_PAID, first_name='V', last_name='One')

    job1.shifts = [Shift(attendee=volunteer, job=job1)]
    job2.shifts = [Shift(attendee=volunteer, job=job2)]

    with Session() as session:
        session.add_all([
            dept1, dept2, poc_dept1, poc_dept2, poc_both, job1, job2,
            volunteer])
        session.commit()
        assert volunteer.must_contact == '(Dept1) Poc Both / Poc Dept1<br/>(Dept2) Poc Both / Poc Dept2'
def import_jobs(session):
    job_locs, _ = zip(*c.JOB_LOCATION_OPTS)
    depts_known = []
    for j in dump['jobs']:
        if j['location'] in job_locs:
            j.pop('restricted', '')
            location = j.pop('location', '')
            dept_id = _dept_id_from_location(location)
            j['department_id'] = dept_id
            if dept_id not in depts_known and not session.query(Department).filter(Department.id == dept_id).count():
                session.add(Department(id=dept_id, name=location))
                depts_known.append(dept_id)
            j['start_time'] = offset_to_datetime(j['start_time'])
            shifts = j.pop('shifts')
            job = Job(**j)
            session.add(job)
            for secret_id in shifts:
                if secret_id not in skipped_attendees:
                    job.shifts.append(Shift(attendee=attendees[secret_id]))
예제 #6
0
def _copy_department_shifts(service, to_department, from_department, dept_role_map):
    from_config = service.config.info()
    FROM_EPOCH = c.EVENT_TIMEZONE.localize(datetime.strptime(from_config['EPOCH'], '%Y-%m-%d %H:%M:%S.%f'))
    EPOCH_DELTA = c.EPOCH - FROM_EPOCH

    for from_job in from_department['jobs']:
        to_job = Job(
            name=from_job['name'],
            description=from_job['description'],
            duration=from_job['duration'],
            type=from_job['type'],
            extra15=from_job['extra15'],
            slots=from_job['slots'],
            start_time=UTC.localize(dateparser.parse(from_job['start_time'])) + EPOCH_DELTA,
            visibility=from_job['visibility'],
            weight=from_job['weight'],
            department_id=to_department.id)
        for from_required_role in from_job['required_roles']:
            to_job.required_roles.append(dept_role_map[from_required_role['id']])
        to_department.jobs.append(to_job)
예제 #7
0
def init_db(request):
    if os.path.exists(TEST_DB_FILE):
        os.remove(TEST_DB_FILE)
    patch_session(Session, request)
    initialize_db(modify_tables=True)
    register_session_listeners()
    with Session() as session:
        session.add(
            Attendee(placeholder=True,
                     first_name='Regular',
                     last_name='Volunteer',
                     ribbon=c.VOLUNTEER_RIBBON,
                     staffing=True))
        session.add(
            Attendee(placeholder=True,
                     first_name='Regular',
                     last_name='Attendee'))

        d_arcade_trusted_dept_role = DeptRole(name='Trusted',
                                              description='Trusted in Arcade')
        d_arcade = Department(name='Arcade',
                              description='Arcade',
                              dept_roles=[d_arcade_trusted_dept_role])

        d_console_trusted_dept_role = DeptRole(
            name='Trusted', description='Trusted in Console')
        d_console = Department(name='Console',
                               description='Console',
                               dept_roles=[d_console_trusted_dept_role])
        session.add_all([
            d_arcade, d_arcade_trusted_dept_role, d_console,
            d_console_trusted_dept_role
        ])

        assigned_depts = {
            'One': [d_arcade],
            'Two': [d_console],
            'Three': [d_arcade, d_console],
            'Four': [d_arcade, d_console],
            'Five': []
        }
        trusted_depts = {
            'One': [],
            'Two': [],
            'Three': [],
            'Four': [d_arcade, d_console],
            'Five': []
        }

        for name in ['One', 'Two', 'Three', 'Four', 'Five']:
            dept_memberships = []
            for dept in assigned_depts[name]:
                is_trusted = dept in trusted_depts[name]
                dept_memberships.append(
                    DeptMembership(
                        department_id=dept.id,
                        dept_roles=(dept.dept_roles if is_trusted else [])))
            session.add_all(dept_memberships)

            session.add(
                Attendee(placeholder=True,
                         first_name=name,
                         last_name=name,
                         paid=c.NEED_NOT_PAY,
                         badge_type=c.STAFF_BADGE,
                         dept_memberships=dept_memberships))

            session.add(
                Attendee(placeholder=True,
                         first_name=name,
                         last_name=name,
                         paid=c.NEED_NOT_PAY,
                         badge_type=c.SUPPORTER_BADGE))
            session.commit()

        session.add(
            WatchList(first_names='Banned, Alias, Nickname',
                      last_name='Attendee',
                      email='*****@*****.**',
                      birthdate=date(1980, 7, 10),
                      action='Action',
                      reason='Reason'))

        session.add(
            Job(name='Job One',
                start_time=c.EPOCH,
                slots=1,
                weight=1,
                duration=2,
                department=d_arcade,
                extra15=True))
        session.add(
            Job(name='Job Two',
                start_time=c.EPOCH + timedelta(hours=1),
                slots=1,
                weight=1,
                duration=2,
                department=d_arcade))
        session.add(
            Job(name='Job Three',
                start_time=c.EPOCH + timedelta(hours=2),
                slots=1,
                weight=1,
                duration=2,
                department=d_arcade))
        session.add(
            Job(name='Job Four',
                start_time=c.EPOCH,
                slots=2,
                weight=1,
                duration=2,
                department=d_console,
                extra15=True))
        session.add(
            Job(name='Job Five',
                start_time=c.EPOCH + timedelta(hours=2),
                slots=1,
                weight=1,
                duration=2,
                department=d_console))
        session.add(
            Job(name='Job Six',
                start_time=c.EPOCH,
                slots=1,
                weight=1,
                duration=2,
                department=d_console,
                required_roles=[d_console_trusted_dept_role]))

        session.add(
            PromoCode(code='ten percent off',
                      discount=10,
                      discount_type=PromoCode._PERCENT_DISCOUNT))
        session.add(
            PromoCode(code='ten dollars off',
                      discount=10,
                      discount_type=PromoCode._FIXED_DISCOUNT))
        session.add(
            PromoCode(code='ten dollar badge',
                      discount=10,
                      discount_type=PromoCode._FIXED_PRICE))
        session.add(PromoCode(code='free badge', discount=0, uses_allowed=100))

        session.commit()
예제 #8
0
    def shifts(self,
               session,
               target_server='',
               api_token='',
               to_department_id='',
               from_department_id='',
               message='',
               **kwargs):

        target_url, target_host, remote_api_token = _format_import_params(
            target_server, api_token)
        uri = '{}/jsonrpc/'.format(target_url)

        message = ''
        service = None
        if target_server or api_token:
            if not remote_api_token:
                message = 'No API token given and could not find a token for: {}'.format(
                    target_host)
            elif not target_url:
                message = 'Unrecognized hostname: {}'.format(target_server)

            if not message:
                service = ServerProxy(
                    uri=uri, extra_headers={'X-Auth-Token': remote_api_token})

        department = {}
        from_departments = []
        if not message and service:
            from_departments = [(id, name) for id, name in sorted(
                service.dept.list().items(), key=lambda d: d[1])]
            if cherrypy.request.method == 'POST':
                from_department = service.dept.jobs(
                    department_id=from_department_id)
                to_department = session.query(Department).get(to_department_id)
                from_config = service.config.info()
                FROM_EPOCH = c.EVENT_TIMEZONE.localize(
                    datetime.strptime(from_config['EPOCH'],
                                      '%Y-%m-%d %H:%M:%S.%f'))
                EPOCH_DELTA = c.EPOCH - FROM_EPOCH

                to_dept_roles_by_id = to_department.dept_roles_by_id
                to_dept_roles_by_name = to_department.dept_roles_by_name
                dept_role_map = {}
                for from_dept_role in from_department['dept_roles']:
                    to_dept_role = to_dept_roles_by_id.get(
                        from_dept_role['id'], [None])[0]
                    if not to_dept_role:
                        to_dept_role = to_dept_roles_by_name.get(
                            from_dept_role['name'], [None])[0]
                    if not to_dept_role:
                        to_dept_role = DeptRole(
                            name=from_dept_role['name'],
                            description=from_dept_role['description'],
                            department_id=to_department.id)
                        to_department.dept_roles.append(to_dept_role)
                    dept_role_map[from_dept_role['id']] = to_dept_role

                for from_job in from_department['jobs']:
                    to_job = Job(
                        name=from_job['name'],
                        description=from_job['description'],
                        duration=from_job['duration'],
                        type=from_job['type'],
                        extra15=from_job['extra15'],
                        slots=from_job['slots'],
                        start_time=UTC.localize(
                            dateparser.parse(from_job['start_time'])) +
                        EPOCH_DELTA,
                        visibility=from_job['visibility'],
                        weight=from_job['weight'],
                        department_id=to_department.id)
                    for from_required_role in from_job['required_roles']:
                        to_job.required_roles.append(
                            dept_role_map[from_required_role['id']])
                    to_department.jobs.append(to_job)

                message = '{} shifts successfully imported from {}'.format(
                    to_department.name, uri)
                raise HTTPRedirect(
                    'shifts?target_server={}&api_token={}&message={}',
                    target_server, api_token, message)

        return {
            'target_server': target_server,
            'target_url': uri,
            'api_token': api_token,
            'department': department,
            'to_departments': c.DEPARTMENT_OPTS,
            'from_departments': from_departments,
            'message': message,
        }
예제 #9
0
def job(): return Job()


@pytest.fixture
예제 #10
0
def test_hours():
    assert Job(start_time=c.EPOCH, duration=1).hours == {c.EPOCH}
    assert Job(start_time=c.EPOCH,
               duration=2).hours == {c.EPOCH, c.EPOCH + timedelta(hours=1)}
예제 #11
0
def test_total_hours(monkeypatch):
    monkeypatch.setattr(Job, 'weighted_hours', 3)
    assert Job(slots=1).total_hours == 3
    assert Job(slots=2).total_hours == 6
예제 #12
0
def test_weighted_hours(monkeypatch):
    monkeypatch.setattr(Job, 'real_duration', 2)
    assert Job(weight=1).weighted_hours == 2
    assert Job(weight=1.5).weighted_hours == 3
    assert Job(weight=2).weighted_hours == 4
예제 #13
0
def test_real_duration():
    assert Job(duration=2).real_duration == 2
    assert Job(duration=2, extra15=True).real_duration == 2.25