示例#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 test_requested_any_dept():
    dept1 = Department(name='Dept1', description='Dept1')
    dept2 = Department(name='Dept2', description='Dept2')
    volunteer = Attendee(paid=c.HAS_PAID, first_name='V', last_name='One')
    volunteer.dept_membership_requests = [
        DeptMembershipRequest(attendee=volunteer)]

    with Session() as session:
        session.add_all([dept1, dept2, volunteer])
        session.commit()
        session.refresh(volunteer)
        all_depts = session.query(Department).order_by(Department.name).all()
        assert all_depts == volunteer.requested_depts
示例#3
0
def _create_copy_department(from_department):
    to_department = Department()
    for field in ['name', 'description', 'solicits_volunteers', 'is_shiftless',
                  'is_setup_approval_exempt', 'is_teardown_approval_exempt', 'max_consecutive_hours']:
        if field in from_department:
            setattr(to_department, field, from_department[field])
    return to_department
示例#4
0
        def _guess_dept(id_name):
            id, name = id_name
            if id in depts:
                return (id, depts[id])

            dept = session.query(Department).filter(or_(
                Department.id == id,
                Department.normalized_name == Department.normalize_name(name))).first()

            if dept:
                depts[id] = dept
                return (id, dept)
            return None
示例#5
0
def _create_copy_department(from_department):
    to_department = Department()
    for field in [
            'name', 'description', 'solicits_volunteers', 'is_shiftless',
            'is_setup_approval_exempt', 'is_teardown_approval_exempt',
            'max_consecutive_minutes'
    ]:
        if field in from_department:
            setattr(to_department, field, from_department[field])

        # Convert old years' max hours to minutes, this can eventually be removed
        if 'max_consecutive_hours' in from_department:
            setattr(to_department, 'max_consecutive_minutes',
                    int(from_department['max_consecutive_hours']) * 60)
    return to_department
示例#6
0
def match_to_group_preconditions():
    group_id = None
    # leader_id = None
    with Session() as session:
        console = Department(name='Console_01', description='Console_01')
        leader = Attendee(
            first_name='Fearless',
            last_name='Leader',
            email='*****@*****.**',
            zip_code='21211',
            ec_name='Nana Fearless',
            ec_phone='555-555-1234',
            cellphone='555-555-2345',
            birthdate=date(1964, 12, 30),
            registered=localized_now(),
            paid=c.PAID_BY_GROUP,
            badge_type=c.STAFF_BADGE,
            badge_printed_name='Fearmore',
            ribbon='',
            staffing=True,
            assigned_depts=[console])

        group = Group(name='Too Many Badges!')
        group.auto_recalc = False
        group.attendees = [leader]
        group.leader = leader
        session.add(leader)
        session.add(group)
        assert session.assign_badges(
            group,
            4,
            new_badge_type=c.STAFF_BADGE,
            new_ribbon_type='',
            paid=c.PAID_BY_GROUP) is None
        session.flush()

        group_id = group.id
        # leader_id = leader.id

    yield group_id

    with Session() as session:
        session.query(Group).filter(Group.id == group_id).delete(
            synchronize_session=False)
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]))
示例#8
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()
示例#9
0
def shiftless_dept():
    yield Department(
        id='27152595-2ea8-43ee-8edb-a68cefb2b2ac',
        name='Con Ops',
        description='Con Ops',
        is_shiftless=True)
示例#10
0
def dept():
    yield Department(
        id='97cc0050-11e0-42eb-9a1b-83f27a1acf76',
        name='Console Challenges',
        description='Console Challenges')
示例#11
0
def duplicate_badge_num_preconditions():
    group_id = None
    leader_id = None
    with Session() as session:
        leader = Attendee(first_name='Fearless',
                          last_name='Leader',
                          email='*****@*****.**',
                          zip_code='21211',
                          ec_name='Nana Fearless',
                          ec_phone='555-555-1234',
                          cellphone='555-555-2345',
                          birthdate=date(1964, 12, 30),
                          registered=localized_now(),
                          paid=c.PAID_BY_GROUP,
                          ribbon='',
                          staffing=True,
                          badge_type=c.PSEUDO_GROUP_BADGE)

        group = Group(name='Too Many Badges!')
        group.attendees = [leader]
        group.leader = leader
        session.add(leader)
        session.add(group)
        assert session.assign_badges(group,
                                     15,
                                     new_badge_type=c.STAFF_BADGE,
                                     new_ribbon_type='',
                                     paid=c.NEED_NOT_PAY) is None
        session.flush()

        group_id = group.id
        leader_id = leader.id

    with Session() as session:
        console = Department(name='DEPT_01', description='DEPT_01')
        leader = session.query(Attendee).get(leader_id)
        leader.paid = c.NEED_NOT_PAY
        leader.badge_printed_name = 'Fearmore'
        leader.badge_type = c.STAFF_BADGE
        leader.assigned_depts = [console]

        group = session.query(Group).get(group_id)
        group.auto_recalc = False

    for i in range(10):
        with Session() as session:
            console = session.query(Department).filter_by(name='DEPT_01').one()
            group = session.query(Group).get(group_id)

            is_staff = (i < 9)
            params = {
                'first_name': 'Doubtful',
                'last_name': 'Follower{}'.format(i),
                'email': 'fearsome{}@example.com'.format(i),
                'zip_code': '21211',
                'ec_name': 'Nana Fearless',
                'ec_phone': '555-555-1234',
                'cellphone': '555-555-321{}'.format(i),
                'birthdate': date(1964, 12, 30),
                'registered': localized_now(),
                'staffing': is_staff,
                'badge_status': str(c.COMPLETED_STATUS),
                'badge_printed_name': 'Fears{}'.format(i) if is_staff else '',
                'assigned_depts': [console] if is_staff else ''
            }

            attendee = group.unassigned[0]
            attendee.apply(params, restricted=False)

        with Session() as session:
            group = session.query(Group).get(group_id)
            badge_nums = [a.badge_num for a in group.attendees]
            # SQLite doesn't support deferred constraints, so our test database
            # doesn't actually have a unique constraint on the badge_num
            # column. So we have to manually check for duplicate badge numbers.
            assert_unique(badge_nums)

    yield group_id

    with Session() as session:
        session.query(Group).filter(Group.id == group_id).delete(
            synchronize_session=False)