示例#1
0
def test_new_extra():
    assert 0 == Group().amount_extra
    assert 20 == Group(attendees=[Attendee(paid=c.PAID_BY_GROUP, amount_extra=20)]).amount_extra
    assert 30 == Group(attendees=[
        Attendee(paid=c.PAID_BY_GROUP, amount_extra=10),
        Attendee(paid=c.PAID_BY_GROUP, amount_extra=20)
    ]).amount_extra
示例#2
0
def test_amount_unpaid(monkeypatch):
    assert 0 == Group(registered=datetime.now(UTC)).amount_unpaid
    assert 222 == Group(registered=datetime.now(UTC), cost=222).amount_unpaid
    assert 111 == Group(registered=datetime.now(UTC), cost=222, amount_paid=111).amount_unpaid
    assert 0 == Group(registered=datetime.now(UTC), cost=222, amount_paid=222).amount_unpaid
    monkeypatch.setattr(Group, 'default_cost', 333)
    assert 333 == Group().amount_unpaid
示例#3
0
def test_badges_purchased():
    assert 0 == Group().badges_purchased
    assert 0 == Group(attendees=[Attendee()]).badges_purchased
    assert 1 == Group(attendees=[Attendee(paid=c.PAID_BY_GROUP)]).badges_purchased
    assert 2 == Group(attendees=[
        Attendee(paid=c.PAID_BY_GROUP), Attendee(paid=c.PAID_BY_GROUP),
        Attendee(paid=c.NOT_PAID), Attendee(paid=c.HAS_PAID), Attendee(paid=c.REFUNDED), Attendee(paid=c.NEED_NOT_PAY)
    ]).badges_purchased
示例#4
0
def test_group_badge_status_cascade():
    g = Group(cost=0, auto_recalc=False)
    taken = Attendee(
        group_id=g.id, paid=c.PAID_BY_GROUP, badge_status=c.NEW_STATUS, first_name='Liam', last_name='Neeson')
    floating = Attendee(group_id=g.id, paid=c.PAID_BY_GROUP, badge_status=c.NEW_STATUS)
    g.attendees = [taken, floating]
    g.presave_adjustments()
    assert taken.badge_status == c.COMPLETED_STATUS and floating.badge_status == c.NEW_STATUS
示例#5
0
def test_email():
    assert not Group().email
    assert not Group(attendees=[Attendee()]).email
    assert '[email protected]' == Group(attendees=[Attendee(email='[email protected]')]).email
    assert not Group(attendees=[Attendee(email='[email protected]'), Attendee(email='[email protected]')]).email

    assert not Group(leader=Attendee()).email
    assert '[email protected]' == Group(leader=Attendee(email='[email protected]')).email
    assert '[email protected]' == Group(leader=Attendee(email='[email protected]'), attendees=[Attendee(email='[email protected]')]).email
    assert '[email protected]' == Group(
        leader=Attendee(email='[email protected]'), attendees=[Attendee(email='[email protected]'), Attendee(email='[email protected]')]).email

    assert '[email protected]' == Group(leader=Attendee(), attendees=[Attendee(email='[email protected]')]).email
    assert not Group(leader=Attendee(), attendees=[Attendee(email='[email protected]'), Attendee(email='[email protected]')]).email
    def test_free_dealer_no_app(self):
        session = Session().session
        with request_cached_context():
            session.add(Group(tables=1, cost=0, auto_recalc=False, status=c.UNAPPROVED))
            session.commit()

        assert c.DEALER_APPS == 0
示例#7
0
def test_assign_extra_create_arguments(session):
    group = Group()
    registered = localized_now()
    session.assign_badges(group, 2, registered=registered)
    assert 2 == group.badges == len(group.attendees)
    for attendee in group.attendees:
        assert attendee.registered == registered
示例#8
0
def test_badge_cost(monkeypatch, clear_price_bumps):
    monkeypatch.setattr(c, 'get_group_price', Mock(return_value=c.DEALER_BADGE_PRICE + 10))
    assert 4 * c.DEALER_BADGE_PRICE + 20 == Group(attendees=[
        Attendee(paid=c.REFUNDED), Attendee(ribbon=c.DEALER_RIBBON),
        Attendee(paid=c.PAID_BY_GROUP), Attendee(paid=c.PAID_BY_GROUP),
        Attendee(paid=c.PAID_BY_GROUP, ribbon=c.DEALER_RIBBON), Attendee(paid=c.PAID_BY_GROUP, ribbon=c.DEALER_RIBBON)
    ]).badge_cost
def import_groups(session):
    for g in dump['groups']:
        secret_id = g.pop('secret_id')
        g['cost'] = int(float(g.pop('amount_owed')))
        g['name'] = random_group_name()
        groups[secret_id] = Group(**g)
        session.add(groups[secret_id])
示例#10
0
    def test_waitlisted_dealer_not_app(self):
        session = Session().session
        with request_cached_context():
            session.add(Group(tables=1, cost=10, status=c.WAITLISTED))
            session.commit()

        assert c.DEALER_APPS == 0
示例#11
0
    def test_not_a_dealer_no_app(self):
        session = Session().session
        with request_cached_context():
            session.add(Group(tables=0, cost=10, status=c.UNAPPROVED))
            session.commit()

        assert c.DEALER_APPS == 0
示例#12
0
def test_self_service_refunds_group_leader(monkeypatch):
    monkeypatch.setattr(config.Config, 'SELF_SERVICE_REFUNDS_OPEN',
                        property(lambda s: True))
    attendee = Attendee(paid=c.HAS_PAID, amount_paid=10)
    attendee.group = Group(leader_id=attendee.id)
    txn = StripeTransaction(amount=1000)
    attendee.stripe_txn_share_logs = [
        StripeTransactionAttendee(attendee_id=attendee.id, txn_id=txn.id, share=1000)]
    assert not attendee.can_self_service_refund_badge
示例#13
0
def test_is_dealer():
    assert not Attendee().is_dealer
    assert Attendee(ribbon=c.DEALER_RIBBON).is_dealer
    assert Attendee(badge_type=c.PSEUDO_DEALER_BADGE).is_dealer

    # not all attendees in a dealer group are necessarily dealers
    dealer_group = Group(tables=1)
    assert not Attendee(group=dealer_group).is_dealer
    assert Attendee(group=dealer_group, paid=c.PAID_BY_GROUP).is_dealer
示例#14
0
 def repurchase(self, session, id, **params):
     if 'csrf_token' in params:
         new_attendee = Attendee(
             **session.attendee(id).to_dict(c.UNTRANSFERABLE_ATTRS))
         Charge.unpaid_preregs[new_attendee.id] = to_sessionized(
             new_attendee, Group())
         Tracking.track(c.UNPAID_PREREG, new_attendee)
         raise HTTPRedirect("form?edit_id={}", new_attendee.id)
     return {'id': id}
示例#15
0
def test_assign_new_badges(session, monkeypatch):
    monkeypatch.setattr(Group, 'new_ribbon', 111)
    group = Group()
    session.assign_badges(group, '2', 222)
    assert 2 == group.badges == len(group.attendees)
    for attendee in group.attendees:
        assert attendee.paid == c.PAID_BY_GROUP
        assert attendee.ribbon == 111
        assert attendee.badge_type == 222
示例#16
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)
示例#17
0
def test_approved_presave_adjustment():
    g = Group()
    g.presave_adjustments()
    assert g.approved is None

    g.status = c.APPROVED
    g.presave_adjustments()
    assert g.approved is not None
示例#18
0
def test_table_cost():
    assert 0 == Group().table_cost
    assert 100 == Group(tables=1).table_cost
    assert 300 == Group(tables=2).table_cost
    assert 600 == Group(tables=3).table_cost
    assert 1000 == Group(tables=4).table_cost
    assert 1400 == Group(tables=5).table_cost
    assert 1800 == Group(tables=6).table_cost
