def test_send_monthly_invoice(self): """Method to test monthly invoices""" with self.app.test_request_context(): TicketFeesFactory(service_fee=10.23, maximum_fee=11) test_event = EventFactoryBasic(state='published') test_user = UserFactory() test_order = OrderFactory(status='completed') test_order.completed_at = datetime.datetime.now( ) - datetime.timedelta(days=30) test_order.amount = 100 test_order.event = test_event test_ticket_holder = AttendeeFactory() test_ticket_holder.event = test_event test_ticket_holder.order = test_order test_event.owner = test_user db.session.commit() send_monthly_event_invoice() event_invoice = EventInvoice.query.get(1) self.assertEqual(event_invoice.amount, 10.23)
def test_match_discount_quantity(self): """Method to test the quantity calculation of discount code""" with self.app.test_request_context(): ticket = TicketFactory() discount_code = DiscountCodeTicketFactory(tickets_number=5) discount_code.tickets.append(ticket) order_without_discount = OrderFactory(status='completed') db.session.commit() # Attendees associated with the order without discount code should not be counted AttendeeFactoryBase.create_batch( 10, order_id=order_without_discount.id, ticket_id=ticket.id) self.assertTrue( TicketingManager.match_discount_quantity(discount_code, ticket_holders=[1])) order_with_discount = OrderFactory( status='completed', discount_code_id=discount_code.id) db.session.commit() # Attendees associated with the order with discount code should be counted AttendeeFactoryBase.create_batch(5, order_id=order_with_discount.id, ticket_id=ticket.id) self.assertFalse( TicketingManager.match_discount_quantity(discount_code, ticket_holders=[1])) self.assertEqual(5, discount_code.confirmed_attendees_count)
def test_should_not_expire_valid_orders(self): """Method to test to not mark valid orders as expired""" with app.test_request_context(): obj = OrderFactory() event = EventFactoryBasic() obj.event = event set_expiry_for_order(obj) self.assertEqual(obj.status, 'pending')
def test_export_orders_csv(self): """Method to check the orders data export""" with self.app.test_request_context(): test_order = OrderFactory() test_order.amount = 2 field_data = export_orders_csv([test_order]) self.assertEqual(field_data[1][2], 'initializing') self.assertEqual(field_data[1][4], '2')
def test_should_expire_outdated_order(self): """Method to test expiration of outdated orders""" with app.test_request_context(): obj = OrderFactory() event = EventFactoryBasic() obj.event = event obj.created_at = datetime.now( timezone.utc) - timedelta(minutes=obj.event.order_expiry_time) set_expiry_for_order(obj) self.assertEqual(obj.status, 'expired')
def test_should_expire_outdated_order(self): """Method to test expiration of outdated orders""" with app.test_request_context(): obj = OrderFactory() event = EventFactoryBasic() obj.event = event obj.created_at = datetime.now(timezone.utc) - timedelta( minutes=obj.event.order_expiry_time) set_expiry_for_order(obj) self.assertEqual(obj.status, 'expired')
def test_should_delete_related_attendees(self): """Method to test to delete related attendees of an event""" with app.test_request_context(): attendee = AttendeeFactory() save_to_db(attendee) obj = OrderFactory() obj.ticket_holders = [attendee, ] save_to_db(obj) delete_related_attendees_for_order(obj) order = db.session.query(Order).filter(Order.id == obj.id).first() self.assertEqual(len(order.ticket_holders), 0)
def test_should_delete_related_attendees(self): """Method to test to delete related attendees of an event""" with app.test_request_context(): attendee = AttendeeFactory() db.session.add(attendee) db.session.commit() obj = OrderFactory() obj.ticket_holders = [attendee, ] db.session.add(obj) db.session.commit() delete_related_attendees_for_order(obj) order = db.session.query(Order).filter(Order.id == obj.id).first() self.assertEqual(len(order.ticket_holders), 0)
def test_count_sold_and_reserved_tickets(self): """Method to test the count query of sold tickets""" with self.app.test_request_context(): ticket = TicketFactory() completed_order = OrderFactory(status='completed') placed_order = OrderFactory(status='placed') initializing_order = OrderFactory(status='initializing', created_at=datetime.utcnow() - timedelta(minutes=5)) pending_order = OrderFactory(status='pending', created_at=datetime.utcnow() - timedelta(minutes=35)) expired_time_order = OrderFactory(status='initializing', created_at=common.date_) expired_order = OrderFactory(status='expired') db.session.commit() # will not be counted as they have no order_id AttendeeFactoryBase.create_batch(2) # will be counted as attendee have valid orders AttendeeFactoryBase.create_batch(6, order_id=completed_order.id) # will be counted as attendee has valid placed order AttendeeFactoryBase(order_id=placed_order.id) # will be counted as attendee has initializing order under order expiry time AttendeeFactoryBase.create_batch(4, order_id=initializing_order.id) # will be counted as attendee has pending order under 30+order expiry time AttendeeFactoryBase.create_batch(2, order_id=pending_order.id) # will not be counted as the order is not under order expiry time AttendeeFactoryBase.create_batch(3, order_id=expired_time_order.id) # will not be counted as the order has an expired state AttendeeFactoryBase.create_batch(5, order_id=expired_order.id) count = get_sold_and_reserved_tickets_count(ticket.event_id) self.assertEqual(count, 13)