def test_cart_discount_caching(self):
        """
        Test that the cached discount information is correct.
        """
        event = EventFactory()
        order = OrderFactory(event=event)
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)
        discount = DiscountFactory(amount=20, event=event, item_options=[item_option])

        order.add_to_cart(item_option)
        order.add_discount(discount)

        discount.delete()

        self.assertTrue(order.bought_items.exists())
        boughtitem = order.bought_items.all()[0]
        self.assertTrue(boughtitem.discounts.exists())
        boughtitemdiscount = boughtitem.discounts.all()[0]

        self.assertTrue(boughtitemdiscount.discount_id is None)
        self.assertEqual(boughtitemdiscount.name, discount.name)
        self.assertEqual(boughtitemdiscount.code, discount.code)
        self.assertEqual(boughtitemdiscount.discount_type, discount.discount_type)
        self.assertEqual(boughtitemdiscount.amount, discount.amount)

        self.assertEqual(boughtitemdiscount.savings(), 20)
Example #2
0
    def test_cart_discount_caching(self):
        """
        Test that the cached discount information is correct.
        """
        event = EventFactory()
        order = OrderFactory(event=event)
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)
        discount = DiscountFactory(amount=20,
                                   event=event,
                                   item_options=[item_option])

        order.add_to_cart(item_option)
        order.add_discount(discount)

        discount.delete()

        self.assertTrue(order.bought_items.exists())
        boughtitem = order.bought_items.all()[0]
        self.assertTrue(boughtitem.discounts.exists())
        boughtitemdiscount = boughtitem.discounts.all()[0]

        self.assertTrue(boughtitemdiscount.discount_id is None)
        self.assertEqual(boughtitemdiscount.name, discount.name)
        self.assertEqual(boughtitemdiscount.code, discount.code)
        self.assertEqual(boughtitemdiscount.discount_type,
                         discount.discount_type)
        self.assertEqual(boughtitemdiscount.amount, discount.amount)

        self.assertEqual(boughtitemdiscount.savings(), 20)
    def test_summary_data__discount_deleted(self):
        """
        Test that get_summary_data returns correct values for savings and
        total cost even if a discount was deleted.

        """
        event = EventFactory()
        order = OrderFactory(event=event)
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)
        discount = DiscountFactory(amount=20, event=event, item_options=[item_option])

        order.add_to_cart(item_option)

        summary_data = order.get_summary_data()
        self.assertEqual(summary_data['gross_cost'], 100)
        self.assertEqual(summary_data['total_savings'], 0)
        self.assertEqual(summary_data['net_cost'], 100)

        order.add_discount(discount)

        summary_data = order.get_summary_data()
        self.assertEqual(summary_data['gross_cost'], 100)
        self.assertEqual(summary_data['total_savings'], -20)
        self.assertEqual(summary_data['net_cost'], 80)

        discount.delete()

        # Make sure that the value isn't cached.
        order = Order.objects.get(pk=order.pk)

        summary_data = order.get_summary_data()
        self.assertEqual(summary_data['gross_cost'], 100)
        self.assertEqual(summary_data['total_savings'], -20)
        self.assertEqual(summary_data['net_cost'], 80)
Example #4
0
    def test_summary_data__discount_deleted(self):
        """
        Test that get_summary_data returns correct values for savings and
        total cost even if a discount was deleted.

        """
        event = EventFactory()
        order = OrderFactory(event=event)
        transaction = TransactionFactory(event=event, order=order)
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)
        discount = DiscountFactory(amount=20,
                                   event=event,
                                   item_options=[item_option])

        order.add_to_cart(item_option)
        order.add_discount(discount)
        order.mark_cart_paid(transaction)

        summary_data = order.get_summary_data()
        self.assertEqual(summary_data['gross_cost'], 100)
        self.assertEqual(summary_data['total_savings'], -20)
        self.assertEqual(summary_data['net_cost'], 80)

        discount.delete()

        # Make sure that the value isn't cached.
        order = Order.objects.get(pk=order.pk)

        summary_data = order.get_summary_data()
        self.assertEqual(summary_data['gross_cost'], 100)
        self.assertEqual(summary_data['total_savings'], -20)
        self.assertEqual(summary_data['net_cost'], 80)
