def test_amount_lte_ticket_price(self): """ Discount Code Validate Amount Value - Tests if function runs without an exception :return: """ with app.test_request_context(): ticket = TicketFactory() ticket.price = 100 save_to_db(ticket) schema = DiscountCodeSchemaTicket() original_data = {'data': {}} data = {'type': 'amount', 'value': 70, 'tickets': ['1']} DiscountCodeSchemaTicket.validate_value(schema, data, original_data)
def test_free_ticket(self): """ Discount Code Validate Amount Value - Tests exception when discount code is created for free ticket :return: """ with app.test_request_context(): ticket = TicketFactory() ticket.price = 0 save_to_db(ticket) schema = DiscountCodeSchemaTicket() original_data = {'data': {}} data = {'type': 'amount', 'value': 150, 'tickets': ['1']} with self.assertRaises(UnprocessableEntity): DiscountCodeSchemaTicket.validate_value( schema, data, original_data)
def test_amount_gt_ticket_price(self): """ Discount Code Validate Amount Value - Tests if exception is raised when discount value is gt ticket price :return: """ with app.test_request_context(): ticket = TicketFactory() ticket.price = 100 save_to_db(ticket) schema = DiscountCodeSchemaTicket() original_data = {'data': {}} data = {'type': 'amount', 'value': 150, 'tickets': ['1']} with self.assertRaises(UnprocessableEntity): DiscountCodeSchemaTicket.validate_value( schema, data, original_data)
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_date_db_populate(self): """ Tickets Validate Date - Tests if validation works on values stored in db and not given in 'data' :return: """ with self.app.test_request_context(): schema = TicketSchema() TicketFactory() original_data = {'data': {'id': 1}} data = {} TicketSchema.validate_date(schema, data, original_data)
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)