def test_edit_attendee_order(db, client, jwt): attendee = AttendeeOrderTicketSubFactory() order = OrderSubFactory(event=attendee.event) db.session.commit() attendee_order = attendee.order data = json.dumps({ 'data': { 'type': 'attendee', 'id': str(attendee.id), "relationships": { "order": { "data": { "id": str(order.id), "type": "order" } } }, } }) client.patch( f'/v1/attendees/{attendee.id}', content_type='application/vnd.api+json', headers=jwt, data=data, ) db.session.refresh(attendee) # Order should not be updated assert attendee.order.id != order.id assert attendee.order.id == attendee_order.id
def test_expire_initializing_tickets(db): order_expiry_time = get_settings()['order_expiry_time'] order_old = OrderSubFactory( created_at=datetime.datetime.now(timezone.utc) - timedelta(minutes=order_expiry_time)) AttendeeSubFactory.create_batch(3, order=order_old) order_new = OrderSubFactory() AttendeeSubFactory.create_batch(2, order=order_new) db.session.commit() expire_initializing_tickets() assert order_old.status == 'expired' assert len(order_old.ticket_holders) == 0 assert order_new.status == 'initializing' assert len(order_new.ticket_holders) == 2
def test_send_notif_ticket_purchase_organizer(user): """Method to test order invoice notification after purchase""" order = OrderSubFactory(identifier='sc4r4fde4', event__name='Poodle') send_notif_ticket_purchase_organizer(user, order) notification = Notification.query.first() assert (f'New ticket purchase for Poodle : ({order.invoice_number})' == notification.title) assert notification.message == 'The order has been processed successfully.'
def _create_discounted_attendees(db): discount, tickets = _create_discount_code(db) order_with_discount = OrderSubFactory(status='completed', discount_code=discount) AttendeeSubFactory.create_batch(3, order=order_with_discount, ticket_id=tickets[0]['id']) db.session.commit() return discount, tickets
def test_expire_pending_tickets(db): order_old = OrderSubFactory( status='pending', created_at=datetime.datetime.now(timezone.utc) - timedelta(minutes=45), ) AttendeeSubFactory.create_batch(3, order=order_old) order_new = OrderSubFactory( status='pending', created_at=datetime.datetime.now(timezone.utc) - timedelta(minutes=15), ) AttendeeSubFactory.create_batch(2, order=order_new) db.session.commit() expire_pending_tickets() assert order_old.status == 'expired' assert len(order_old.ticket_holders) == 3 assert order_new.status == 'pending' assert len(order_new.ticket_holders) == 2
def test_reject_attendees_with_order(db): attendees = AttendeeSubFactory.create_batch(2) attendees.append(AttendeeSubFactory(order=OrderSubFactory())) db.session.commit() with pytest.raises( ConflictError, match= f'Order already exists for attendee with id {attendees[-1].id}', ): validate_ticket_holders([att.id for att in attendees])
def test_nested_sorting(db, client, admin_jwt): OrderSubFactory(event__name='Shah', identifier='zxcv') OrderSubFactory(event__name='Abu', identifier='abcde') OrderSubFactory(event__name='Xerxes', identifier='fghj') db.session.commit() response = client.get( '/v1/orders?sort=event.name', content_type='application/vnd.api+json', headers=admin_jwt, ) orders = json.loads(response.data)['data'] assert orders[0]['attributes']['identifier'] == 'abcde' assert orders[1]['attributes']['identifier'] == 'zxcv' assert orders[2]['attributes']['identifier'] == 'fghj' response = client.get( '/v1/orders?sort=-event.name', content_type='application/vnd.api+json', headers=admin_jwt, ) orders = json.loads(response.data)['data'] assert orders[0]['attributes']['identifier'] == 'fghj' assert orders[1]['attributes']['identifier'] == 'zxcv' assert orders[2]['attributes']['identifier'] == 'abcde' response = client.get( '/v1/orders?sort=identifier', content_type='application/vnd.api+json', headers=admin_jwt, ) orders = json.loads(response.data)['data'] assert orders[0]['attributes']['identifier'] == 'abcde' assert orders[1]['attributes']['identifier'] == 'fghj' assert orders[2]['attributes']['identifier'] == 'zxcv'
def test_send_monthly_invoice(db): """Method to test monthly invoices""" TicketFeesFactory(service_fee=10.23, maximum_fee=11) test_order = OrderSubFactory( status='completed', event__state='published', completed_at=datetime.datetime.now() - datetime.timedelta(days=30), amount=100, ) AttendeeSubFactory(event=test_order.event, order=test_order) db.session.commit() send_monthly_event_invoice() event_invoice = test_order.event.invoices[0] assert event_invoice.amount == 10.23
def test_send_monthly_invoice(db): """Method to test monthly invoices""" TicketFeesFactory(service_fee=10.23, maximum_fee=11, country='global') test_order = OrderSubFactory( status='completed', event__state='published', completed_at=monthdelta(this_month_date(), -1), amount=100, ) role, _ = get_or_create(Role, name='owner', title_name='Owner') UsersEventsRoles(user=UserFactory(), event=test_order.event, role=role) AttendeeSubFactory(event=test_order.event, order=test_order) db.session.commit() send_monthly_event_invoice() event_invoice = test_order.event.invoices[0] assert event_invoice.amount == 10.23
def test_notify_ticket_purchase_atttendee(db): order = OrderSubFactory(user=UserFactory()) attendee = AttendeeOrderSubFactory(order=order, email='*****@*****.**') UserFactory(_email='*****@*****.**') db.session.commit() notify_ticket_purchase_attendee(order) notifications = Notification.query.order_by(Notification.id).all() notification_buyer = notifications[0] assert notification_buyer.user == order.user assert notification_buyer.content.type == NotificationType.TICKET_PURCHASED assert notification_buyer.content.target == order assert notification_buyer.content.actors[0].actor == order.user notification = notifications[1] assert notification.user == attendee.user assert notification.content.type == NotificationType.TICKET_PURCHASED_ATTENDEE assert notification.content.target == order assert notification.content.actors[0].actor == order.user
def get_complex_custom_form_order(db, user): order = OrderSubFactory(amount=234, status='initializing', user=user) attendee = AttendeeSubFactory(order=order) CustomForms( event=attendee.event, form='attendee', field_identifier='whatUniversity', name='what university', type='text', is_complex=True, is_included=True, is_required=True, ) CustomForms( event=attendee.event, form='attendee', field_identifier='whatCollege', name='what college', type='text', is_complex=True, is_included=True, is_required=True, ) CustomForms( event=attendee.event, form='attendee', field_identifier='naamBatao', name='naam batao', type='text', is_complex=True, is_included=True, is_required=False, ) db.session.commit() return str(order.id)
def test_throw_ticket_sold_out(client, db, jwt): event = EventFactoryBasic() tickets = _create_tickets([10, 20], event=event, quantity=2) order = OrderSubFactory(status='completed', event=event) AttendeeFactoryBase.create_batch(2, order=order, ticket=tickets[0], event=event) AttendeeFactoryBase.create_batch(2, order=order, ticket=tickets[1], event=event) db.session.commit() response = client.post( '/v1/orders/create-order', content_type='application/json', headers=jwt, data=json.dumps({ 'tickets': [ { 'id': tickets[0].id, 'quantity': 2 }, { 'id': tickets[1].id, 'quantity': 3 }, ] }), ) assert TicketHolder.query.count() == 0 assert response.status_code == 409 error_dict = json.loads(response.data) assert error_dict['errors'][0]['title'] == 'Conflict' assert 'already sold out' in error_dict['errors'][0]['detail']
def create_order(db, user): order = OrderSubFactory(amount=234, status='initializing', user=user) AttendeeSubFactory.create_batch(3, order=order) db.session.commit() return str(order.id)