Example #5
0
    def setUp(self):
        event = EventFactory()
        self.order = OrderFactory(event=event, email='*****@*****.**')
        transaction = TransactionFactory(event=event,
                                         order=self.order,
                                         amount=130,
                                         method=Transaction.CHECK,
                                         is_confirmed=False)
        item = ItemFactory(event=event, name='Multipass')
        item_option1 = ItemOptionFactory(price=100, item=item, name='Gold')
        item_option2 = ItemOptionFactory(price=60, item=item, name='Silver')

        discount = DiscountFactory(amount=30,
                                   discount_type='percent',
                                   event=event,
                                   item_options=[item_option1])

        self.order.add_to_cart(item_option1)
        self.order.add_to_cart(item_option2)
        self.order.add_discount(discount)
        self.order.mark_cart_paid(transaction)

        self.mailer = OrderAlertMailer(transaction,
                                       site='dancerfly.com',
                                       secure=True)
        self.event_name = event.name
Example #6
0
    def test_comped__sends_email(self):
        """A successful completion with fully-comped items should send a receipt email and an alert email."""
        organization = OrganizationFactory()
        owner = PersonFactory()
        OrganizationMember.objects.create(
            person=owner,
            organization=organization,
            role=OrganizationMember.OWNER,
        )
        event = EventFactory(
            collect_housing_data=False,
            organization=organization,
        )
        order = OrderFactory(event=event)
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)
        discount = DiscountFactory(amount=100,
                                   discount_type='percent',
                                   event=event,
                                   item_options=[item_option])

        order.add_to_cart(item_option)
        order.add_to_cart(item_option)
        order.add_discount(discount)

        view = SummaryView()
        view.request = self.factory.post('/')
        view.request.user = AnonymousUser()
        view.event = event
        view.order = order

        self.assertEqual(len(mail.outbox), 0)
        response = view.post(view.request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(len(mail.outbox), 2)
    def setUp(self):
        self.person = PersonFactory()
        event = EventFactory()
        self.order = OrderFactory(event=event, person=self.person)
        transaction = TransactionFactory(event=event,
                                         order=self.order,
                                         amount=130)
        item = ItemFactory(event=event, name='Multipass')
        item_option1 = ItemOptionFactory(price=100, item=item, name='Gold')
        item_option2 = ItemOptionFactory(price=60, item=item, name='Silver')

        discount = DiscountFactory(amount=30,
                                   discount_type='percent',
                                   event=event,
                                   item_options=[item_option1])

        self.order.add_to_cart(item_option1)
        self.order.add_to_cart(item_option2)
        self.order.add_discount(discount)
        self.order.mark_cart_paid(transaction)

        self.mailer = OrderReceiptMailer(transaction,
                                         site='dancerfly.com',
                                         secure=True)
        self.event_name = event.name
        self.discount_amount = format_money(discount.amount, event.currency)
        self.total_amount = format_money(transaction.amount, event.currency)
        self.option1 = '{0} ({1})'.format(item.name, item_option1.name)
        self.option2 = '{0} ({1})'.format(item.name, item_option1.name)
        self.item_price = format_money(item_option1.price, event.currency)
Example #8
0
    def test_summary_data__base(self):
        """
        Test that get_summary_data returns correct values for savings and
        total cost.

        """
        event = EventFactory()
        order = OrderFactory(event=event)
        transaction = TransactionFactory(event=event, order=order)
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)
        discount = DiscountFactory(amount=20,
                                   event=event,
                                   item_options=[item_option])

        order.add_to_cart(item_option)
        order.mark_cart_paid(transaction)

        summary_data = order.get_summary_data()
        self.assertEqual(summary_data['gross_cost'], 100)
        self.assertEqual(summary_data['total_savings'], 0)
        self.assertEqual(summary_data['net_cost'], 100)

        # Discounts don't get added to BOUGHT items.
        order.add_discount(discount)

        summary_data = order.get_summary_data()
        self.assertEqual(summary_data['gross_cost'], 100)
        self.assertEqual(summary_data['total_savings'], 0)
        self.assertEqual(summary_data['net_cost'], 100)
Example #9
0
 def setUp(self):
     self.event = EventFactory()
     self.order = OrderFactory(event=self.event)
     self.item = ItemFactory(event=self.event)
     self.item_option = ItemOptionFactory(price=100, item=self.item)
     self.order.add_to_cart(self.item_option)
     self.discount = DiscountFactory(amount=20,
                                     event=self.event,
                                     item_options=[self.item_option])
