Merge pull request #21638 from edx/awais786/BOM-471

BOM-471
This commit is contained in:
Awais Qureshi
2019-09-12 20:13:49 +05:00
committed by GitHub

View File

@@ -284,14 +284,17 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
self.assertEqual(resp.status_code, 200)
#first course price is 40$ and the second course price is 20$
# after 10% discount on both the courses the total price will be 18+36 = 54
self.assertIn('54.00', resp.content)
self.assertIn('54.00', resp.content.decode('utf-8'))
def test_add_course_to_cart_already_in_cart(self):
PaidCourseRegistration.add_to_order(self.cart, self.course_key)
self.login_user()
resp = self.client.post(reverse('add_course_to_cart', args=[text_type(self.course_key)]))
self.assertEqual(resp.status_code, 400)
self.assertIn(u'The course {0} is already in your cart.'.format(text_type(self.course_key)), resp.content)
self.assertIn(
u'The course {0} is already in your cart.'.format(text_type(self.course_key)),
resp.content.decode('utf-8')
)
def test_course_discount_invalid_coupon(self):
self.add_coupon(self.course_key, True, self.coupon_code)
@@ -299,7 +302,10 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
non_existing_code = "non_existing_code"
resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': non_existing_code})
self.assertEqual(resp.status_code, 404)
self.assertIn(u"Discount does not exist against code '{0}'.".format(non_existing_code), resp.content)
self.assertIn(
u"Discount does not exist against code '{0}'.".format(non_existing_code),
resp.content.decode('utf-8')
)
def test_valid_qty_greater_then_one_and_purchase_type_should_business(self):
qty = 2
@@ -317,18 +323,18 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
item = self.add_course_to_user_cart(self.course_key)
resp = self.client.post(reverse('shoppingcart.views.update_user_cart'), {'ItemId': item.id, 'qty': qty})
self.assertEqual(resp.status_code, 400)
self.assertIn("Quantity must be between 1 and 1000.", resp.content)
self.assertIn("Quantity must be between 1 and 1000.", resp.content.decode('utf-8'))
# invalid quantity, Quantity must be an integer.
qty = 'abcde'
resp = self.client.post(reverse('shoppingcart.views.update_user_cart'), {'ItemId': item.id, 'qty': qty})
self.assertEqual(resp.status_code, 400)
self.assertIn("Quantity must be an integer.", resp.content)
self.assertIn("Quantity must be an integer.", resp.content.decode('utf-8'))
# invalid quantity, Quantity is not present in request
resp = self.client.post(reverse('shoppingcart.views.update_user_cart'), {'ItemId': item.id})
self.assertEqual(resp.status_code, 400)
self.assertIn("Quantity must be between 1 and 1000.", resp.content)
self.assertIn("Quantity must be between 1 and 1000.", resp.content.decode('utf-8'))
def test_valid_qty_but_item_not_found(self):
qty = 2
@@ -378,7 +384,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
resp = self.client.post(reverse('shoppingcart.views.update_user_cart'), {'ItemId': item.id, 'qty': qty})
self.assertEqual(resp.status_code, 200)
resp = self.client.get(reverse('shoppingcart.views.show_cart', args=[]))
self.assertIn("Billing Details", resp.content)
self.assertIn("Billing Details", resp.content.decode('utf-8'))
def test_purchase_type_should_be_personal_when_remove_all_items_from_cart(self):
item1 = self.add_course_to_user_cart(self.course_key)
@@ -421,14 +427,20 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
non_existing_code = "non_existing_code"
resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': non_existing_code})
self.assertEqual(resp.status_code, 404)
self.assertIn(u"Discount does not exist against code '{0}'.".format(non_existing_code), resp.content)
self.assertIn(
u"Discount does not exist against code '{0}'.".format(non_existing_code),
resp.content.decode('utf-8')
)
def test_course_discount_inactive_coupon(self):
self.add_coupon(self.course_key, False, self.coupon_code)
self.add_course_to_user_cart(self.course_key)
resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': self.coupon_code})
self.assertEqual(resp.status_code, 404)
self.assertIn(u"Discount does not exist against code '{0}'.".format(self.coupon_code), resp.content)
self.assertIn(
u"Discount does not exist against code '{0}'.".format(self.coupon_code),
resp.content.decode('utf-8')
)
def test_course_does_not_exist_in_cart_against_valid_coupon(self):
course_key = text_type(self.course_key) + 'testing'
@@ -437,7 +449,10 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': self.coupon_code})
self.assertEqual(resp.status_code, 404)
self.assertIn(u"Discount does not exist against code '{0}'.".format(self.coupon_code), resp.content)
self.assertIn(
u"Discount does not exist against code '{0}'.".format(self.coupon_code),
resp.content.decode('utf-8')
)
def test_inactive_registration_code_returns_error(self):
"""
@@ -454,7 +469,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
self.assertEqual(resp.status_code, 400)
self.assertIn(
u"This enrollment code ({enrollment_code}) is no longer valid.".format(
enrollment_code=self.reg_code), resp.content)
enrollment_code=self.reg_code), resp.content.decode('utf-8'))
def test_course_does_not_exist_in_cart_against_valid_reg_code(self):
course_key = text_type(self.course_key) + 'testing'
@@ -463,8 +478,10 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': self.reg_code})
self.assertEqual(resp.status_code, 404)
self.assertIn(u"Code '{0}' is not valid for any course in the shopping cart.".format(self.reg_code),
resp.content)
self.assertIn(
u"Code '{0}' is not valid for any course in the shopping cart.".format(self.reg_code),
resp.content.decode('utf-8')
)
def test_cart_item_qty_greater_than_1_against_valid_reg_code(self):
course_key = text_type(self.course_key)
@@ -476,7 +493,10 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
# it will raise an exception
resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': self.reg_code})
self.assertEqual(resp.status_code, 404)
self.assertIn("Cart item quantity should not be greater than 1 when applying activation code", resp.content)
self.assertIn(
"Cart item quantity should not be greater than 1 when applying activation code",
resp.content.decode('utf-8')
)
@ddt.data(True, False)
def test_reg_code_uses_associated_mode(self, expired_mode):
@@ -501,7 +521,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
resp = self.client.post(reverse('register_code_redemption', args=[self.reg_code]), HTTP_HOST='localhost')
self.assertEqual(resp.status_code, 200)
self.assertIn(self.course.display_name.encode('utf-8'), resp.content)
self.assertIn("error processing your redeem code", resp.content)
self.assertIn("error processing your redeem code", resp.content.decode('utf-8'))
def test_course_discount_for_valid_active_coupon_code(self):
@@ -522,7 +542,10 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
# Only one coupon redemption should be allowed per order.
resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': self.coupon_code})
self.assertEqual(resp.status_code, 400)
self.assertIn("Only one coupon redemption is allowed against an order", resp.content)
self.assertIn(
"Only one coupon redemption is allowed against an order",
resp.content.decode('utf-8')
)
def test_course_discount_against_two_distinct_coupon_codes(self):
@@ -541,7 +564,10 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
self.add_coupon(self.course_key, True, 'abxyz')
resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': 'abxyz'})
self.assertEqual(resp.status_code, 400)
self.assertIn("Only one coupon redemption is allowed against an order", resp.content)
self.assertIn(
"Only one coupon redemption is allowed against an order",
resp.content.decode('utf-8')
)
def test_same_coupons_code_on_multiple_courses(self):
@@ -605,7 +631,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
response = self.client.get(redeem_url)
self.assertEquals(response.status_code, 200)
# check button text
self.assertIn('Activate Course Enrollment', response.content)
self.assertIn('Activate Course Enrollment', response.content.decode('utf-8'))
#now activate the user by enrolling him/her to the course
response = self.client.post(redeem_url)
@@ -617,7 +643,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
self.assertEqual(resp.status_code, 400)
self.assertIn(u"This enrollment code ({enrollment_code}) is not valid.".format(
enrollment_code=self.reg_code
), resp.content)
), resp.content.decode('utf-8'))
def test_upgrade_from_valid_reg_code(self):
"""Use a valid registration code to upgrade from honor to verified mode. """
@@ -636,7 +662,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
response = self.client.get(redeem_url)
self.assertEquals(response.status_code, 200)
# check button text
self.assertIn('Activate Course Enrollment', response.content)
self.assertIn('Activate Course Enrollment', response.content.decode('utf-8'))
#now activate the user by enrolling him/her to the course
response = self.client.post(redeem_url)
@@ -776,13 +802,16 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
self.login_user()
resp = self.client.post(reverse('add_course_to_cart', args=[text_type(self.course_key)]))
self.assertEqual(resp.status_code, 400)
self.assertIn(u'You are already registered in course {0}.'.format(text_type(self.course_key)), resp.content)
self.assertIn(
u'You are already registered in course {0}.'.format(text_type(self.course_key)),
resp.content.decode('utf-8')
)
def test_add_nonexistent_course_to_cart(self):
self.login_user()
resp = self.client.post(reverse('add_course_to_cart', args=['non/existent/course']))
self.assertEqual(resp.status_code, 404)
self.assertIn("The course you requested does not exist.", resp.content)
self.assertIn("The course you requested does not exist.", resp.content.decode('utf-8'))
def test_add_course_to_cart_success(self):
self.login_user()
@@ -898,7 +927,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
self.login_user()
resp = self.client.post(reverse('shoppingcart.views.postpay_callback', args=[]))
self.assertEqual(resp.status_code, 200)
self.assertIn('ERROR_TEST!!!', resp.content)
self.assertIn('ERROR_TEST!!!', resp.content.decode('utf-8'))
((template, context), _) = render_mock.call_args
self.assertEqual(template, 'shoppingcart/error.html')
@@ -1087,8 +1116,8 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
resp = self.client.get(reverse('shoppingcart.views.show_receipt', args=[self.cart.id]))
self.assertEqual(resp.status_code, 200)
self.assertIn('FirstNameTesting123', resp.content)
self.assertIn(str(self.get_discount(self.cost)), resp.content)
self.assertIn('FirstNameTesting123', resp.content.decode('utf-8'))
self.assertIn(str(self.get_discount(self.cost)), resp.content.decode('utf-8'))
@patch('shoppingcart.views.render_to_response', render_mock)
def test_reg_code_and_course_registration_scenario(self):
@@ -1105,7 +1134,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
response = self.client.get(redeem_url)
self.assertEquals(response.status_code, 200)
# check button text
self.assertIn('Activate Course Enrollment', response.content)
self.assertIn('Activate Course Enrollment', response.content.decode('utf-8'))
#now activate the user by enrolling him/her to the course
response = self.client.post(redeem_url)
@@ -1132,14 +1161,14 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
resp = self.client.get(redeem_url)
self.assertEquals(resp.status_code, 200)
# check button text
self.assertIn('Activate Course Enrollment', resp.content)
self.assertIn('Activate Course Enrollment', resp.content.decode('utf-8'))
#now activate the user by enrolling him/her to the course
resp = self.client.post(redeem_url)
self.assertEquals(resp.status_code, 200)
resp = self.client.get(reverse('shoppingcart.views.show_cart', args=[]))
self.assertIn('Payment', resp.content)
self.assertIn('Payment', resp.content.decode('utf-8'))
self.cart.purchase(first='FirstNameTesting123', street1='StreetTesting123')
resp = self.client.get(reverse('shoppingcart.views.show_receipt', args=[self.cart.id]))
@@ -1172,7 +1201,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
resp = self.client.get(reverse('shoppingcart.views.show_receipt', args=[self.cart.id]))
self.assertEqual(resp.status_code, 200)
self.assertIn('0.00', resp.content)
self.assertIn('0.00', resp.content.decode('utf-8'))
@patch('shoppingcart.views.render_to_response', render_mock)
def test_show_receipt_success(self):
@@ -1187,8 +1216,8 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
self.login_user()
resp = self.client.get(reverse('shoppingcart.views.show_receipt', args=[self.cart.id]))
self.assertEqual(resp.status_code, 200)
self.assertIn('FirstNameTesting123', resp.content)
self.assertIn('80.00', resp.content)
self.assertIn('FirstNameTesting123', resp.content.decode('utf-8'))
self.assertIn('80.00', resp.content.decode('utf-8'))
((template, context), _) = render_mock.call_args # pylint: disable=unpacking-non-sequence
self.assertEqual(template, 'shoppingcart/receipt.html')
@@ -1252,11 +1281,13 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
# when order_type = 'business' the user is not enrolled in the
# course but presented with the enrollment links
self.assertFalse(CourseEnrollment.is_enrolled(self.cart.user, self.course_key))
self.assertIn('FirstNameTesting123', resp.content)
self.assertIn('80.00', resp.content)
self.assertIn('FirstNameTesting123', resp.content.decode('utf-8'))
self.assertIn('80.00', resp.content.decode('utf-8'))
# check for the enrollment codes content
self.assertIn('Please send each professional one of these unique registration codes to enroll into the course.',
resp.content)
self.assertIn(
'Please send each professional one of these unique registration codes to enroll into the course.',
resp.content.decode('utf-8')
)
# fetch the newly generated registration codes
course_registration_codes = CourseRegistrationCode.objects.filter(order=self.cart)
@@ -1272,11 +1303,14 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
self.assertFalse(context['reg_code_info_list'][0]['is_redeemed'])
self.assertFalse(context['reg_code_info_list'][1]['is_redeemed'])
self.assertIn(self.cart.purchase_time.strftime(u"%B %d, %Y"), resp.content)
self.assertIn(self.cart.company_name, resp.content)
self.assertIn(self.cart.company_contact_name, resp.content)
self.assertIn(self.cart.company_contact_email, resp.content)
self.assertIn(self.cart.recipient_email, resp.content)
self.assertIn(
self.cart.purchase_time.strftime(u"%B %d, %Y"),
resp.content.decode('utf-8')
)
self.assertIn(self.cart.company_name, resp.content.decode('utf-8'))
self.assertIn(self.cart.company_contact_name, resp.content.decode('utf-8'))
self.assertIn(self.cart.company_contact_email, resp.content.decode('utf-8'))
self.assertIn(self.cart.recipient_email, resp.content.decode('utf-8'))
self.assertIn(u"Invoice #{order_id}".format(order_id=self.cart.id), resp.content.decode(resp.charset))
codes_string = u'You have successfully purchased <b>{total_registration_codes} course registration codes'
self.assertIn(codes_string.format(
@@ -1290,7 +1324,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
#now activate the user by enrolling him/her to the course
response = self.client.post(redeem_url)
self.assertEquals(response.status_code, 200)
self.assertIn('View Dashboard', response.content)
self.assertIn('View Dashboard', response.content.decode('utf-8'))
# now view the receipt page again to see if any registration codes
# has been expired or not
@@ -1320,8 +1354,8 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
resp = self.client.get(reverse('shoppingcart.views.show_receipt', args=[self.cart.id]))
self.assertEqual(resp.status_code, 200)
self.assertIn('FirstNameTesting123', resp.content)
self.assertIn('80.00', resp.content)
self.assertIn('FirstNameTesting123', resp.content.decode('utf-8'))
self.assertIn('80.00', resp.content.decode('utf-8'))
((template, context), _) = render_mock.call_args
@@ -1348,7 +1382,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
self.login_user()
resp = self.client.get(reverse('shoppingcart.views.show_receipt', args=[self.cart.id]))
self.assertEqual(resp.status_code, 200)
self.assertIn('40.00', resp.content)
self.assertIn('40.00', resp.content.decode('utf-8'))
((template, context), _tmp) = render_mock.call_args
self.assertEqual(template, 'shoppingcart/receipt.html')
@@ -1457,7 +1491,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
self.add_course_to_user_cart(self.testing_course.id)
resp = self.client.get(reverse('courseware', kwargs={'course_id': text_type(self.course.id)}))
self.assertEqual(resp.status_code, 200)
self.assertIn('<a class="shopping-cart"', resp.content)
self.assertIn('<a class="shopping-cart"', resp.content.decode('utf-8'))
def test_shopping_cart_navigation_link_and_not_on_courseware(self):
"""
@@ -1468,7 +1502,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
self.add_course_to_user_cart(self.testing_course.id)
resp = self.client.get(reverse('dashboard'))
self.assertEqual(resp.status_code, 200)
self.assertIn('<a class="shopping-cart"', resp.content)
self.assertIn('<a class="shopping-cart"', resp.content.decode('utf-8'))
class ReceiptRedirectTest(SharedModuleStoreTestCase):