async def event_tickets(request): event_id = await _check_event_permissions(request) not_admin = request['session']['role'] != 'admin' tickets = [] settings = request.app['settings'] conn: BuildPgConnection = request['conn'] for t in await conn.fetch(event_tickets_sql, event_id): ticket = { 'ticket_id': ticket_id_signed(t['id'], settings), **t, } if not_admin: ticket.pop('guest_email') ticket.pop('buyer_email') tickets.append(ticket) waiting_list = [ dict(r) for r in await conn.fetch(event_waiting_list_sql, event_id) ] if not_admin: [r.pop('email') for r in waiting_list] donations = [ dict(r) for r in await conn.fetch(event_donations_sql, event_id) ] if not_admin: [r.pop('user_email') for r in donations] return json_response(tickets=tickets, waiting_list=waiting_list, donations=donations)
async def test_send_ticket_name_on_ticket(email_actor: EmailActor, factory: Factory, dummy_server, db_conn, settings): await factory.create_company() await factory.create_cat(ticket_extra_title='Foo Bar') await factory.create_user() await factory.create_event() anne = await factory.create_user(first_name=None, last_name=None, email='*****@*****.**') res = await factory.create_reservation(anne) assert 'UPDATE 1' == await db_conn.execute( "UPDATE tickets SET first_name='Cat', last_name='Dog'") booked_action_id = await factory.book_free(res, anne) await email_actor.send_event_conf(booked_action_id) assert len(dummy_server.app['emails']) == 1 email = dummy_server.app['emails'][0] assert email['To'] == 'Cat Dog <*****@*****.**>' assert email['part:text/plain'].startswith( 'Hi Cat,\n' '\n' 'Thanks for booking your ticket for Supper Clubs, **The Event Name** hosted by Frank Spencer.\n' '\n' 'Foo Bar not provided, please let the event host Frank Spencer know if you have any special requirements.\n' ) assert 'Card Charged' not in email['part:text/plain'] tid = await db_conn.fetchval('SELECT id FROM tickets') ticket_id_s = ticket_id_signed(tid, settings) assert ticket_id_s.endswith(f'-{tid}') assert f'* Ticket ID: **{ticket_id_s}**\n' in email['part:text/plain'] assert f'<li>Ticket ID: <strong>{ticket_id_s}</strong></li>\n' in email[ 'part:text/html']
def modify(record): data = { 'donation_id': ticket_id_signed(record['id'], settings), **record, } data.pop('id') data.pop('ticket_type_id') if not_admin: data.pop('user_id') data.pop('user_email') return data
async def event_tickets(request): event_id = await _check_event_permissions(request) not_admin = request['session']['role'] != 'admin' tickets = [] settings = request.app['settings'] for t in await request['conn'].fetch(event_tickets_sql, event_id): ticket = { 'ticket_id': ticket_id_signed(t['id'], settings), **t, } if not_admin: ticket.pop('guest_email') ticket.pop('buyer_email') tickets.append(ticket) return json_response(tickets=tickets)
def test_ticket_id_signed(ticket_id, expected, settings): assert expected == ticket_id_signed(ticket_id, settings)