Exemple #1
0
    def setUp(self):
        self.factory = RequestFactory()
        self.view = MergeOrderView()

        event = EventFactory(collect_housing_data=True)
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)

        self.person = PersonFactory()
        self.order1 = OrderFactory(event=event, person=self.person)
        self.order2 = OrderFactory(event=event,
                                   person=None,
                                   email=self.person.email)

        self.tr1 = TransactionFactory(event=event, order=self.order1)
        self.tr2 = TransactionFactory(event=event, order=self.order2)

        self.order1.add_to_cart(item_option)
        self.order1.mark_cart_paid(self.tr1)

        self.order2.add_to_cart(item_option)
        self.order2.add_to_cart(item_option)
        self.order2.mark_cart_paid(self.tr2)

        self.att1 = AttendeeFactory(
            order=self.order1,
            bought_items=self.order1.bought_items.all(),
            email='*****@*****.**')
        self.att2 = AttendeeFactory(
            order=self.order2,
            bought_items=self.order2.bought_items.all(),
            email='*****@*****.**')

        self.housing2 = EventHousingFactory(
            event=event,
            order=self.order2,
            contact_name='Picard',
            contact_email='*****@*****.**',
            contact_phone='111-111-1111',
            public_transit_access=True,
            person_prefer='Dr. Crusher',
            person_avoid='Wesley Crusher')

        self.attendee1 = AttendeeFactory(order=self.order1)
        self.attendee2 = AttendeeFactory(order=self.order2)

        self.view.request = self.factory.post('/', {'pk': self.order2.pk})
        self.view.request.user = self.person

        setattr(self.view.request, 'session', 'session')
        messages = FallbackStorage(self.view.request)
        setattr(self.view.request, '_messages', messages)
    def test_attendee_count__home_housing(self):
        """Attendee count should be present & accurate; housing data should."""
        event = EventFactory(collect_housing_data=True)
        order = OrderFactory(event=event)
        transaction = TransactionFactory(event=event, order=order)
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)

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

        AttendeeFactory(
            order=order,
            bought_items=order.bought_items.all(),
            housing_status=Attendee.HOME,
        )

        view = EventSummaryView()
        view.request = self.factory.get('/')
        view.request.user = AnonymousUser()
        view.event = event
        context_data = view.get_context_data()

        self.assertEqual(context_data['attendee_count'], 1)
        self.assertEqual(context_data['attendee_requesting_count'], 0)
        self.assertEqual(context_data['attendee_arranged_count'], 0)
        self.assertEqual(context_data['attendee_home_count'], 1)
Exemple #3
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
Exemple #4
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)
Exemple #5
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)
    def test_unicode_csv(self):
        event = EventFactory(collect_housing_data=True, currency='GBP')
        order = OrderFactory(event=event)
        transaction = TransactionFactory(event=event, order=order)
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)

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

        AttendeeFactory(
            order=order,
            bought_items=order.bought_items.all(),
            housing_status=Attendee.HOME,
        )

        view = AttendeeFilterView()
        view.event = event
        view.request = self.factory.get('/?format=csv')
        view.request.user = AnonymousUser()

        table = view.get_table(Attendee.objects.all())
        response = view.render_to_response({'table': table})
        self.assertEqual(response['content-disposition'],
                         'attachment; filename="export.csv"')
        content = list(response)
        self.assertIn('£200.00', content[1])
Exemple #7
0
 def setUp(self):
     self.factory = RequestFactory()
     self.person = PersonFactory(
         first_name="Conan",
         last_name="O'Brien",
     )
     self.event = EventFactory()
     self.order = OrderFactory(
         event=self.event,
         person=self.person,
     )
     TransactionFactory(
         event=self.event,
         order=self.order,
         amount=130,
     )
     self.item = ItemFactory(
         event=self.event,
         name='Multipass',
     )
     self.item_option1 = ItemOptionFactory(
         price=100,
         item=self.item,
         name='Gold',
     )
     self.order.add_to_cart(self.item_option1)
     self.bought_item = self.order.bought_items.all()[0]