示例#19
0
 def test_unpaid_group_not_completed(self, monkeypatch):
     monkeypatch.setattr(Group, 'amount_unpaid', 100)
     g = Group()
     a = Attendee(paid=c.PAID_BY_GROUP,
                  badge_status=c.NEW_STATUS,
                  first_name='Paid',
                  placeholder=False,
                  group=g)
     a._status_adjustments()
     assert a.badge_status == c.NEW_STATUS
示例#20
0
 def test_promo_code_does_not_help_dealer(self, monkeypatch):
     promo_code = PromoCode(discount=1, expiration_date=next_week)
     attendee = Attendee(badge_type=c.PSEUDO_DEALER_BADGE,
                         group=Group(),
                         cellphone='555-555-1234',
                         promo_code=promo_code,
                         placeholder=True,
                         first_name='First',
                         last_name='Last')
     assert check(attendee, prereg=True) == \
         "You can't apply a promo code to a dealer registration."
示例#21
0
 def test_charge_log_transaction_no_unpaid(self, monkeypatch):
     group = Group()
     monkeypatch.setattr(Group, 'amount_unpaid', 0)
     charge = Charge(targets=[group], amount=1000,
                     description="Test charge")
     charge.response = stripe.Charge(id=10)
     txn = charge.stripe_transaction_from_charge()
     result = charge.stripe_transaction_for_model(group, txn)
     assert result.group_id == group.id
     assert result.txn_id == txn.id
     assert result.share == 1000
示例#22
0
    def test_set_group_paid_to_complete(self, monkeypatch):
        monkeypatch.setattr(Group, 'amount_unpaid', 0)
        g = Group()
        a = Attendee(paid=c.PAID_BY_GROUP,
                     badge_status=c.NEW_STATUS,
                     first_name='Paid',
                     placeholder=False,
                     group=g,
                     group_id=g.id)

        a._status_adjustments()
        assert a.badge_status == c.COMPLETED_STATUS
示例#23
0
def test_assign_removing_badges(monkeypatch, session):
    monkeypatch.setattr(Attendee, 'registered', datetime.now(UTC))
    attendees = [
        Attendee(paid=c.PAID_BY_GROUP),
        Attendee(first_name='x'),
        Attendee(paid=c.HAS_PAID),
        Attendee(paid=c.PAID_BY_GROUP)]
    group = Group(attendees=attendees)
    session.assign_badges(group, 2)
    assert group.badges == 2
    assert session.delete.call_count == 2
    session.delete.assert_any_call(attendees[0])
    session.delete.assert_any_call(attendees[3])
示例#24
0
 def _get_unsaved(self, id, if_not_found=None):
     """
     if_not_found:  pass in an HTTPRedirect() class to raise if the unsaved attendee is not found.
                    by default we will redirect to the index page
     """
     if id in Charge.unpaid_preregs:
         target = Charge.from_sessionized(Charge.unpaid_preregs[id])
         if isinstance(target, Attendee):
             return target, Group()
         else:
             [leader] = [a for a in target.attendees if not a.is_unassigned]
             return leader, target
     else:
         raise HTTPRedirect(
             'index') if if_not_found is None else if_not_found
示例#25
0
def test_group_email(monkeypatch):
    monkeypatch.setattr(Email, 'fk', Group(leader=Attendee(email="*****@*****.**")))
    assert "*****@*****.**" == Email(model='Group').rcpt_email
示例#26
0
def test_group_name(monkeypatch):
    monkeypatch.setattr(Email, 'fk', Group(leader=Attendee(first_name="Test", last_name="Leader")))
    assert "Test Leader" == Email(model='Group').rcpt_name
