Esempio n. 1
0
    def test_issue_credit_for_enterprise_offer_no_partial_credit(self):
        """
        Test that credit is not issued if not all of the lines in an order are refunded.
        """
        order = self.create_order(user=UserFactory(), multiple_lines=True)

        offer = EnterpriseOfferFactory(partner=PartnerFactory(),
                                       max_discount=150)

        discount = OrderDiscountFactory(order=order,
                                        offer_id=offer.id,
                                        frequency=1,
                                        amount=150)

        offer.record_usage({
            'freq': discount.frequency,
            'discount': discount.amount
        })
        offer.refresh_from_db()
        assert offer.status == ConditionalOffer.CONSUMED
        assert offer.total_discount == 150

        refund = RefundFactory(order=order, user=UserFactory())
        refund.lines.first().delete()

        with mock.patch.object(models,
                               'revoke_fulfillment_for_refund') as mock_revoke:
            mock_revoke.return_value = True
            self.assertTrue(refund.approve())

        offer.refresh_from_db()

        assert offer.status == ConditionalOffer.CONSUMED
        assert offer.total_discount == 150
Esempio n. 2
0
    def test_issue_credit_for_enterprise_offer(self):
        """
        Test that enterprise offers are credited for the discounted amount.
        """
        order = self.create_order(user=UserFactory())

        offer = EnterpriseOfferFactory(partner=PartnerFactory(),
                                       max_discount=150)

        discount = OrderDiscountFactory(order=order,
                                        offer_id=offer.id,
                                        frequency=1,
                                        amount=150)

        offer.record_usage({
            'freq': discount.frequency,
            'discount': discount.amount
        })
        offer.refresh_from_db()
        assert offer.status == ConditionalOffer.CONSUMED
        assert offer.total_discount == 150

        refund = RefundFactory(order=order, user=UserFactory())

        with mock.patch.object(models,
                               'revoke_fulfillment_for_refund') as mock_revoke:
            mock_revoke.return_value = True
            self.assertTrue(refund.approve())

        offer.refresh_from_db()

        assert offer.status == ConditionalOffer.OPEN
        assert offer.total_discount == 0
Esempio n. 3
0
    def test_remove_dashboard_permission(self):
        user = UserFactory(is_staff=False)
        permission = PermissionFactory(codename='dashboard_access',
                                       content_type=ContentType.objects.get(
                                           app_label='partner',
                                           model='partner'))
        user.user_permissions.add(permission)
        partner = PartnerFactory()
        partner.users.add(user)

        view = views.PartnerUserUnlinkView()
        view.unlink_user(user, partner)

        assert partner.users.count() == 0
        assert Permission.objects.filter(pk=permission.pk).exists()
Esempio n. 4
0
    def setUp(self):
        """
        Creates two orders. order_in has self.user in it's partner users list.
        """
        super().setUp()
        self.address = ShippingAddressFactory()
        self.basket_in = create_basket()
        self.basket_out = create_basket()
        # replace partner with one that has the user in it's users list
        self.partner_in = PartnerFactory(users=[self.user])
        stockrecord = self.basket_in.lines.all()[0].stockrecord
        stockrecord.partner = self.partner_in
        stockrecord.save()

        self.order_in = create_order(basket=self.basket_in,
                                     shipping_address=self.address)
        self.order_out = create_order(basket=self.basket_out,
                                      shipping_address=self.address)
Esempio n. 5
0
 def setUp(self):
     super(TestAStaffUser, self).setUp()
     self.partner = PartnerFactory()
Esempio n. 6
0
 def setUp(self):
     super().setUp()
     self.partner = PartnerFactory()