Exemple #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)
Exemple #9
0
 def test_dwolla_payment_form_handles_valueerror(self, oauth_refresh,
                                                 dwolla_get_sources):
     oauth_refresh.return_value = {
         'error': 'access_denied',
         'error_description': 'Arbitrary error code.'
     }
     dwolla_get_sources.return_value = DWOLLA_SOURCES
     order = OrderFactory()
     order.event.organization.dwolla_test_account = DwollaOrganizationAccountFactory(
         access_token_expires=timezone.now() - timedelta(1))
     order.event.organization.save()
     person = PersonFactory()
     person.dwolla_test_account = DwollaUserAccountFactory()
     person.save()
     pin = '1234'
     source = 'Balance'
     form = DwollaPaymentForm(order=order,
                              amount=Decimal('42.15'),
                              data={
                                  'dwolla_pin': pin,
                                  'source': source
                              },
                              user=person)
     self.assertTrue(form.is_bound)
     self.assertTrue(form.errors)
     self.assertEqual(form.errors['__all__'],
                      [oauth_refresh.return_value['error_description']])
Exemple #10
0
    def setUp(self):
        self.owner = Person.objects.create_user(email="*****@*****.**",
                                                password="******")
        self.non_owner = Person.objects.create_user(
            email="*****@*****.**", password="******")
        self.event = EventFactory(collect_housing_data=False)
        OrganizationMember.objects.create(
            person=self.owner,
            organization=self.event.organization,
            role=OrganizationMember.OWNER,
        )
        self.order = OrderFactory(event=self.event, code='aaaaaaaa')
        self.transaction = TransactionFactory(event=self.event,
                                              order=self.order)
        item = ItemFactory(event=self.event)
        item_option = ItemOptionFactory(price=100, item=item)

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

        self.attendee = AttendeeFactory(
            order=self.order, bought_items=self.order.bought_items.all())
        self.url = reverse('brambling_event_order_detail',
                           kwargs={
                               'event_slug': self.event.slug,
                               'organization_slug':
                               self.event.organization.slug,
                               'code': self.order.code,
                           })
Exemple #11
0
    def test_payment__sends_email(self):
        """A successful payment should send a receipt email and an alert email."""
        organization = OrganizationFactory(check_payment_allowed=True)
        owner = PersonFactory()
        OrganizationMember.objects.create(
            person=owner,
            organization=organization,
            role=OrganizationMember.OWNER,
        )
        event = EventFactory(
            collect_housing_data=False,
            organization=organization,
            check_postmark_cutoff=timezone.now().date(),
        )
        order = OrderFactory(event=event)
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)

        order.add_to_cart(item_option)
        order.add_to_cart(item_option)

        view = SummaryView()
        view.request = self.factory.post('/', {'check': 1})
        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)
Exemple #12
0
    def test_summary_data__itemoption_changed(self):
        """
        Test that get_summary_data returns correct values for savings and
        total cost even if an itemoption was changed.

        """
        event = EventFactory()
        order = OrderFactory(event=event)
        transaction = TransactionFactory(event=event, order=order)
        item = ItemFactory(event=event)
        item_option = ItemOptionFactory(price=100, item=item)

        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)

        item_option.price = 200
        item_option.save()

        # 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'], 0)
        self.assertEqual(summary_data['net_cost'], 100)
    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)
Exemple #14
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)
Exemple #15
0
 def setUp(self):
     self.person = PersonFactory(stripe_test_customer_id='FAKE_CUSTOMER_ID')
     self.order = OrderFactory(person=self.person)
     self.event = self.order.event
     self.card = CardFactory(is_saved=True)
     self.person.cards.add(self.card)
     self.person.save()
