Commit 18743016 by Vedran Karačić Committed by GitHub

Merge pull request #1010 from edx/vkaracic/SOL-2134

[SOL-2134] Add error message template.
parents 25666359 c0036400
...@@ -12,6 +12,7 @@ from oscar.test.factories import ( ...@@ -12,6 +12,7 @@ from oscar.test.factories import (
ConditionalOfferFactory, OrderFactory, OrderLineFactory, RangeFactory, VoucherFactory ConditionalOfferFactory, OrderFactory, OrderLineFactory, RangeFactory, VoucherFactory
) )
from oscar.test.utils import RequestFactory from oscar.test.utils import RequestFactory
from rest_framework import status
from ecommerce.core.url_utils import get_lms_url from ecommerce.core.url_utils import get_lms_url
from ecommerce.coupons.tests.mixins import CouponMixin from ecommerce.coupons.tests.mixins import CouponMixin
...@@ -263,7 +264,6 @@ class CouponOfferViewTests(ApiMockMixin, CouponMixin, CourseCatalogTestMixin, Lm ...@@ -263,7 +264,6 @@ class CouponOfferViewTests(ApiMockMixin, CouponMixin, CourseCatalogTestMixin, Lm
class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin, TestCase): class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin, TestCase):
redeem_url = reverse('coupons:redeem') redeem_url = reverse('coupons:redeem')
HTTP_MOVED = 301
def setUp(self): def setUp(self):
super(CouponRedeemViewTests, self).setUp() super(CouponRedeemViewTests, self).setUp()
...@@ -317,7 +317,7 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin ...@@ -317,7 +317,7 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin
response = self.client.get(url_without_sku) response = self.client.get(url_without_sku)
self.assertEqual(response.context['error'], _('SKU not provided.')) self.assertEqual(response.context['error'], _('SKU not provided.'))
def test_invalid_voucher(self): def test_invalid_voucher_code(self):
""" Verify an error is returned when voucher does not exist. """ """ Verify an error is returned when voucher does not exist. """
code = 'DOESNTEXIST' code = 'DOESNTEXIST'
url = self.redeem_url + '?code={}&sku={}'.format(code, self.stock_record.partner_sku) url = self.redeem_url + '?code={}&sku={}'.format(code, self.stock_record.partner_sku)
...@@ -332,6 +332,16 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin ...@@ -332,6 +332,16 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin
response = self.client.get(url) response = self.client.get(url)
self.assertEqual(response.context['error'], _('The product does not exist.')) self.assertEqual(response.context['error'], _('The product does not exist.'))
def test_expired_voucher(self):
""" Verify an error is returned for expired coupon. """
start_datetime = now() - datetime.timedelta(days=20)
end_datetime = now() - datetime.timedelta(days=10)
code = 'INVALID'
__, product = prepare_voucher(code=code, start_datetime=start_datetime, end_datetime=end_datetime)
url = self.redeem_url + '?code={}&sku={}'.format(code, StockRecord.objects.get(product=product).partner_sku)
response = self.client.get(url)
self.assertEqual(response.context['error'], _('This coupon code has expired.'))
@httpretty.activate @httpretty.activate
def test_basket_redirect_discount_code(self): def test_basket_redirect_discount_code(self):
""" Verify the view redirects to the basket single-item view when a discount code is provided. """ """ Verify the view redirects to the basket single-item view when a discount code is provided. """
...@@ -345,9 +355,9 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin ...@@ -345,9 +355,9 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin
def test_basket_redirect_enrollment_code(self): def test_basket_redirect_enrollment_code(self):
""" Verify the view redirects to LMS when an enrollment code is provided. """ """ Verify the view redirects to LMS when an enrollment code is provided. """
self.create_and_test_coupon() self.create_and_test_coupon()
httpretty.register_uri(httpretty.GET, self.student_dashboard_url, status=self.HTTP_MOVED) httpretty.register_uri(httpretty.GET, self.student_dashboard_url, status=status.HTTP_301_MOVED_PERMANENTLY)
self.mock_account_api(self.request, self.user.username, data={'is_active': True}) self.mock_account_api(self.request, self.user.username, data={'is_active': True})
self.assert_redemption_page_redirects(self.student_dashboard_url, target=self.HTTP_MOVED) self.assert_redemption_page_redirects(self.student_dashboard_url, target=status.HTTP_301_MOVED_PERMANENTLY)
@httpretty.activate @httpretty.activate
def test_multiple_vouchers(self): def test_multiple_vouchers(self):
...@@ -356,8 +366,8 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin ...@@ -356,8 +366,8 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin
basket = Basket.get_basket(self.user, self.site) basket = Basket.get_basket(self.user, self.site)
basket.vouchers.add(Voucher.objects.get(code=COUPON_CODE)) basket.vouchers.add(Voucher.objects.get(code=COUPON_CODE))
self.mock_account_api(self.request, self.user.username, data={'is_active': True}) self.mock_account_api(self.request, self.user.username, data={'is_active': True})
httpretty.register_uri(httpretty.GET, self.student_dashboard_url, status=self.HTTP_MOVED) httpretty.register_uri(httpretty.GET, self.student_dashboard_url, status=status.HTTP_301_MOVED_PERMANENTLY)
self.assert_redemption_page_redirects(self.student_dashboard_url, target=self.HTTP_MOVED) self.assert_redemption_page_redirects(self.student_dashboard_url, target=status.HTTP_301_MOVED_PERMANENTLY)
@httpretty.activate @httpretty.activate
def test_already_enrolled_rejection(self): def test_already_enrolled_rejection(self):
......
...@@ -97,24 +97,16 @@ class CouponOfferView(TemplateView): ...@@ -97,24 +97,16 @@ class CouponOfferView(TemplateView):
try: try:
voucher, products = get_voucher_and_products_from_code(code=code) voucher, products = get_voucher_and_products_from_code(code=code)
except Voucher.DoesNotExist: except Voucher.DoesNotExist:
return { return {'error': _('Coupon does not exist')}
'error': _('Coupon does not exist'),
}
except exceptions.ProductNotFoundError: except exceptions.ProductNotFoundError:
return { return {'error': _('The voucher is not applicable to your current basket.')}
'error': _('The voucher is not applicable to your current basket.'),
}
valid_voucher, msg = voucher_is_valid(voucher, products, self.request) valid_voucher, msg = voucher_is_valid(voucher, products, self.request)
if valid_voucher: if valid_voucher:
self.template_name = 'coupons/offer.html' self.template_name = 'coupons/offer.html'
return return
return { return {'error': msg}
'error': msg, return {'error': _('This coupon code is invalid.')}
}
return {
'error': _('This coupon code is invalid.'),
}
@method_decorator(login_required_for_credit) @method_decorator(login_required_for_credit)
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
...@@ -158,9 +150,11 @@ class CouponRedeemView(EdxOrderPlacementMixin, View): ...@@ -158,9 +150,11 @@ class CouponRedeemView(EdxOrderPlacementMixin, View):
return render(request, template_name, {'error': _('You are not eligible to use this coupon.')}) return render(request, template_name, {'error': _('You are not eligible to use this coupon.')})
if not request.user.account_details(request)['is_active']: if not request.user.account_details(request)['is_active']:
return render(request, template_name, { return render(
'error': _('You need to activate your account in order to redeem this coupon.') request,
}) template_name,
{'error': _('You need to activate your account in order to redeem this coupon.')}
)
if request.user.is_user_already_enrolled(request, product): if request.user.is_user_already_enrolled(request, product):
return render(request, template_name, {'error': _('You are already enrolled in the course.')}) return render(request, template_name, {'error': _('You are already enrolled in the course.')})
......
...@@ -34,14 +34,6 @@ a { ...@@ -34,14 +34,6 @@ a {
} }
} }
.message-error {
border-top: 4px solid #B20610;
h3 {
margin-bottom: 10px;
font-weight: bold;
}
}
.depth { .depth {
padding: 1.25rem 1.25rem; padding: 1.25rem 1.25rem;
} }
......
...@@ -34,5 +34,6 @@ ...@@ -34,5 +34,6 @@
@import 'views/course_admin'; @import 'views/course_admin';
@import 'views/coupon_admin'; @import 'views/coupon_admin';
@import 'views/coupon_offer'; @import 'views/coupon_offer';
@import 'views/error';
@import "default"; @import "default";
...@@ -54,3 +54,6 @@ $small-input-width: 174px; ...@@ -54,3 +54,6 @@ $small-input-width: 174px;
$input-addon-width: 40px; $input-addon-width: 40px;
$coupon-grid-item-height: 75px; $coupon-grid-item-height: 75px;
$container-padding-top: 60px;
$container-padding-bottom: spacing-vertical(small);
#offer { #offer {
.container { .container {
padding-top: 60px; padding-top: $container-padding-top;
padding-bottom: spacing-vertical(small); padding-bottom: $container-padding-bottom;
.row { .row {
.pagination-block { .pagination-block {
......
#error-message {
padding-top: $container-padding-top;
padding-bottom: $container-padding-bottom;
}
.message-error-content {
border-top: 4px solid #B20610;
h3 {
margin-bottom: 10px;
font-weight: bold;
}
}
<div class="depth depth-2 message-error offer-error"> <div class="depth depth-2 message-error-content offer-error">
<h3><%= error_msg %></h3> <h3><%= error_msg %></h3>
<%- gettext('If you need assistance, contact edX support.') %> <%- gettext('If you need assistance, contact edX support.') %>
</div> </div>
{% extends 'edx/base.html' %} {% extends 'edx/error.html' %}
{% load i18n %} {% load i18n %}
{% block title %}{% trans "Redeem" %}{% endblock %} {% block title %}{% trans "Redeem" %}{% endblock %}
{% block navbar %}
{% include 'edx/partials/_student_navbar.html' %}
{% endblock navbar %}
{% block content %}
<div id="offer">
<div class="container">
<div class="depth depth-2 message-error">
<h3>{{ error }}</h3>
{% trans "If you need assistance, contact edX support." %}
</div>
</div>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'edx/base.html' %}
{% load i18n %}
{% block title %}{% endblock %}
{% block navbar %}
{% include 'edx/partials/_student_navbar.html' %}
{% endblock navbar %}
{% block content %}
<div id="error-message">
<div class="container">
<div class="depth depth-2 message-error-content">
<h3>{{ error }}</h3>
{% trans "If you need assistance, contact edX support." %}
</div>
</div>
</div>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment