def test_zero_price_purchase(browser, base_test_data, logged_in_student, mocker):
"""
Test that a course can be purchased with a 100%-off coupon
"""
mocker.patch('ecommerce.views.enroll_user_on_success')
# Make a 100% off coupon. By setting the price to $0 we can avoid dealing with Cybersource
coupon = CouponFactory.create(
amount=1,
amount_type=Coupon.PERCENT_DISCOUNT,
coupon_type=Coupon.STANDARD,
content_object=base_test_data.program
)
UserCoupon.objects.create(coupon=coupon, user=logged_in_student)
browser.get("/")
# Click the dashboard link on the upper right of the homepage
browser.click_when_loaded(By.CLASS_NAME, "header-dashboard-link")
browser.assert_no_console_errors()
browser.click_when_loaded(By.CLASS_NAME, "enroll-button")
browser.wait_until_loaded(By.CLASS_NAME, "continue-payment")
# Click back then click the enroll now button again to assert back button behavior
browser.driver.back()
browser.click_when_loaded(By.CLASS_NAME, "enroll-button")
browser.assert_no_console_errors()
# Click 'Continue' on the order summary page
browser.click_when_loaded(By.CLASS_NAME, "continue-payment")
browser.assert_no_console_errors()
browser.wait_until_loaded(By.CLASS_NAME, "toast-message")
# Assert that the purchase went through fine but enrolling in edX failed
# Which makes sense since there is no edX for these tests
assert browser.driver.find_element_by_css_selector(".course-status-messages .status-message .message").text == (
"Something went wrong. You paid for this course but are not enrolled. Contact us for help."
)
browser.assert_no_console_errors()
评论列表
文章目录