Exemple #16
0
    def test_order_by_purchase_date(self):
        """
        If ordering by purchase date is selected, we should get that
        ordering even if the field isn't selected.

        """
        order2 = OrderFactory(event=self.event)
        transaction = TransactionFactory(
            event=self.event,
            order=order2,
            timestamp=timezone.now() - datetime.timedelta(days=50)
        )
        order2.add_to_cart(self.item_option)
        order2.mark_cart_paid(transaction)
        attendee2 = AttendeeFactory(
            order=order2,
            bought_items=order2.bought_items.all(),
            housing_status='have',
            email='*****@*****.**',
            other_needs='99 mattresses',
            person_avoid='Darth Vader',
            person_prefer='Han Solo',
        )

        table = AttendeeTable(
            event=self.event,
            data={
                'o': '-purchase_date',
                TABLE_COLUMN_FIELD: ['pk', 'get_full_name'],
            },
        )
        rows = list(table)
        self.assertEqual(rows[0]['pk'].value, self.attendee.pk)
        self.assertEqual(rows[1]['pk'].value, attendee2.pk)
Exemple #17
0
 def test_alien_item_refund(self):
     alien_order = OrderFactory(event=self.event, person=self.person)
     alien_item = BoughtItem.objects.create(item_option=self.item_option1, price=Decimal(0), status=BoughtItem.BOUGHT, order=alien_order)
     data = {
         'items': [alien_item.pk]
     }
     form = TransactionRefundForm(self.txn, data)
     self.assertEqual(len(form.errors.get('items', [])), 1)
 def test_alien_item_return(self):
     alien_order = OrderFactory(event=self.event, person=self.person)
     alien_item = BoughtItem.objects.create(item_option=self.item_option1,
                                            price=Decimal(0),
                                            status=BoughtItem.BOUGHT,
                                            order=alien_order)
     with self.assertRaises(ValueError):
         self.txn.refund(bought_items=BoughtItem.objects.filter(
             pk=alien_item.pk))
Exemple #19
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])
Exemple #20
0
 def test_for_request__code__anon_anon(self):
     """Anonymous users forbidden to access anonymous orders."""
     event = EventFactory()
     OrderFactory(event=event, person=None)
     request = self.factory.get('/')
     self._add_session(request)
     request.user = AnonymousUser()
     with self.assertRaises(Order.DoesNotExist):
         Order.objects.for_request(event, request, create=False)
Exemple #21
0
    def test_for_request__session__authed_anon__with_order(self):
        """
        An authenticated user's own order will take precedence over
        a session order.
        """
        event = EventFactory()
        person = PersonFactory()
        order = OrderFactory(event=event, person=None)
        order2 = OrderFactory(event=event, person=person)
        request = self.factory.get('/')
        self._add_session(request)
        Order.objects._set_session_code(request, event, order.code)
        request.user = person

        fetched, created = Order.objects.for_request(event,
                                                     request,
                                                     create=False)
        self.assertFalse(created)
        self.assertEqual(fetched, order2)
Exemple #22
0
 def setUp(self):
     self.person = PersonFactory()
     self.event = EventFactory()
     self.item = ItemFactory(event=self.event, name='Multipass')
     self.order = OrderFactory(event=self.event, person=self.person)
     self.item_option1 = ItemOptionFactory(price=100, item=self.item, name='Gold')
     self.item_option2 = ItemOptionFactory(price=100, item=self.item, name='Gold')
     self.bought_item1 = BoughtItem.objects.create(item_option=self.item_option1, order=self.order, price=Decimal(0), status=BoughtItem.BOUGHT)
     self.bought_item2 = BoughtItem.objects.create(item_option=self.item_option2, order=self.order, price=Decimal(0), status=BoughtItem.BOUGHT)
     self.txn = TransactionFactory(amount=Decimal("20"), order=self.order)
     self.txn.bought_items.add(self.bought_item1, self.bought_item2)