示例#27
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)
示例#28
0
def test_cost_presave_adjustment():
    g = Group(cost=123, auto_recalc=False)
    g.presave_adjustments()
    assert g.cost == 123

    g.auto_recalc = True
    g.presave_adjustments()
    assert g.cost == 0

    g.auto_recalc = False
    g.cost = ''
    g.presave_adjustments()
    assert g.cost == 0

    g.auto_recalc = False
    g.cost = 10
    g.presave_adjustments()
    assert g.cost == 10

    g.amount_paid = ''
    g.presave_adjustments()
    assert g.amount_paid == 0

    g.amount_refunded = ''
    g.presave_adjustments()
    assert g.amount_refunded == 0
示例#29
0
def test_is_unpaid():
    assert not Group().is_unpaid
    assert not Group(amount_paid=1).is_unpaid
    assert not Group(amount_paid=1, cost=1).is_unpaid
    assert Group(cost=1).is_unpaid
示例#30
0
    def form(self, session, message='', edit_id=None, **params):
        """
        Our production NGINX config caches the page at /preregistration/form.
        Since it's cached, we CAN'T return a session cookie with the page. We
        must POST to a different URL in order to bypass the cache and get a
        valid session cookie. Thus, this page is also exposed as "post_form".
        """
        params['id'] = 'None'   # security!
        group = Group()

        if edit_id is not None:
            attendee = self._get_unsaved(
                edit_id,
                if_not_found=HTTPRedirect('form?message={}', 'That preregistration has already been finalized'))
            attendee.apply(params, restricted=True)
            params.setdefault('pii_consent', True)
        else:
            attendee = session.attendee(params, ignore_csrf=True, restricted=True)

            if attendee.badge_type == c.PSEUDO_DEALER_BADGE:
                if not c.DEALER_REG_OPEN:
                    return render('static_views/dealer_reg_closed.html') if c.AFTER_DEALER_REG_START \
                        else render('static_views/dealer_reg_not_open.html')

                # Both the Attendee class and Group class have identically named
                # address fields. In order to distinguish the two sets of address
                # fields in the params, the Group fields are prefixed with "group_"
                # when the form is submitted. To prevent instantiating the Group object
                # with the Attendee's address fields, we must clone the params and
                # rename all the "group_" fields.
                group_params = dict(params)
                for field_name in ['country', 'region', 'zip_code', 'address1', 'address2', 'city']:
                    group_params[field_name] = params.get('group_{}'.format(field_name), '')
                    if params.get('copy_address'):
                        params[field_name] = group_params[field_name]
                        attendee.apply(params)

                group = session.group(group_params, ignore_csrf=True, restricted=True)

        if c.PAGE == 'post_dealer':
            attendee.badge_type = c.PSEUDO_DEALER_BADGE
        elif not attendee.badge_type:
            attendee.badge_type = c.ATTENDEE_BADGE

        if cherrypy.request.method == 'POST' or edit_id is not None:
            message = check_pii_consent(params, attendee) or message
            if not message and attendee.badge_type not in c.PREREG_BADGE_TYPES:
                message = 'Invalid badge type!'
            if not message and c.BADGE_PROMO_CODES_ENABLED and params.get('promo_code'):
                if session.lookup_promo_or_group_code(params.get('promo_code'), PromoCodeGroup):
                    Charge.universal_promo_codes[attendee.id] = params.get('promo_code')
                message = session.add_promo_code_to_attendee(attendee, params.get('promo_code'))

        if message:
            return {
                'message':    message,
                'attendee':   attendee,
                'group':      group,
                'edit_id':    edit_id,
                'affiliates': session.affiliates(),
                'cart_not_empty': Charge.unpaid_preregs,
                'copy_address': params.get('copy_address'),
                'promo_code_code': params.get('promo_code', ''),
                'pii_consent': params.get('pii_consent'),
                'name': params.get('name', ''),
                'badges': params.get('badges', 0),
            }

        if 'first_name' in params:
            if attendee.badge_type == c.PSEUDO_DEALER_BADGE:
                message = check(group, prereg=True)

            message = message or check(attendee, prereg=True)

            if attendee.badge_type in [c.PSEUDO_GROUP_BADGE, c.PSEUDO_DEALER_BADGE]:
                message = "Please enter a group name" if not params.get('name') else message
            else:
                params['badges'] = 0
                params['name'] = ''

            if not message:
                if attendee.badge_type == c.PSEUDO_DEALER_BADGE:
                    attendee.paid = c.PAID_BY_GROUP
                    group.attendees = [attendee]
                    session.assign_badges(group, params['badges'])
                    group.status = c.WAITLISTED if c.DEALER_REG_SOFT_CLOSED else c.UNAPPROVED
                    attendee.ribbon = add_opt(attendee.ribbon_ints, c.DEALER_RIBBON)
                    attendee.badge_type = c.ATTENDEE_BADGE

                    session.add_all([attendee, group])
                    session.commit()
                    try:
                        send_email.delay(
                            c.MARKETPLACE_EMAIL,
                            c.MARKETPLACE_EMAIL,
                            '{} Received'.format(c.DEALER_APP_TERM.title()),
                            render('emails/dealers/reg_notification.txt', {'group': group}, encoding=None),
                            model=group.to_dict('id'))
                        send_email.delay(
                            c.MARKETPLACE_EMAIL,
                            attendee.email,
                            '{} Received'.format(c.DEALER_APP_TERM.title()),
                            render('emails/dealers/application.html', {'group': group}, encoding=None),
                            'html',
                            model=group.to_dict('id'))
                    except Exception:
                        log.error('unable to send marketplace application confirmation email', exc_info=True)
                    raise HTTPRedirect('dealer_confirmation?id={}', group.id)
                else:
                    track_type = c.UNPAID_PREREG
                    if attendee.id in Charge.unpaid_preregs:
                        track_type = c.EDITED_PREREG
                        # Clear out any previously cached targets, in case the unpaid badge
                        # has been edited and changed from a single to a group or vice versa.
                        del Charge.unpaid_preregs[attendee.id]

                    Charge.unpaid_preregs[attendee.id] = Charge.to_sessionized(attendee,
                                                                               params.get('name'),
                                                                               params.get('badges'))
                    Tracking.track(track_type, attendee)

                if session.attendees_with_badges().filter_by(
                        first_name=attendee.first_name, last_name=attendee.last_name, email=attendee.email).count():

                    raise HTTPRedirect('duplicate?id={}', group.id if attendee.paid == c.PAID_BY_GROUP else attendee.id)

                if attendee.banned:
                    raise HTTPRedirect('banned?id={}', group.id if attendee.paid == c.PAID_BY_GROUP else attendee.id)

                if c.PREREG_REQUEST_HOTEL_INFO_OPEN:
                    hotel_page = 'hotel?edit_id={}' if edit_id else 'hotel?id={}'
                    raise HTTPRedirect(hotel_page, group.id if attendee.paid == c.PAID_BY_GROUP else attendee.id)
                else:
                    raise HTTPRedirect('index')

        else:
            if edit_id is None:
                if attendee.badge_type == c.PSEUDO_DEALER_BADGE:
                    # All new dealer signups should default to receiving the
                    # hotel info email, even if the deadline has passed.
                    # There's a good chance some dealers will apply for a table
                    # AFTER the hotel booking deadline, but BEFORE the hotel
                    # booking is sent out. This ensures they'll still receive
                    # the email, as requested by the Marketplace Department.
                    attendee.requested_hotel_info = True

            if attendee.badge_type == c.PSEUDO_DEALER_BADGE and c.DEALER_REG_SOFT_CLOSED:
                message = '{} is closed, but you can ' \
                    'fill out this form to add yourself to our waitlist'.format(c.DEALER_REG_TERM.title())

        promo_code_group = None
        if attendee.promo_code:
            promo_code_group = session.query(PromoCode).filter_by(code=attendee.promo_code.code).first().group

        return {
            'message':    message,
            'attendee':   attendee,
            'badges': params.get('badges', 0),
            'name': params.get('name', ''),
            'group':      group,
            'promo_code_group': promo_code_group,
            'edit_id':    edit_id,
            'affiliates': session.affiliates(),
            'cart_not_empty': Charge.unpaid_preregs,
            'copy_address': params.get('copy_address'),
            'promo_code_code': params.get('promo_code', ''),
            'pii_consent': params.get('pii_consent'),
        }
