Ejemplo n.º 1
0
    def setUp(self):
        super(UtilTests, self).setUp()

        self.user = self.create_user(full_name="Tešt Ušer", is_staff=True)
        self.client.login(username=self.user.username, password=self.password)

        self.course = CourseFactory(id='course-v1:test-org+course+run', partner=self.partner)
        self.verified_seat = self.course.create_or_update_seat('verified', False, 100)

        self.catalog = Catalog.objects.create(partner=self.partner)

        self.stock_record = StockRecord.objects.filter(product=self.verified_seat).first()
        self.seat_price = self.stock_record.price_excl_tax
        self.catalog.stock_records.add(self.stock_record)

        self.coupon = self.create_coupon(
            title='Tešt product',
            catalog=self.catalog,
            note='Tešt note',
            quantity=1,
            max_uses=1,
            voucher_type=Voucher.MULTI_USE
        )
        self.coupon.history.all().update(history_user=self.user)
        self.coupon_vouchers = CouponVouchers.objects.filter(coupon=self.coupon)

        self.entitlement = create_or_update_course_entitlement(
            'verified', 100, self.partner, 'foo-bar', 'Foo Bar Entitlement'
        )
        self.entitlement_stock_record = StockRecord.objects.filter(product=self.entitlement).first()
        self.entitlement_catalog = Catalog.objects.create(partner=self.partner)
        self.entitlement_catalog.stock_records.add(self.entitlement_stock_record)
        self.entitlement_coupon = self.create_coupon(
            title='Tešt Entitlement product',
            catalog=self.entitlement_catalog,
            note='Tešt Entitlement note',
            quantity=1,
            max_uses=1,
            voucher_type=Voucher.MULTI_USE
        )
        self.entitlement_coupon_vouchers = CouponVouchers.objects.filter(coupon=self.entitlement_coupon)

        self.data = {
            'benefit_type': Benefit.PERCENTAGE,
            'benefit_value': 100.00,
            'catalog': self.catalog,
            'coupon': self.coupon,
            'end_datetime': datetime.datetime.now() + datetime.timedelta(days=1),
            'enterprise_customer': None,
            'enterprise_customer_catalog': None,
            'name': "Test voucher",
            'quantity': 10,
            'start_datetime': datetime.datetime.now() - datetime.timedelta(days=1),
            'voucher_type': Voucher.SINGLE_USE
        }
Ejemplo n.º 2
0
    def test_report_for_inactive_coupons(self):
        """ Verify the coupon report show correct status for inactive coupons. """
        self.data.update({
            'name': self.coupon.title,
            'end_datetime': datetime.datetime.now() - datetime.timedelta(days=1)
        })
        vouchers = create_vouchers(**self.data)
        self.coupon_vouchers.first().vouchers.add(*vouchers)

        __, rows = generate_coupon_report(self.coupon_vouchers)

        # The data that is the same for all vouchers like Coupon Name, Coupon Type, etc.
        # are only shown in row[0]
        # The data that is unique among vouchers like Code, Url, Status, etc.
        # starts from row[1]
        self.assertEqual(rows[0]['Coupon Name'], self.coupon.title)
        self.assertEqual(rows[2]['Status'], _('Inactive'))