Exemple #23
0
    def test_dwolla_charge__user(self):
        event = EventFactory(api_type=Event.TEST,
                             application_fee_percent=Decimal('2.5'))
        event.organization.dwolla_test_account = DwollaOrganizationAccountFactory(
        )
        event.organization.save()
        self.assertTrue(event.dwolla_connected())
        dwolla_prep(Event.TEST)

        person = PersonFactory()
        person.dwolla_test_account = DwollaUserAccountFactory()
        person.save()
        order = OrderFactory(person=person, event=event, code='dwoll1')
        charge = dwolla_charge(
            account=person.dwolla_test_account,
            amount=42.15,
            order=order,
            event=event,
            pin=settings.DWOLLA_TEST_USER_PIN,
            source='Balance',
        )

        self.assertIsInstance(charge, dict)
        self.assertEqual(charge["Type"], "money_received")
        self.assertEqual(len(charge['Fees']), 1)
        self.assertEqual(charge["Notes"],
                         "Order {} for {}".format(order.code, event.name))

        txn = Transaction.from_dwolla_charge(charge, event=event)
        # 42.15 * 0.025 = 1.05
        self.assertEqual(Decimal(txn.application_fee), Decimal('1.05'))
        # 0.25
        self.assertEqual(Decimal(txn.processing_fee), Decimal('0'))

        refund = dwolla_refund(order=order,
                               event=event,
                               payment_id=txn.remote_id,
                               amount=txn.amount,
                               pin=settings.DWOLLA_TEST_ORGANIZATION_PIN)

        self.assertIsInstance(refund, dict)
        self.assertEqual(refund["Amount"], txn.amount)

        refund_info = transactions.info(
            tid=str(refund['TransactionId']),
            alternate_token=event.organization.get_dwolla_account(
                event.api_type).get_token())
        self.assertEqual(refund_info["Notes"],
                         "Order {} for {}".format(order.code, event.name))

        refund_txn = Transaction.from_dwolla_refund(refund, txn, event=event)
        self.assertEqual(refund_txn.amount, -1 * txn.amount)
        self.assertEqual(refund_txn.application_fee, 0)
        self.assertEqual(refund_txn.processing_fee, 0)
Exemple #24
0
    def setUp(self):
        self.event = EventFactory(collect_housing_data=True)
        self.item = ItemFactory(event=self.event)
        self.item_option = ItemOptionFactory(price=100, item=self.item)

        self.order = OrderFactory(event=self.event)
        self.transaction = TransactionFactory(
            event=self.event,
            order=self.order,
        )
        self.order.add_to_cart(self.item_option)
        self.order.mark_cart_paid(self.transaction)

        self.attendee = AttendeeFactory(
            order=self.order,
            bought_items=self.order.bought_items.all(),
            housing_status='have',
            email='*****@*****.**',
            other_needs='99 mattresses',
            person_avoid='Darth Vader',
            person_prefer='Lando Calrissian',
        )
        self.attendee.ef_cause = [
            EnvironmentalFactorFactory(name='Laughter'),
            EnvironmentalFactorFactory(name='Confusion'),
        ]
        self.attendee.housing_prefer = [
            HousingCategoryFactory(name='Yurt'),
        ]
        self.attendee.ef_avoid = [
            EnvironmentalFactorFactory(name='Ontology'),
            EnvironmentalFactorFactory(name='Gnosticism'),
        ]
        self.attendee.nights.add(HousingRequestNightFactory(date=self.event.start_date))

        attendee_form = CustomFormFactory(event=self.event, form_type='attendee')
        f1 = CustomFormFieldFactory(form=attendee_form, name='favorite color')
        self.custom_key1 = f1.key
        entry1 = CustomFormEntry.objects.create(
            related_ct=ContentType.objects.get(model='attendee'),
            related_id=self.attendee.id,
            form_field=f1)
        entry1.set_value('ochre')
        entry1.save()

        housing_form = CustomFormFactory(event=self.event, form_type='housing')
        f2 = CustomFormFieldFactory(form=housing_form, name='floor or bed')
        self.custom_key2 = f2.key
        entry2 = CustomFormEntry.objects.create(
            related_ct=ContentType.objects.get(model='attendee'),
            related_id=self.attendee.pk,
            form_field=f2)
        entry2.set_value('bed')
        entry2.save()