示例#31
0
    def form(self, session, message='', edit_id=None, **params):
        """
        Our production NGINX config caches the page at /preregistration/form.
        Since it's cached, we CAN'T return a session cookie with the page. We
        must POST to a different URL in order to bypass the cache and get a
        valid session cookie. Thus, this page is also exposed as "post_form".
        """
        params['id'] = 'None'   # security!
        group = Group()

        if edit_id is not None:
            attendee = self._get_unsaved(
                edit_id,
                if_not_found=HTTPRedirect('form?message={}', 'That preregistration has already been finalized'))
            attendee.apply(params, restricted=True)
            params.setdefault('pii_consent', True)
        else:
            attendee = session.attendee(params, ignore_csrf=True, restricted=True)

            if attendee.badge_type == c.PSEUDO_DEALER_BADGE:
                if not c.DEALER_REG_OPEN:
                    return render('static_views/dealer_reg_closed.html') if c.AFTER_DEALER_REG_START \
                        else render('static_views/dealer_reg_not_open.html')

                # Both the Attendee class and Group class have identically named
                # address fields. In order to distinguish the two sets of address
                # fields in the params, the Group fields are prefixed with "group_"
                # when the form is submitted. To prevent instantiating the Group object
                # with the Attendee's address fields, we must clone the params and
                # rename all the "group_" fields.
                group_params = dict(params)
                for field_name in ['country', 'region', 'zip_code', 'address1', 'address2', 'city']:
                    group_params[field_name] = params.get('group_{}'.format(field_name), '')
                    if params.get('copy_address'):
                        params[field_name] = group_params[field_name]

                group = session.group(group_params, ignore_csrf=True, restricted=True)

        if c.PAGE == 'post_dealer':
            attendee.badge_type = c.PSEUDO_DEALER_BADGE
        elif not attendee.badge_type:
            attendee.badge_type = c.ATTENDEE_BADGE

        if cherrypy.request.method == 'POST' or edit_id is not None:
            message = check_pii_consent(params, attendee) or message
            if not message and attendee.badge_type not in c.PREREG_BADGE_TYPES:
                message = 'Invalid badge type!'
            if not message and c.BADGE_PROMO_CODES_ENABLED and params.get('promo_code'):
                message = session.add_promo_code_to_attendee(attendee, params.get('promo_code'))

        if message:
            return {
                'message':    message,
                'attendee':   attendee,
                'group':      group,
                'edit_id':    edit_id,
                'affiliates': session.affiliates(),
                'cart_not_empty': Charge.unpaid_preregs,
                'copy_address': params.get('copy_address'),
                'promo_code': params.get('promo_code', ''),
                'pii_consent': params.get('pii_consent'),
            }

        if 'first_name' in params:
            message = check(attendee, prereg=True)
            if not message and attendee.badge_type == c.PSEUDO_DEALER_BADGE:
                message = check(group, prereg=True)

            if attendee.badge_type in [c.PSEUDO_GROUP_BADGE, c.PSEUDO_DEALER_BADGE]:
                message = "Please enter a group name" if not params.get('name') else ''
            else:
                params['badges'] = 0
                params['name'] = ''

            if not message:
                if attendee.badge_type == c.PSEUDO_DEALER_BADGE:
                    attendee.paid = c.PAID_BY_GROUP
                    group.attendees = [attendee]
                    session.assign_badges(group, params['badges'])
                    group.status = c.WAITLISTED if c.DEALER_REG_SOFT_CLOSED else c.UNAPPROVED
                    attendee.ribbon = add_opt(attendee.ribbon_ints, c.DEALER_RIBBON)
                    attendee.badge_type = c.ATTENDEE_BADGE

                    session.add_all([attendee, group])
                    session.commit()
                    try:
                        send_email.delay(
                            c.MARKETPLACE_EMAIL,
                            c.MARKETPLACE_EMAIL,
                            'Dealer Application Received',
                            render('emails/dealers/reg_notification.txt', {'group': group}, encoding=None),
                            model=group.to_dict('id'))
                        send_email.delay(
                            c.MARKETPLACE_EMAIL,
                            attendee.email,
                            'Dealer Application Received',
                            render('emails/dealers/application.html', {'group': group}, encoding=None),
                            'html',
                            model=group.to_dict('id'))
                    except Exception:
                        log.error('unable to send marketplace application confirmation email', exc_info=True)
                    raise HTTPRedirect('dealer_confirmation?id={}', group.id)
                else:
                    track_type = c.UNPAID_PREREG
                    if attendee.id in Charge.unpaid_preregs:
                        track_type = c.EDITED_PREREG
                        # Clear out any previously cached targets, in case the unpaid badge
                        # has been edited and changed from a single to a group or vice versa.
                        del Charge.unpaid_preregs[attendee.id]

                    Charge.unpaid_preregs[attendee.id] = Charge.to_sessionized(attendee,
                                                                               params.get('name'),
                                                                               params.get('badges'))
                    Tracking.track(track_type, attendee)

                if session.attendees_with_badges().filter_by(
                        first_name=attendee.first_name, last_name=attendee.last_name, email=attendee.email).count():

                    raise HTTPRedirect('duplicate?id={}', group.id if attendee.paid == c.PAID_BY_GROUP else attendee.id)

                if attendee.banned:
                    raise HTTPRedirect('banned?id={}', group.id if attendee.paid == c.PAID_BY_GROUP else attendee.id)

                if c.PREREG_REQUEST_HOTEL_INFO_OPEN:
                    hotel_page = 'hotel?edit_id={}' if edit_id else 'hotel?id={}'
                    raise HTTPRedirect(hotel_page, group.id if attendee.paid == c.PAID_BY_GROUP else attendee.id)
                else:
                    raise HTTPRedirect('index')

        else:
            if edit_id is None:
                if attendee.badge_type == c.PSEUDO_DEALER_BADGE:
                    # All new dealer signups should default to receiving the
                    # hotel info email, even if the deadline has passed.
                    # There's a good chance some dealers will apply for a table
                    # AFTER the hotel booking deadline, but BEFORE the hotel
                    # booking is sent out. This ensures they'll still receive
                    # the email, as requested by the Marketplace Department.
                    attendee.requested_hotel_info = True

            if attendee.badge_type == c.PSEUDO_DEALER_BADGE and c.DEALER_REG_SOFT_CLOSED:
                message = 'Dealer registration is closed, but you can ' \
                    'fill out this form to add yourself to our waitlist'

        promo_code_group = None
        if attendee.promo_code:
            promo_code_group = session.query(PromoCode).filter_by(code=attendee.promo_code.code).first().group

        return {
            'message':    message,
            'attendee':   attendee,
            'group':      group,
            'promo_code_group': promo_code_group,
            'edit_id':    edit_id,
            'affiliates': session.affiliates(),
            'cart_not_empty': Charge.unpaid_preregs,
            'copy_address': params.get('copy_address'),
            'promo_code': params.get('promo_code', ''),
            'pii_consent': params.get('pii_consent'),
        }
示例#32
0
def test_min_badges_addable():
    assert 5 == Group().min_badges_addable
    assert 1 == Group(can_add=True).min_badges_addable
示例#33
0
def test_new_ribbon():
    assert '' == Group().new_ribbon
    assert '' == Group(attendees=[Attendee()]).new_ribbon
    assert c.DEALER_RIBBON == Group(tables=1).new_ribbon