Example #10
0
    def test_summary_data__items_no_transaction__discount(self):
        """
        Items without transactions are included in summary data.

        """
        event = EventFactory()
        order = OrderFactory(event=event)
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)
        discount = DiscountFactory(amount=20,
                                   event=event,
                                   item_options=[item_option])

        order.add_to_cart(item_option)
        order.add_discount(discount)
        summary_data = order.get_summary_data()
        self.assertEqual(summary_data['gross_cost'], 100)
        self.assertEqual(summary_data['total_savings'], -20)
        self.assertEqual(summary_data['net_cost'], 80)
Example #11
0
    def setUp(self):
        self.factory = RequestFactory()

        event = EventFactory()
        self.order = OrderFactory(event=event, email='*****@*****.**')
        self.transaction = TransactionFactory(
            event=event, order=self.order, amount=130,
            method=Transaction.CHECK, is_confirmed=False)
        item = ItemFactory(event=event, name='Multipass')
        item_option1 = ItemOptionFactory(price=100, item=item, name='Gold')
        item_option2 = ItemOptionFactory(price=60, item=item, name='Silver')

        discount = DiscountFactory(amount=30, discount_type='percent',
                                   event=event, item_options=[item_option1])

        self.order.add_to_cart(item_option1)
        self.order.add_to_cart(item_option2)
        self.order.add_discount(discount)
        self.order.mark_cart_paid(self.transaction)

        order2 = OrderFactory(event=event, email='*****@*****.**')
        order2.add_to_cart(item_option2)
        transaction2 = TransactionFactory(event=event, order=self.order,
                                          amount=130, method=Transaction.CHECK,
                                          is_confirmed=True)
        order2.mark_cart_paid(transaction2)

        self.order3 = OrderFactory(event=event, email='*****@*****.**')
        self.order3.add_to_cart(item_option1)
        transaction3 = TransactionFactory(event=event, order=self.order3,
                                          amount=130, method=Transaction.CHECK,
                                          is_confirmed=True)
        self.order3.mark_cart_paid(transaction3)

        self.viewset = ItemOptionViewSet()
        self.viewset.request = self.factory.get('/')
        self.viewset.request.user = self.order.person
    def test_duplication(self):
        """Passing in a template_event should result in settings and relevant related objects being copied"""
        threedays = timedelta(days=3)
        template = EventFactory(
            start_date=timezone.now() - threedays,
            end_date=timezone.now() - threedays,
        )
        item = ItemFactory(event=template)
        ItemOptionFactory(item=item)
        ItemImageFactory(item=item)
        DiscountFactory(event=template)
        SavedReportFactory(event=template)
        custom_form = CustomFormFactory(event=template)
        CustomFormFieldFactory(form=custom_form)

        request = self.factory.post(
            '/', {
                'name': 'New event',
                'slug': 'new-event',
                'start_date': timezone.now().strftime("%Y-%m-%d"),
                'end_date': timezone.now().strftime("%Y-%m-%d"),
                'organization': str(template.organization.pk),
                'template_event': str(template.pk),
            })
        owner = PersonFactory()
        OrganizationMember.objects.create(
            person=owner,
            organization=template.organization,
            role=OrganizationMember.OWNER,
        )
        request.user = owner
        form = EventCreateForm(request, data=request.POST)
        self.assertFalse(form.errors)
        event = form.save()

        # Get a refreshed version from the db
        event = Event.objects.get(pk=event.pk)

        fields = (
            'description',
            'website_url',
            'banner_image',
            'city',
            'state_or_province',
            'country',
            'timezone',
            'currency',
            'has_dances',
            'has_classes',
            'liability_waiver',
            'privacy',
            'collect_housing_data',
            'collect_survey_data',
            'cart_timeout',
            'check_postmark_cutoff',
            'transfers_allowed',
            'facebook_url',
        )
        self.assertEqual(dict((f, getattr(event, f)) for f in fields),
                         dict((f, getattr(template, f)) for f in fields))
        # Make sure things haven't been moved off old events.
        self.assertEqual(template.items.count(), 1)
        item = template.items.all()[0]
        self.assertEqual(item.options.count(), 1)
        self.assertEqual(template.discount_set.count(), 1)
        self.assertEqual(template.savedreport_set.count(), 1)
        self.assertEqual(template.forms.count(), 1)
        custom_form = template.forms.all()[0]
        self.assertEqual(custom_form.fields.count(), 1)

        # Make sure things have been copied to new event.
        self.assertEqual(event.items.count(), 1)
        item = event.items.all()[0]
        self.assertEqual(item.options.count(), 1)
        self.assertEqual(event.discount_set.count(), 1)
        self.assertEqual(event.savedreport_set.count(), 1)
        self.assertEqual(event.forms.count(), 1)
        custom_form = event.forms.all()[0]
        self.assertEqual(custom_form.fields.count(), 1)

        # Check that dates have been adjusted properly.
        old_item = template.items.all()[0]
        old_option = old_item.options.all()[0]
        new_item = event.items.all()[0]
        new_option = new_item.options.all()[0]
        self.assertEqual(
            new_option.available_start - old_option.available_start, threedays)

        old_discount = template.discount_set.all()[0]
        new_discount = event.discount_set.all()[0]
        self.assertEqual(
            new_discount.available_start - old_discount.available_start,
            threedays)
