コード例 #1
0
def test_match_discount_quantity(db):
    """Method to test the quantity calculation of discount code"""

    ticket = TicketSubFactory()
    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,
        event_id=ticket.event_id,
    )

    assert discount_code.is_available(ticket_holders=[1]) is True

    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,
                                     event_id=ticket.event_id)

    assert discount_code.is_available(ticket_holders=[1]) is False
    assert discount_code.confirmed_attendees_count == 5
コード例 #2
0
    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)
コード例 #3
0
    def test_export_orders_csv(self):
        """Method to check the orders data export"""

        with self.app.test_request_context():
            test_order = OrderFactory(created_at=datetime.now())
            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')
コード例 #4
0
    def test_should_not_expire_valid_orders(self):
        """Method to test to not mark valid orders as expired"""

        with self.app.test_request_context():
            obj = OrderFactory()
            event = EventFactoryBasic()
            obj.event = event
            db.session.commit()
            set_expiry_for_order(obj)
            self.assertEqual(obj.status, 'initializing')
コード例 #5
0
    def test_should_expire_outdated_order(self):
        """Method to test expiration of outdated orders"""

        with self.app.test_request_context():
            obj = OrderFactory()
            order_expiry_time = get_settings()['order_expiry_time']
            event = EventFactoryBasic()
            obj.event = event
            obj.created_at = datetime.now(
                timezone.utc) - timedelta(minutes=order_expiry_time)
            set_expiry_for_order(obj)
            self.assertEqual(obj.status, 'expired')
コード例 #6
0
    def test_should_delete_related_attendees(self):
        """Method to test to delete related attendees of an event"""

        with self.app.test_request_context():
            attendee = AttendeeFactoryBase(event_id=EventFactoryBasic().id)

            obj = OrderFactory(event_id=attendee.event_id)
            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)
コード例 #7
0
    def test_export_attendees_csv(self):
        """Method to check the attendees data export"""

        with self.app.test_request_context():
            test_attendee = AttendeeFactory()
            test_order = OrderFactory(created_at=datetime.now())
            test_attendee.order = test_order
            custom_forms = CustomFormFactory()
            field_data = export_attendees_csv([test_attendee], [custom_forms])
            assert field_data[1][8] == 'tax id'
コード例 #8
0
def test_humanize_helper(db):
    """Method to test humanization of order creation time"""

    test_order = OrderFactory(created_at=datetime.datetime.now() -
                              datetime.timedelta(days=10))
    actual_response = humanize_helper(test_order.created_at)
    expected_response = '10 days ago'
    assert actual_response == expected_response

    actual_response = humanize_helper(test_order.completed_at)
    expected_response = 'N/A'
    assert actual_response == expected_response
コード例 #9
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()
            other_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, ticket_id=ticket.id)
            # will be counted as attendee have valid orders
            AttendeeFactoryBase.create_batch(6,
                                             order_id=completed_order.id,
                                             ticket_id=ticket.id)
            # will be counted as attendee has valid placed order
            AttendeeFactoryBase(order_id=placed_order.id, ticket_id=ticket.id)
            # will not be counted as they are deleted
            AttendeeFactoryBase.create_batch(
                3,
                order_id=placed_order.id,
                ticket_id=ticket.id,
                deleted_at=datetime.utcnow(),
            )
            # will be counted as attendee has initializing order under order expiry time
            AttendeeFactoryBase.create_batch(4,
                                             order_id=initializing_order.id,
                                             ticket_id=ticket.id)
            # will be counted as attendee has pending order under 30+order expiry time
            AttendeeFactoryBase.create_batch(2,
                                             order_id=pending_order.id,
                                             ticket_id=ticket.id)
            # will not be counted as the order is not under order expiry time
            AttendeeFactoryBase.create_batch(3,
                                             order_id=expired_time_order.id,
                                             ticket_id=ticket.id)
            # will not be counted as the order has an expired state
            AttendeeFactoryBase.create_batch(5,
                                             order_id=expired_order.id,
                                             ticket_id=ticket.id)
            # will not be counted as the attendees have different ticket ID
            AttendeeFactoryBase.create_batch(2,
                                             order_id=completed_order.id,
                                             ticket_id=other_ticket.id)

            count = get_sold_and_reserved_tickets_count(ticket.id)

            self.assertEqual(count, 13)

            # Last 2 attendees belong to other ticket
            self.assertEqual(
                get_sold_and_reserved_tickets_count(other_ticket.id), 2)