Exemple #25
0
 def test_for_request__code__authed_other_authed(self):
     """An authenticated user can't access orders created by anyone else."""
     event = EventFactory()
     person = PersonFactory()
     person2 = PersonFactory()
     order = OrderFactory(event=event, person=person2)
     request = self.factory.get('/')
     self._add_session(request)
     Order.objects._set_session_code(request, event, order.code)
     request.user = person
     with self.assertRaises(Order.DoesNotExist):
         Order.objects.for_request(event, request, create=False)
    def test_charge__no_customer(self):
        event = EventFactory(api_type=TEST,
                             application_fee_percent=Decimal('2.5'))
        order = OrderFactory(event=event)
        self.assertTrue(event.stripe_connected())
        stripe_prep(TEST)
        stripe.api_key = event.organization.stripe_test_access_token

        token = stripe.Token.create(card={
            "number": '4242424242424242',
            "exp_month": 12,
            "exp_year": 2050,
            "cvc": '123'
        }, )
        charge = stripe_charge(
            token,
            amount=42.15,
            order=order,
            event=event,
        )
        self.assertIsInstance(charge.balance_transaction, stripe.StripeObject)
        self.assertEqual(charge.balance_transaction.object,
                         "balance_transaction")
        self.assertEqual(len(charge.balance_transaction.fee_details), 2)
        self.assertEqual(charge.metadata, {
            'order': order.code,
            'event': event.name
        })

        txn = Transaction.from_stripe_charge(charge,
                                             api_type=event.api_type,
                                             event=event)
        # 42.15 * 0.025 = 1.05
        self.assertEqual(txn.application_fee, Decimal('1.05'))
        # (42.15 * 0.029) + 0.30 = 1.52
        self.assertEqual(txn.processing_fee, Decimal('1.52'))

        refund = stripe_refund(order=order,
                               event=event,
                               payment_id=txn.remote_id,
                               amount=txn.amount)
        self.assertEqual(refund['refund'].metadata, {
            'order': order.code,
            'event': event.name
        })

        refund_txn = Transaction.from_stripe_refund(refund,
                                                    api_type=event.api_type,
                                                    related_transaction=txn,
                                                    event=event)
        self.assertEqual(refund_txn.amount, -1 * txn.amount)
        self.assertEqual(refund_txn.application_fee, -1 * txn.application_fee)
        self.assertEqual(refund_txn.processing_fee, -1 * txn.processing_fee)
Exemple #27
0
 def test_check_payment_form(self):
     order = OrderFactory()
     event = order.event
     form = CheckPaymentForm(order=order, amount=Decimal('42.15'), data={})
     self.assertTrue(form.is_bound)
     self.assertFalse(form.errors)
     txn = form.save()
     self.assertIsInstance(txn, Transaction)
     self.assertEqual(txn.event, event)
     self.assertEqual(txn.amount, Decimal('42.15'))
     self.assertEqual(txn.application_fee, Decimal('0'))
     self.assertEqual(txn.processing_fee, Decimal('0'))
Exemple #28
0
 def test_for_request__authed(self):
     """An authenticated user will automatically get their own order."""
     event = EventFactory()
     person = PersonFactory()
     order = OrderFactory(event=event, person=person)
     request = self.factory.get('/')
     request.user = person
     fetched, created = Order.objects.for_request(event,
                                                  request,
                                                  create=False)
     self.assertFalse(created)
     self.assertEqual(fetched, order)
Exemple #29
0
 def test_for_request__code__authed_anon(self):
     """Authenticated users cannot access orders created by anonymous users
     without the code stored in the session.
     """
     event = EventFactory()
     person = PersonFactory()
     OrderFactory(event=event, person=None)
     request = self.factory.get('/')
     self._add_session(request)
     request.user = person
     with self.assertRaises(Order.DoesNotExist):
         Order.objects.for_request(event, request, create=False)
    def setUp(self):
        stripe_prep(TEST)

        self.event = EventFactory()
        self.order = OrderFactory()

        self.factory = RequestFactory()
        self.view = StripeWebhookView.as_view()
        self.data = json.dumps({'id': 'evt_123_event_id'})

        self.request = self.factory.post(path='/',
                                         content_type='application/json',
                                         data=self.data)