Example #13
0
    def test_summary_data__transfer(self):
        """Items sent or received in a transfer shouldn't count towards net cost and savings"""
        event = EventFactory()
        order = OrderFactory(
            event=event,
            person=PersonFactory(),
        )
        person2 = PersonFactory()
        transaction = TransactionFactory(
            event=event,
            order=order,
            is_confirmed=True,
            transaction_type=Transaction.PURCHASE,
            amount=80,
        )
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)
        discount = DiscountFactory(amount=20,
                                   event=event,
                                   item_options=[item_option])

        order.add_to_cart(item_option)
        order.add_discount(discount)
        order.mark_cart_paid(transaction)

        bought_item = transaction.bought_items.get()
        invite = TransferInvite.get_or_create(
            request=Mock(user=person2, session={}),
            email=person2.email,
            content=bought_item,
        )[0]
        invite.accept()

        summary_data = order.get_summary_data()
        self.assertEqual(summary_data['gross_cost'], 100)
        self.assertEqual(summary_data['total_savings'], -20)
        self.assertEqual(summary_data['total_refunds'], 0)
        self.assertEqual(summary_data['total_payments'], 80)
        self.assertEqual(summary_data['net_cost'], 80)
        self.assertEqual(summary_data['net_balance'], 0)
        self.assertEqual(summary_data['unconfirmed_check_payments'], False)
        transactions = summary_data['transactions']
        self.assertEqual(len(transactions), 2)
        transfer_txn, transfer_txn_dict = transactions.items()[0]
        self.assertEqual(transfer_txn.transaction_type, Transaction.TRANSFER)
        self.assertEqual(transfer_txn_dict['items'], [bought_item])
        self.assertEqual(transfer_txn_dict['gross_cost'], 0)
        self.assertEqual(transfer_txn_dict['discounts'], [])
        self.assertEqual(transfer_txn_dict['total_savings'], 0)
        self.assertEqual(transfer_txn_dict['net_cost'], 0)
        purchase_txn, purchase_txn_dict = transactions.items()[1]
        self.assertEqual(purchase_txn.transaction_type, Transaction.PURCHASE)
        self.assertEqual(purchase_txn_dict['items'], [bought_item])
        self.assertEqual(purchase_txn_dict['gross_cost'], 100)
        self.assertEqual(purchase_txn_dict['discounts'],
                         [bought_item.discounts.first()])
        self.assertEqual(purchase_txn_dict['total_savings'], -20)
        self.assertEqual(purchase_txn_dict['net_cost'], 80)

        order2 = Order.objects.get(event=event, person=person2)
        summary_data2 = order2.get_summary_data()
        self.assertEqual(summary_data2['gross_cost'], 0)
        self.assertEqual(summary_data2['total_savings'], 0)
        self.assertEqual(summary_data2['total_refunds'], 0)
        self.assertEqual(summary_data2['total_payments'], 0)
        self.assertEqual(summary_data2['net_cost'], 0)
        self.assertEqual(summary_data2['net_balance'], 0)
        self.assertEqual(summary_data2['unconfirmed_check_payments'], False)
        transactions2 = summary_data2['transactions']
        self.assertEqual(len(transactions2), 1)
        transfer_txn2, transfer_txn2_dict = transactions.items()[0]
        self.assertEqual(transfer_txn2.transaction_type, Transaction.TRANSFER)
        self.assertEqual(transfer_txn2_dict['items'], [bought_item])
        self.assertEqual(transfer_txn2_dict['gross_cost'], 0)
        self.assertEqual(transfer_txn2_dict['discounts'], [])
        self.assertEqual(transfer_txn2_dict['total_savings'], 0)
        self.assertEqual(transfer_txn2_dict['net_cost'], 0)