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])
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
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]
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, })
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)
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_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 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 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_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)
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)
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)
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])
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()
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)
def test_cart_boughtitem_caching(self): """ Test that the cached boughtitem information is correct. """ event = EventFactory() order = OrderFactory(event=event) item = ItemFactory(event=event) item_option = ItemOptionFactory(price=100, item=item) order.add_to_cart(item_option) item.delete() self.assertTrue(order.bought_items.exists()) boughtitem = order.bought_items.all()[0] self.assertTrue(boughtitem.item_option_id is None) self.assertEqual(boughtitem.item_name, item.name) self.assertEqual(boughtitem.item_description, item.description) self.assertEqual(boughtitem.item_option_name, item_option.name) self.assertEqual(boughtitem.price, item_option.price) self.assertTrue(boughtitem.item_option_id is None)
def test_cart_boughtitem_caching(self): """ Test that the cached boughtitem information is correct. """ event = EventFactory() order = OrderFactory(event=event) item = ItemFactory(event=event) item_option = ItemOptionFactory(price=100, item=item) order.add_to_cart(item_option) item.delete() self.assertTrue(order.bought_items.exists()) boughtitem = order.bought_items.all()[0] self.assertTrue(boughtitem.item_option_id is None) self.assertEqual(boughtitem.item_name, item.name) self.assertEqual(boughtitem.item_description, item.description) self.assertEqual(boughtitem.item_option_name, item_option.name) self.assertEqual(boughtitem.price, item_option.price) self.assertTrue(boughtitem.item_option_id is None)
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_summary_data__items_no_transaction(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) 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)
def set_up_view(self, orderer=None, is_confirmed=False): organization = OrganizationFactory(check_payment_allowed=True) OrganizationMember.objects.create( person=PersonFactory(), organization=organization, role=OrganizationMember.OWNER, ) event = EventFactory( collect_housing_data=False, organization=organization, check_postmark_cutoff=timezone.now().date() + timedelta(1), ) item = ItemFactory(event=event) item_option = ItemOptionFactory(price=100, item=item) receiver = PersonFactory() order_kwargs = dict(event=event) if orderer: order_kwargs['person'] = orderer order = OrderFactory(**order_kwargs) order.add_to_cart(item_option) transaction = TransactionFactory(event=event, order=order, is_confirmed=is_confirmed) order.mark_cart_paid(transaction) # The BoughtItem should be in the correct state if we've set up this # test Order correctly. self.assertEqual(order.bought_items.first().status, BoughtItem.BOUGHT) view = TransferView() view.kwargs = dict( event_slug=event.slug, organization_slug=organization.slug, ) view.request = self.factory.post( '/', dict( bought_item=order.bought_items.first().pk, email=receiver.email, )) view.request.user = orderer if orderer else AnonymousUser() view.event = event view.order = order view.workflow = RegistrationWorkflow(order=order, event=event) view.current_step = view.workflow.steps.get(view.current_step_slug) return view
def test_queryset_distinct(self): """ For authenticated users, make sure the qs is distinct. Specifically, having multiple additional editors on the event shouldn't cause duplication issues. """ person = PersonFactory() editor1 = PersonFactory() editor2 = PersonFactory() editor3 = PersonFactory() event = EventFactory(collect_housing_data=False) EventMember.objects.create( person=editor1, event=event, role=EventMember.EDIT, ) EventMember.objects.create( person=editor2, event=event, role=EventMember.EDIT, ) EventMember.objects.create( person=editor3, event=event, role=EventMember.EDIT, ) order = OrderFactory(event=event, person=person) # Set up three attendees to trigger duplication. AttendeeFactory(order=order) AttendeeFactory(order=order) AttendeeFactory(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) viewset = BoughtItemViewSet() viewset.request = self.factory.get('/') viewset.request.user = person qs = viewset.get_queryset() self.assertEqual(len(qs), 2) self.assertEqual(set(qs), set(order.bought_items.all()))
def test_needs_housing(self): event = EventFactory(collect_housing_data=False) 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) a1 = AttendeeFactory(order=order, bought_items=order.bought_items.all(), housing_status=Attendee.NEED) a2 = AttendeeFactory(order=order, bought_items=order.bought_items.all()) self.assertTrue(a1.needs_housing()) self.assertFalse(a2.needs_housing())
def setUp(self): stripe_prep(TEST) self.event = EventFactory() self.order = OrderFactory(event=self.event) self.factory = RequestFactory() self.view = StripeWebhookView.as_view() self.stripe_event = {'id': 'evt_123_event_id'} self.data = json.dumps(self.stripe_event) self.request = self.factory.post(path='/', content_type='application/json', data=self.data) item = ItemFactory(event=self.event) item_option = ItemOptionFactory(price=60, item=item) self.order.add_to_cart(item_option) token = stripe.Token.create(card={ 'number': '4242424242424242', 'exp_month': 12, 'exp_year': 2017, 'cvc': '123' }, ) charge = stripe_charge(token, 100, self.order, self.event) self.txn = Transaction.from_stripe_charge( charge, event=self.event, order=self.order, api_type=self.event.api_type, ) self.refund = stripe_refund(self.order, self.event, charge.id, 100) data = mock.Mock(object=mock.Mock(name='charge', id=charge.id)) self.mock_event = mock.Mock( data=data, type='charge.refunded', livemode=False, ) self.order.mark_cart_paid(self.txn)
def setUp(self): self.event = EventFactory() self.order = OrderFactory(event=self.event) self.transaction = TransactionFactory( event=self.event, order=self.order, ) self.item = ItemFactory(event=self.event) self.item_option = ItemOptionFactory(price=100, item=self.item) 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(), ) self.view = AttendeeFilterView() self.view.event = self.event
def setUp(self): self.factory = RequestFactory() 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, ) order = OrderFactory(event=self.event, code='aaaaaaaa') self.transaction = TransactionFactory(event=self.event, order=order) item = ItemFactory(event=self.event) item_option = ItemOptionFactory(price=100, item=item) order.add_to_cart(item_option) order.add_to_cart(item_option) order.mark_cart_paid(self.transaction) AttendeeFactory(order=order, bought_items=order.bought_items.all())
def test_subject__transfer(self): person = PersonFactory(first_name="Conan", last_name="O'Brien") event = EventFactory() order = OrderFactory(event=event, person=person) TransactionFactory(event=event, order=order, amount=130) item = ItemFactory(event=event, name='Multipass') item_option1 = ItemOptionFactory(price=100, item=item, name='Gold') order.add_to_cart(item_option1) boughtitem = order.bought_items.all()[0] request = self.factory.get('/') request.user = person invite, created = TransferInvite.get_or_create( request=request, email='*****@*****.**', content=boughtitem, ) invite.send() self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, "{} wants to transfer an item to you".format( person.get_full_name()))
def setUp(self): self.factory = RequestFactory() owner = PersonFactory() self.event = EventFactory(collect_housing_data=False) OrganizationMember.objects.create( person=owner, organization=self.event.organization, role=OrganizationMember.OWNER, ) order = OrderFactory(event=self.event, code='aaaaaaaa') self.transaction = TransactionFactory(event=self.event, order=order) item = ItemFactory(event=self.event) item_option = ItemOptionFactory(price=100, item=item) order.add_to_cart(item_option) order.add_to_cart(item_option) order.mark_cart_paid(self.transaction) AttendeeFactory(order=order, bought_items=order.bought_items.all()) self.view = SendReceiptView() self.view.request = self.factory.get('/') self.view.request.user = owner
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)
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)
def setUp(self): event = EventFactory(collect_housing_data=True, start_date=now().date() + timedelta(days=2), end_date=now().date() + timedelta(days=2)) order = OrderFactory(event=event, providing_housing=False) housing = EventHousingFactory(event=event, order=order, contact_name='Zardoz', contact_email='*****@*****.**', contact_phone='111-111-1111', public_transit_access=True, person_prefer='Han Solo', person_avoid='Greedo') HousingSlotFactory(eventhousing=housing, date=event.start_date, spaces=1, spaces_max=1) HousingSlotFactory(eventhousing=housing, date=event.start_date - timedelta(days=1), spaces=1, spaces_max=1) housing.ef_present.add(EnvironmentalFactorFactory(name='Carbonite')) housing.ef_present.add(EnvironmentalFactorFactory(name='Sandbarges')) housing.ef_avoid.add(EnvironmentalFactorFactory(name='Jedi')) housing.ef_avoid.add(EnvironmentalFactorFactory(name='Droids')) housing.housing_categories.add(HousingCategoryFactory(name='Palace')) 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) self.attendee = AttendeeFactory( order=order, bought_items=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=event.start_date)) housing_form = CustomFormFactory(event=event, form_type='hosting') field = CustomFormFieldFactory(form=housing_form, name='bed condition') self.custom_key = field.key entry2 = CustomFormEntry.objects.create( related_ct=ContentType.objects.get(model='eventhousing'), related_id=housing.pk, form_field=field) entry2.set_value('unmade') entry2.save() self.event = event self.order = order