当前位置: 首页>>代码示例>>Python>>正文


Python OrderFactory.get_eventhousing方法代码示例

本文整理汇总了Python中brambling.tests.factories.OrderFactory.get_eventhousing方法的典型用法代码示例。如果您正苦于以下问题:Python OrderFactory.get_eventhousing方法的具体用法?Python OrderFactory.get_eventhousing怎么用?Python OrderFactory.get_eventhousing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在brambling.tests.factories.OrderFactory的用法示例。


在下文中一共展示了OrderFactory.get_eventhousing方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MergeUnclaimableOrderTest

# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import get_eventhousing [as 别名]
class MergeUnclaimableOrderTest(TestCase):

    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='[email protected]')
        self.att2 = AttendeeFactory(
            order=self.order2, bought_items=self.order2.bought_items.all(),
            email='[email protected]')

        self.housing2 = EventHousingFactory(
            event=event, order=self.order2, contact_name='Picard',
            contact_email='[email protected]', 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_should_redirect(self):
        response = self.view.post(self.view.request)

        self.assertEqual(response.status_code, 302)

    def test_should_transfer_transactions_to_new_order(self):
        self.view.post(self.view.request)

        self.tr2 = Transaction.objects.get(pk=self.tr2.pk)
        self.assertEqual(self.tr2.order, self.order1)

    def test_should_transfer_bought_items_to_new_order(self):
        self.view.post(self.view.request)

        self.assertEqual(self.order1.bought_items.count(), 3)
        for item in self.tr2.bought_items.all():
            self.assertEqual(item.order, self.order1)

    def test_should_transfer_attendees_to_new_order(self):
        self.view.post(self.view.request)

        self.att2 = Attendee.objects.get(pk=self.att2.pk)
        self.assertEqual(self.att2.order, self.order1)

    def test_should_delete_old_order(self):
        self.view.post(self.view.request)

        with self.assertRaises(Order.DoesNotExist):
            Order.objects.get(pk=self.order2.pk)

    def test_should_transfer_eventhousing_if_none_present(self):
        self.view.post(self.view.request)

        self.order1 = Order.objects.get(pk=self.order1.pk)

        self.assertEqual(self.order1.get_eventhousing(), self.housing2)

    def test_should_not_transfer_eventhousing_if_present(self):
        housing1 = EventHousingFactory(
            event=self.order1.event, order=self.order1, contact_name='Riker',
            contact_email='[email protected]', contact_phone='111-111-1111',
            public_transit_access=True, person_prefer='Troi',
            person_avoid='Worf')
        self.view.post(self.view.request)

        self.order1 = Order.objects.get(pk=self.order1.pk)
        self.assertEqual(self.order1.get_eventhousing(), housing1)
开发者ID:littleweaver,项目名称:django-brambling,代码行数:97,代码来源:test_merge_orders.py


注:本文中的brambling.tests.factories.OrderFactory.get_eventhousing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。