class TestDynamicDiscountCoupon(VouchersTest): """ Tests for Single Course Discount Coupons """ def setUp(self): """ Prepare setup for running tests """ super(TestDynamicDiscountCoupon, self).setUp() # Initialize common variables course_id, course_info = random.choice(COURSES_CATALOG.items()) self.course_id = course_id self.course_price = course_info['price'] self.total_price = course_info['price'] self.course_title = course_info['title'] # Initialize all page objects self.course_about = CourseAboutPage(self.browser, self.course_id) @skip("Need to rewrite tests for sandbox") def test_discount_single_use_percentage_code(self): """ Scenario: Dynamic Discount Single Use Percentage Code: Code cannot be reused """ self.coupon = Coupon( COURSE_CATALOG_TYPE['multi'], COUPON_TYPE['disc'], VOUCHER_TYPE['single'], catalog_query=CATALOG_QUERY, stock_record_ids=[], course_seat_types=COURSE_SEAT_TYPES['prof'], benefit_type=BENEFIT_TYPE['per'], benefit_value=BENEFIT_VALUE['per'] ) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Login to application using the existing credentials self.login_page.visit() # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id) ) self.enroll_using_discount_code(coupon_code) self.assert_enrollment_and_logout() # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id) ) self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), SINGLE_USE_CODE_REUSE_ERROR.format(coupon_code) )
class TestDynamicDiscountCoupon(VouchersTest): """ Tests for Single Course Discount Coupons """ def setUp(self): """ Prepare setup for running tests """ super(TestDynamicDiscountCoupon, self).setUp() # Initialize common variables course_id, course_info = random.choice(list(COURSES_CATALOG.items())) self.course_id = course_id self.course_price = course_info['price'] self.total_price = course_info['price'] self.course_title = course_info['title'] # Initialize all page objects self.course_about = CourseAboutPage(self.browser, self.course_id) @skip("Need to rewrite tests for sandbox") def test_discount_single_use_percentage_code(self): """ Scenario: Dynamic Discount Single Use Percentage Code: Code cannot be reused """ self.coupon = Coupon(COURSE_CATALOG_TYPE['multi'], COUPON_TYPE['disc'], VOUCHER_TYPE['single'], catalog_query=CATALOG_QUERY, stock_record_ids=[], course_seat_types=COURSE_SEAT_TYPES['prof'], benefit_type=BENEFIT_TYPE['per'], benefit_value=BENEFIT_VALUE['per']) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Login to application using the existing credentials self.login_page.visit() # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id)) self.enroll_using_discount_code(coupon_code) self.assert_enrollment_and_logout_of_ecommerce() # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id)) self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), SINGLE_USE_CODE_REUSE_ERROR.format(coupon_code))
class TestEnrollmentCoupon(VouchersTest): """ Tests for Single Course Enrollment Coupons """ def setUp(self): """ Prepare setup for running tests """ super(TestEnrollmentCoupon, self).setUp() # Initialize common variables self.course_info = get_wl_course_info(org=COURSE_ORG, num=COURSE_NUMBER, run=COURSE_RUN) self.course_id = str(get_course_key(self.course_info)) self.course_title = self.course_info["display_name"] self.course_price = DEFAULT_COURSE_PRICE self.total_price = DEFAULT_COURSE_PRICE self.stock_record_id = self.ecommerce_api.get_stock_record_id( self.course_id, self.course_title) def test_enrollment_single_use_code(self): """ Scenario: Enrollment Single Use Code: Each code can be used by one person successfully """ self.coupon = Coupon(COURSE_CATALOG_TYPE['single'], COUPON_TYPE['enroll'], VOUCHER_TYPE['single'], course_id=self.course_info, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, quantity=2) self.coupon.setup_coupons_using_api(self.course_price) coupon_codes = self.coupon.coupon_codes # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) for coupon_code in coupon_codes: # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id)) self.enroll_using_enrollment_code(coupon_code) self.assert_enrollment_and_logout() def test_enrollment_once_per_customer_code_max_limit(self): """ Scenario: Enrollment Once Per Customer - Code Max Limit: Each code can be used up to the number of allowed uses and after that it is not usable by any user """ maximum_uses = 2 self.coupon = Coupon(COURSE_CATALOG_TYPE['single'], COUPON_TYPE['enroll'], VOUCHER_TYPE['once_per_cust'], course_id=self.course_info, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, max_uses=maximum_uses) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Login to application using the existing credentials for i in range(maximum_uses): # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id)) if i < maximum_uses: self.enroll_using_enrollment_code(coupon_code) self.assert_enrollment_and_logout() else: self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), ONCE_PER_CUSTOMER_CODE_MAX_LIMIT) def test_enrollment_single_use_code_future(self): """ Scenario: Enrollment Single Use Code: Relevant error message is displayed on the use of future coupon """ self.coupon = Coupon(COURSE_CATALOG_TYPE['single'], COUPON_TYPE['enroll'], VOUCHER_TYPE['single'], start_datetime=FUTURE_START_DATE, course_id=self.course_info, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id)) self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), FUTURE_CODE_ERROR.format(coupon_code)) def test_apply_enrollment_single_use_redeem_url(self): """ Scenario: Enrollment Single Use Redeem URL: URL cannot be reused """ self.coupon = Coupon(COURSE_CATALOG_TYPE['single'], COUPON_TYPE['enroll'], VOUCHER_TYPE['single'], course_id=self.course_info, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) self.register_using_api() self.redeem_single_course_enrollment_coupon(coupon_code, self.receipt_page) self.ecom_cookies = self.browser.get_cookies() self.receipt_page.wait_for_page() self.verify_receipt_info_for_discounted_course() self.receipt_page.click_in_nav_to_go_to_dashboard() self.dashboard_page.wait_for_page() self.assert_enrollment_and_logout() self.register_using_api() self.redeem_single_course_enrollment_coupon( coupon_code, self.redeem_coupon_error_page) self.assertEqual(self.redeem_coupon_error_page.error_message, SINGLE_USE_REDEEM_URL_REUSE_ERROR) @skip("test case modification in progress") def test_enrollment_once_per_customer_redeem_url_email_domain(self): """ Scenario: Enrollment Once Per Customer URL: URL can be used only by users of valid email domains """ self.coupon = Coupon(COURSE_CATALOG_TYPE['single'], COUPON_TYPE['enroll'], VOUCHER_TYPE['once_per_cust'], course_id=self.course_info, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, email_domains=VALID_EMAIL_DOMAIN) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Login to application using the existing credentials invalid_domain_users = list(INVALID_DOMAIN_USERS.values()) # Verify that coupon url cannot be used for unauthorized email domain invalid_domain_user = random.choice(invalid_domain_users) self.login_page.visit() self.login_user_using_ui(invalid_domain_user, PASSWORD) self.redeem_single_course_enrollment_coupon( coupon_code, self.redeem_coupon_error_page) self.assertEqual(self.redeem_coupon_error_page.error_message, INVALID_DOMAIN_ERROR_MESSAGE_ON_REDEEM_URL) def test_enrollment_once_per_customer_redeem_url_expired(self): """ Scenario: Enrollment Once Per Customer Redeem URL: Relevant error message is displayed on the use of expired redeem url """ self.coupon = Coupon(COURSE_CATALOG_TYPE['single'], COUPON_TYPE['enroll'], VOUCHER_TYPE['once_per_cust'], end_datetime=EXPIRED_END_DATE, course_id=self.course_info, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Register to application using api self.register_using_api() redeem_coupon = RedeemCouponPage(self.browser, coupon_code).visit() self.assertEqual(redeem_coupon.error_message, EXPIRED_REDEEM_URL_ERROR)
class TestDynamicEnrollmentCoupon(VouchersTest): """ Tests for Single Course Enrollment Coupons """ def setUp(self): """ Prepare setup for running tests """ super(TestDynamicEnrollmentCoupon, self).setUp() # Initialize common variables course_id, course_info = random.choice(COURSES_CATALOG.items()) self.course_id = course_id self.course_price = course_info['price'] self.total_price = course_info['price'] self.course_title = course_info['title'] # Initialize all page objects self.course_about = CourseAboutPage(self.browser, self.course_id) @skip("Need to rewrite tests for sandbox") def test_enrollment_once_per_customer_code_max_limit(self): """ Scenario: Dynamic Enrollment Once Per Customer - Code Max Limit: Each code can be used up to the number of allowed uses and after that it is not usable by any user """ maximum_uses = 2 self.coupon = Coupon(COURSE_CATALOG_TYPE['multi'], COUPON_TYPE['enroll'], VOUCHER_TYPE['once_per_cust'], catalog_query=CATALOG_QUERY, course_seat_types=COURSE_SEAT_TYPES['prof'], stock_record_ids=[], max_uses=maximum_uses) self.coupon.setup_coupons_using_api(self.course_price) self.addCleanup(self.coupon.delete_coupon) coupon_code = self.coupon.coupon_codes[0] for i in range(maximum_uses): if i < maximum_uses: # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id)) self.enroll_using_enrollment_code(coupon_code) self.assert_enrollment_and_logout() else: # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id)) self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), ONCE_PER_CUSTOMER_CODE_MAX_LIMIT) @skip("Need to rewrite tests for sandbox") def test_apply_enrollment_once_per_customer_redeem_url(self): """ Scenario: Registered Users: Dynamic Enrollment Once Per Customer Redeem URL: Each URL can be used up to the number of allowed uses and after that it is not usable by any user """ maximum_uses = 2 self.coupon = Coupon(COURSE_CATALOG_TYPE['multi'], COUPON_TYPE['enroll'], VOUCHER_TYPE['once_per_cust'], catalog_query=CATALOG_QUERY, course_seat_types=COURSE_SEAT_TYPES['prof'], stock_record_ids=[], max_uses=maximum_uses) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] for i in range(maximum_uses): if i < maximum_uses: # Register to application using api self.register_using_api() self.redeem_multi_course_enrollment_coupon( coupon_code, self.login_page, self.course_title) self.login_page.authenticate_user("coupon_user", PASSWORD) self.receipt_page.wait_for_page() self.verify_receipt_info_for_discounted_course() self.receipt_page.click_in_nav_to_go_to_dashboard() self.dashboard_page.wait_for_page() self.assert_enrollment_and_logout() else: self.register_using_api() redeem_coupon = RedeemCouponPage(self.browser, coupon_code).visit() self.assertEqual(redeem_coupon.error_message, ONCE_PER_CUSTOMER_REDEEM_URL_MAX_LIMIT)
class TestDiscountCoupon(VouchersTest): """ Tests for Single Course Discount Coupons """ def setUp(self): super(TestDiscountCoupon, self).setUp() # Initialize common variables self.course_info = get_wl_course_info( org=COURSE_ORG, num=COURSE_NUMBER, run=COURSE_RUN ) self.course_id = str(get_course_key(self.course_info)) self.course_title = self.course_info["display_name"] self.course_price = DEFAULT_COURSE_PRICE self.total_price = DEFAULT_COURSE_PRICE self.stock_record_id = self.ecommerce_api.get_stock_record_id( self.course_id, self.course_title ) def test_discount_single_use_percentage_code(self): """ Scenario: Discount Single Use Percentage Code: Code cannot be reused """ self.coupon = Coupon( COURSE_CATALOG_TYPE['single'], COUPON_TYPE['disc'], VOUCHER_TYPE['single'], course_id=self.course_id, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, benefit_type=BENEFIT_TYPE['per'], benefit_value=BENEFIT_VALUE['per'] ) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id) ) self.enroll_using_discount_code(coupon_code) self.assert_enrollment_and_logout() self.register_using_api( construct_course_basket_page_url(self.course_id) ) self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), SINGLE_USE_CODE_REUSE_ERROR.format(coupon_code) ) @skip('skipped as coupon creation is behaving erratically') def test_discount_once_per_customer_fixed_code_email_domain(self): """ Scenario: Discount Once Per Customer Fixed Code: Code cannot be used by users of invalid email domains """ self.coupon = Coupon( COURSE_CATALOG_TYPE['single'], COUPON_TYPE['disc'], VOUCHER_TYPE['once_per_cust'], course_id=self.course_id, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, benefit_type=BENEFIT_TYPE['abs'], benefit_value=BENEFIT_VALUE['fixed'], email_domains=VALID_EMAIL_DOMAIN ) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Login to application using the invalid domain user credentials invalid_domain_users = list(INVALID_DOMAIN_USERS.values()) # Verify that coupon code cannot be added for unauthorized email domain invalid_domain_user = random.choice(invalid_domain_users) self.login_page.visit() self.login_user_using_ui(invalid_domain_user, PASSWORD) self.go_to_basket() self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), INVALID_DOMAIN_ERROR_MESSAGE_ON_BASKET ) def test_discount_single_use_fixed_code_expired(self): """ Scenario: Discount Single Use Fixed Code: Relevant error message is displayed on the use of Expired coupon """ self.coupon = Coupon( COURSE_CATALOG_TYPE['single'], COUPON_TYPE['disc'], VOUCHER_TYPE['single'], end_datetime=EXPIRED_END_DATE, course_id=self.course_id, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, benefit_type=BENEFIT_TYPE['abs'], benefit_value=BENEFIT_VALUE['fixed'] ) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id) ) self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), EXPIRED_CODE_ERROR.format(coupon_code) ) def test_discount_single_use_fixed_redeem_url(self): """ Scenario: Existing Users - Discount Single Use Fixed Redeem URL: Each redeem url can be used by one person successfully """ self.coupon = Coupon( COURSE_CATALOG_TYPE['single'], COUPON_TYPE['disc'], VOUCHER_TYPE['single'], course_id=self.course_id, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, benefit_type=BENEFIT_TYPE['abs'], benefit_value=BENEFIT_VALUE['fixed'], quantity=2 ) self.coupon.setup_coupons_using_api(self.course_price) coupon_codes = self.coupon.coupon_codes # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) for coupon_code in coupon_codes: # Register to application using api self.register_using_api() self.redeem_single_course_discount_coupon(coupon_code) self.basket_page.wait_for_page() self.ecom_cookies = self.browser.get_cookies() self.make_payment_after_discount() self.dashboard_page.wait_for_page() self.assert_enrollment_and_logout() @skipIf(TEST_ENV == "stage", "skip tests on stage") def test_discount_once_per_customer_percentage_redeem_url(self): """ Scenario: Inactive Users - Discount Once Per Customer Percentage Redeem URL: URL cannot be used twice by he same user """ self.coupon = Coupon( COURSE_CATALOG_TYPE['single'], COUPON_TYPE['disc'], VOUCHER_TYPE['once_per_cust'], course_id=self.course_id, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, benefit_type=BENEFIT_TYPE['per'], benefit_value=BENEFIT_VALUE['per'] ) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) self.home.visit() self.redeem_single_course_discount_coupon(coupon_code) self.login_page.wait_for_page() self.login_page.toggle_to_registration_page() self.registration_page.wait_for_page() user_name = str(uuid.uuid4().node) temp_mail = user_name + "@example.com" self.registration_page.register_white_label_user( get_white_label_registration_fields( email=temp_mail, username=user_name ) ) self.single_seat_basket.wait_for_page() self.make_payment_after_discount() self.assert_course_added_to_dashboard() redeem_coupon = RedeemCouponPage(self.browser, coupon_code).visit() self.assertEqual( redeem_coupon.error_message, ONCE_PER_CUSTOMER_REDEEM_URL_SAME_USER_REUSE ) def test_discount_once_per_customer_fixed_redeem_url_future(self): """ Scenario: Discount Once Per Customer Fixed Redeem URL: Relevant error message is displayed on the use of future redeem url """ self.coupon = Coupon( COURSE_CATALOG_TYPE['single'], COUPON_TYPE['disc'], VOUCHER_TYPE['once_per_cust'], start_datetime=FUTURE_START_DATE, course_id=self.course_id, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, benefit_type=BENEFIT_TYPE['abs'], benefit_value=BENEFIT_VALUE['fixed'], max_uses=2 ) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Register to application using api self.register_using_api() redeem_coupon = RedeemCouponPage(self.browser, coupon_code).visit() self.assertEqual( redeem_coupon.error_message, FUTURE_REDEEM_URL_ERROR )
class TestDiscountCoupon(VouchersTest): """ Tests for Single Course Discount Coupons """ def setUp(self): super(TestDiscountCoupon, self).setUp() # Initialize common variables self.course_info = get_wl_course_info(org=COURSE_ORG, num=COURSE_NUMBER, run=COURSE_RUN) self.course_id = str(get_course_key(self.course_info)) self.course_title = self.course_info["display_name"] self.course_price = DEFAULT_COURSE_PRICE self.total_price = DEFAULT_COURSE_PRICE self.stock_record_id = self.ecommerce_api.get_stock_record_id( self.course_id, self.course_title) def test_discount_single_use_percentage_code(self): """ Scenario: Discount Single Use Percentage Code: Code cannot be reused """ self.coupon = Coupon(COURSE_CATALOG_TYPE['single'], COUPON_TYPE['disc'], VOUCHER_TYPE['single'], course_id=self.course_id, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, benefit_type=BENEFIT_TYPE['per'], benefit_value=BENEFIT_VALUE['per']) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id)) self.enroll_using_discount_code(coupon_code) self.assert_enrollment_and_logout() self.register_using_api( construct_course_basket_page_url(self.course_id)) self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), SINGLE_USE_CODE_REUSE_ERROR.format(coupon_code)) @skip('skipped as coupon creation is behaving erratically') def test_discount_once_per_customer_fixed_code_email_domain(self): """ Scenario: Discount Once Per Customer Fixed Code: Code cannot be used by users of invalid email domains """ self.coupon = Coupon(COURSE_CATALOG_TYPE['single'], COUPON_TYPE['disc'], VOUCHER_TYPE['once_per_cust'], course_id=self.course_id, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, benefit_type=BENEFIT_TYPE['abs'], benefit_value=BENEFIT_VALUE['fixed'], email_domains=VALID_EMAIL_DOMAIN) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Login to application using the invalid domain user credentials invalid_domain_users = list(INVALID_DOMAIN_USERS.values()) # Verify that coupon code cannot be added for unauthorized email domain invalid_domain_user = random.choice(invalid_domain_users) self.login_page.visit() self.login_user_using_ui(invalid_domain_user, PASSWORD) self.go_to_basket() self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), INVALID_DOMAIN_ERROR_MESSAGE_ON_BASKET) def test_discount_single_use_fixed_code_expired(self): """ Scenario: Discount Single Use Fixed Code: Relevant error message is displayed on the use of Expired coupon """ self.coupon = Coupon(COURSE_CATALOG_TYPE['single'], COUPON_TYPE['disc'], VOUCHER_TYPE['single'], end_datetime=EXPIRED_END_DATE, course_id=self.course_id, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, benefit_type=BENEFIT_TYPE['abs'], benefit_value=BENEFIT_VALUE['fixed']) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id)) self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), EXPIRED_CODE_ERROR.format(coupon_code)) def test_discount_single_use_fixed_redeem_url(self): """ Scenario: Existing Users - Discount Single Use Fixed Redeem URL: Each redeem url can be used by one person successfully """ self.coupon = Coupon(COURSE_CATALOG_TYPE['single'], COUPON_TYPE['disc'], VOUCHER_TYPE['single'], course_id=self.course_id, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, benefit_type=BENEFIT_TYPE['abs'], benefit_value=BENEFIT_VALUE['fixed'], quantity=2) self.coupon.setup_coupons_using_api(self.course_price) coupon_codes = self.coupon.coupon_codes # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) for coupon_code in coupon_codes: # Register to application using api self.register_using_api() self.redeem_single_course_discount_coupon(coupon_code) self.basket_page.wait_for_page() self.ecom_cookies = self.browser.get_cookies() self.make_payment_after_discount() self.dashboard_page.wait_for_page() self.assert_enrollment_and_logout() @skipIf(TEST_ENV == "stage", "skip tests on stage") def test_discount_once_per_customer_percentage_redeem_url(self): """ Scenario: Inactive Users - Discount Once Per Customer Percentage Redeem URL: URL cannot be used twice by he same user """ self.coupon = Coupon(COURSE_CATALOG_TYPE['single'], COUPON_TYPE['disc'], VOUCHER_TYPE['once_per_cust'], course_id=self.course_id, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, benefit_type=BENEFIT_TYPE['per'], benefit_value=BENEFIT_VALUE['per']) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) self.home.visit() self.redeem_single_course_discount_coupon(coupon_code) self.login_page.wait_for_page() self.login_page.toggle_to_registration_page() self.registration_page.wait_for_page() user_name = str(uuid.uuid4().node) temp_mail = user_name + "@example.com" self.registration_page.register_white_label_user( get_white_label_registration_fields(email=temp_mail, username=user_name)) self.single_seat_basket.wait_for_page() self.make_payment_after_discount() self.assert_course_added_to_dashboard() redeem_coupon = RedeemCouponPage(self.browser, coupon_code).visit() self.assertEqual(redeem_coupon.error_message, ONCE_PER_CUSTOMER_REDEEM_URL_SAME_USER_REUSE) def test_discount_once_per_customer_fixed_redeem_url_future(self): """ Scenario: Discount Once Per Customer Fixed Redeem URL: Relevant error message is displayed on the use of future redeem url """ self.coupon = Coupon(COURSE_CATALOG_TYPE['single'], COUPON_TYPE['disc'], VOUCHER_TYPE['once_per_cust'], start_datetime=FUTURE_START_DATE, course_id=self.course_id, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, benefit_type=BENEFIT_TYPE['abs'], benefit_value=BENEFIT_VALUE['fixed'], max_uses=2) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Register to application using api self.register_using_api() redeem_coupon = RedeemCouponPage(self.browser, coupon_code).visit() self.assertEqual(redeem_coupon.error_message, FUTURE_REDEEM_URL_ERROR)
class TestEnrollmentCoupon(VouchersTest): """ Tests for Single Course Enrollment Coupons """ def setUp(self): """ Prepare setup for running tests """ super(TestEnrollmentCoupon, self).setUp() # Initialize common variables self.course_info = get_wl_course_info( org=COURSE_ORG, num=COURSE_NUMBER, run=COURSE_RUN ) self.course_id = str(get_course_key(self.course_info)) self.course_title = self.course_info["display_name"] self.course_price = DEFAULT_COURSE_PRICE self.total_price = DEFAULT_COURSE_PRICE self.stock_record_id = self.ecommerce_api.get_stock_record_id( self.course_id, self.course_title ) def test_enrollment_single_use_code(self): """ Scenario: Enrollment Single Use Code: Each code can be used by one person successfully """ self.coupon = Coupon( COURSE_CATALOG_TYPE['single'], COUPON_TYPE['enroll'], VOUCHER_TYPE['single'], course_id=self.course_info, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, quantity=2 ) self.coupon.setup_coupons_using_api(self.course_price) coupon_codes = self.coupon.coupon_codes # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) for coupon_code in coupon_codes: # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id) ) self.enroll_using_enrollment_code(coupon_code) self.assert_enrollment_and_logout() def test_enrollment_once_per_customer_code_max_limit(self): """ Scenario: Enrollment Once Per Customer - Code Max Limit: Each code can be used up to the number of allowed uses and after that it is not usable by any user """ maximum_uses = 2 self.coupon = Coupon( COURSE_CATALOG_TYPE['single'], COUPON_TYPE['enroll'], VOUCHER_TYPE['once_per_cust'], course_id=self.course_info, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, max_uses=maximum_uses ) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Login to application using the existing credentials for i in range(maximum_uses): # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id) ) if i < maximum_uses: self.enroll_using_enrollment_code(coupon_code) self.assert_enrollment_and_logout() else: self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), ONCE_PER_CUSTOMER_CODE_MAX_LIMIT ) def test_enrollment_single_use_code_future(self): """ Scenario: Enrollment Single Use Code: Relevant error message is displayed on the use of future coupon """ self.coupon = Coupon( COURSE_CATALOG_TYPE['single'], COUPON_TYPE['enroll'], VOUCHER_TYPE['single'], start_datetime=FUTURE_START_DATE, course_id=self.course_info, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id ) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id) ) self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), FUTURE_CODE_ERROR.format(coupon_code) ) def test_apply_enrollment_single_use_redeem_url(self): """ Scenario: Enrollment Single Use Redeem URL: URL cannot be reused """ self.coupon = Coupon( COURSE_CATALOG_TYPE['single'], COUPON_TYPE['enroll'], VOUCHER_TYPE['single'], course_id=self.course_info, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id ) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) self.register_using_api() self.redeem_single_course_enrollment_coupon( coupon_code, self.receipt_page ) self.ecom_cookies = self.browser.get_cookies() self.receipt_page.wait_for_page() self.verify_receipt_info_for_discounted_course() self.receipt_page.click_in_nav_to_go_to_dashboard() self.dashboard_page.wait_for_page() self.assert_enrollment_and_logout() self.register_using_api() self.redeem_single_course_enrollment_coupon( coupon_code, self.redeem_coupon_error_page ) self.assertEqual( self.redeem_coupon_error_page.error_message, SINGLE_USE_REDEEM_URL_REUSE_ERROR ) @skip("test case modification in progress") def test_enrollment_once_per_customer_redeem_url_email_domain(self): """ Scenario: Enrollment Once Per Customer URL: URL can be used only by users of valid email domains """ self.coupon = Coupon( COURSE_CATALOG_TYPE['single'], COUPON_TYPE['enroll'], VOUCHER_TYPE['once_per_cust'], course_id=self.course_info, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id, email_domains=VALID_EMAIL_DOMAIN ) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Login to application using the existing credentials invalid_domain_users = list(INVALID_DOMAIN_USERS.values()) # Verify that coupon url cannot be used for unauthorized email domain invalid_domain_user = random.choice(invalid_domain_users) self.login_page.visit() self.login_user_using_ui(invalid_domain_user, PASSWORD) self.redeem_single_course_enrollment_coupon( coupon_code, self.redeem_coupon_error_page ) self.assertEqual( self.redeem_coupon_error_page.error_message, INVALID_DOMAIN_ERROR_MESSAGE_ON_REDEEM_URL ) def test_enrollment_once_per_customer_redeem_url_expired(self): """ Scenario: Enrollment Once Per Customer Redeem URL: Relevant error message is displayed on the use of expired redeem url """ self.coupon = Coupon( COURSE_CATALOG_TYPE['single'], COUPON_TYPE['enroll'], VOUCHER_TYPE['once_per_cust'], end_datetime=EXPIRED_END_DATE, course_id=self.course_info, seat_type=SEAT_TYPE['prof'], stock_record_ids=self.stock_record_id ) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] # Delete coupon after test self.addCleanup(self.coupon.delete_coupon) # Register to application using api self.register_using_api() redeem_coupon = RedeemCouponPage(self.browser, coupon_code).visit() self.assertEqual( redeem_coupon.error_message, EXPIRED_REDEEM_URL_ERROR )
class TestDynamicEnrollmentCoupon(VouchersTest): """ Tests for Single Course Enrollment Coupons """ def setUp(self): """ Prepare setup for running tests """ super(TestDynamicEnrollmentCoupon, self).setUp() # Initialize common variables course_id, course_info = random.choice(COURSES_CATALOG.items()) self.course_id = course_id self.course_price = course_info['price'] self.total_price = course_info['price'] self.course_title = course_info['title'] # Initialize all page objects self.course_about = CourseAboutPage(self.browser, self.course_id) @skip("Need to rewrite tests for sandbox") def test_enrollment_once_per_customer_code_max_limit(self): """ Scenario: Dynamic Enrollment Once Per Customer - Code Max Limit: Each code can be used up to the number of allowed uses and after that it is not usable by any user """ maximum_uses = 2 self.coupon = Coupon( COURSE_CATALOG_TYPE['multi'], COUPON_TYPE['enroll'], VOUCHER_TYPE['once_per_cust'], catalog_query=CATALOG_QUERY, course_seat_types=COURSE_SEAT_TYPES['prof'], stock_record_ids=[], max_uses=maximum_uses ) self.coupon.setup_coupons_using_api(self.course_price) self.addCleanup(self.coupon.delete_coupon) coupon_code = self.coupon.coupon_codes[0] for i in range(maximum_uses): if i < maximum_uses: # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id) ) self.enroll_using_enrollment_code(coupon_code) self.assert_enrollment_and_logout() else: # Register to application using api self.register_using_api( construct_course_basket_page_url(self.course_id) ) self.assertEqual( self.error_message_on_invalid_coupon_code(coupon_code), ONCE_PER_CUSTOMER_CODE_MAX_LIMIT ) @skip("Need to rewrite tests for sandbox") def test_apply_enrollment_once_per_customer_redeem_url(self): """ Scenario: Registered Users: Dynamic Enrollment Once Per Customer Redeem URL: Each URL can be used up to the number of allowed uses and after that it is not usable by any user """ maximum_uses = 2 self.coupon = Coupon( COURSE_CATALOG_TYPE['multi'], COUPON_TYPE['enroll'], VOUCHER_TYPE['once_per_cust'], catalog_query=CATALOG_QUERY, course_seat_types=COURSE_SEAT_TYPES['prof'], stock_record_ids=[], max_uses=maximum_uses ) self.coupon.setup_coupons_using_api(self.course_price) coupon_code = self.coupon.coupon_codes[0] for i in range(maximum_uses): if i < maximum_uses: # Register to application using api self.register_using_api() self.redeem_multi_course_enrollment_coupon( coupon_code, self.login_page, self.course_title ) self.login_page.authenticate_user( "coupon_user", PASSWORD ) self.receipt_page.wait_for_page() self.verify_receipt_info_for_discounted_course() self.receipt_page.click_in_nav_to_go_to_dashboard() self.dashboard_page.wait_for_page() self.assert_enrollment_and_logout() else: self.register_using_api() redeem_coupon = RedeemCouponPage( self.browser, coupon_code ).visit() self.assertEqual( redeem_coupon.error_message, ONCE_PER_CUSTOMER_REDEEM_URL_MAX_LIMIT )