def test_no_product(self): """ Verify that an exception is raised if there is no product. """ voucher = VoucherFactory() offer = ConditionalOfferFactory() voucher.offers.add(offer) with self.assertRaises(exceptions.ProductNotFoundError): get_voucher_and_products_from_code(code=voucher.code)
def test_no_product(self): """ Verify that an exception is raised if there is no product. """ voucher = VoucherFactory(code='NOPRODUCT') offer = ConditionalOfferFactory() voucher.offers.add(offer) with self.assertRaises(exceptions.ProductNotFoundError): get_voucher_and_products_from_code(code='NOPRODUCT')
def get_context_data(self, **kwargs): code = self.request.GET.get('code', None) if code is None: return {'error': _('This coupon code is invalid.')} try: voucher, products = get_voucher_and_products_from_code(code=code) except Voucher.DoesNotExist: return {'error': _('Coupon does not exist.')} except exceptions.ProductNotFoundError: return { 'error': _('The voucher is not applicable to your current basket.') } valid_voucher, msg = voucher_is_valid(voucher, products, self.request) if not valid_voucher: return {'error': msg} context_data = super(CouponOfferView, self).get_context_data(**kwargs) context_data.update( get_enterprise_customer_consent_failed_context_data( self.request, voucher)) if context_data and 'error' not in context_data: context_data.update({ 'offer_app_page_heading': _('Welcome to edX'), 'offer_app_page_heading_message': _('Please choose from the courses selected by your ' 'organization to start learning.') }) self.template_name = 'coupons/offer.html' return context_data
def test_get_voucher_and_products_from_code(self): """ Verify that get_voucher_and_products_from_code() returns products and voucher. """ original_voucher, original_product = prepare_voucher(code=VOUCHER_CODE) voucher, products = get_voucher_and_products_from_code(code=VOUCHER_CODE) self.assertIsNotNone(voucher) self.assertEqual(voucher, original_voucher) self.assertEqual(voucher.code, VOUCHER_CODE) self.assertEqual(len(products), 1) self.assertEqual(products[0], original_product)
def test_get_voucher_and_products_from_code(self): """ Verify that get_voucher_and_products_from_code() returns products and voucher. """ original_voucher, original_product = prepare_voucher(code=COUPON_CODE) voucher, products = get_voucher_and_products_from_code(code=COUPON_CODE) self.assertIsNotNone(voucher) self.assertEqual(voucher, original_voucher) self.assertEqual(voucher.code, COUPON_CODE) self.assertEqual(len(products), 1) self.assertEqual(products[0], original_product)
def get_context_data(self, **kwargs): code = self.request.GET.get('code', None) if code is not None: try: voucher, products = get_voucher_and_products_from_code(code=code) except Voucher.DoesNotExist: return {'error': _('Coupon does not exist')} except exceptions.ProductNotFoundError: return {'error': _('The voucher is not applicable to your current basket.')} valid_voucher, msg = voucher_is_valid(voucher, products, self.request) if valid_voucher: self.template_name = 'coupons/offer.html' return return {'error': msg} return {'error': _('This coupon code is invalid.')}
def get_context_data(self, **kwargs): code = self.request.GET.get('code', None) if code is not None: try: voucher, products = get_voucher_and_products_from_code( code=code) except Voucher.DoesNotExist: return {'error': _('Coupon does not exist')} except exceptions.ProductNotFoundError: return { 'error': _('The voucher is not applicable to your current basket.') } valid_voucher, msg = voucher_is_valid(voucher, products, self.request) if valid_voucher: self.template_name = 'coupons/offer.html' return return {'error': msg} return {'error': _('This coupon code is invalid.')}
def test_get_non_existing_voucher(self): """ Verify that get_voucher_and_products_from_code() raises exception for a non-existing voucher. """ with self.assertRaises(Voucher.DoesNotExist): get_voucher_and_products_from_code(code=FuzzyText().fuzz())
def test_get_non_existing_voucher(self): """ Verify that get_voucher_and_products_from_code() raises exception for a non-existing voucher. """ with self.assertRaises(Voucher.DoesNotExist): get_voucher_and_products_from_code(code='INVALID')