Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
fix: coupon redirect testing for qs addition of paypal redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
grmartin committed Jul 5, 2024
1 parent d9c2531 commit d9ab271
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions ecommerce/coupons/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,16 @@ def tearDown(self):
super().tearDown()
responses.reset()

def redeem_url_with_params(self, code=COUPON_CODE, consent_token=None):
def redeem_url_with_params(self, code=COUPON_CODE, consent_token=None, other_qs_params=None):
""" Constructs the coupon redemption URL with the proper string query parameters. """
params = {
'code': code,
'sku': self.stock_record.partner_sku,
}
if consent_token is not None:
params['consent_token'] = consent_token
if other_qs_params is not None:
params.update(other_qs_params)
return format_url(base=self.redeem_url, params=params)

def create_coupon_and_get_code(
Expand Down Expand Up @@ -387,9 +389,12 @@ def create_coupon_and_get_code(
self.assertEqual(Voucher.objects.filter(code=coupon_code).count(), 1)
return coupon_code, coupon

def redeem_coupon(self, code=COUPON_CODE, consent_token=None):
def redeem_coupon(self, code=COUPON_CODE, consent_token=None, other_qs_params=None):
self.request.user = self.user
return self.client.get(self.redeem_url_with_params(code=code, consent_token=consent_token))
return self.client.get(self.redeem_url_with_params(
code=code,
consent_token=consent_token,
other_qs_params=other_qs_params))

def assert_redirects_to_receipt_page(self, code=COUPON_CODE, consent_token=None):
response = self.redeem_coupon(code=code, consent_token=consent_token)
Expand All @@ -406,9 +411,10 @@ def assert_redirects_to_receipt_page(self, code=COUPON_CODE, consent_token=None)

self.assertRedirects(response, expected_url, status_code=302, fetch_redirect_response=False)

def assert_redemption_page_redirects(self, expected_url, target=200, code=COUPON_CODE, consent_token=None):
def assert_redemption_page_redirects(self, expected_url, target=200, code=COUPON_CODE,
consent_token=None, other_qs_params=None):
""" Verify redirect from redeem page to expected page. """
response = self.redeem_coupon(code=code, consent_token=consent_token)
response = self.redeem_coupon(code=code, consent_token=consent_token, other_qs_params=other_qs_params)
self.assertRedirects(
response, expected_url, status_code=302, target_status_code=target, fetch_redirect_response=False
)
Expand Down Expand Up @@ -495,6 +501,19 @@ def test_basket_redirect_discount_code(self):
self.create_coupon(catalog=self.catalog, code=COUPON_CODE, benefit_value=5)
self.assert_redemption_page_redirects(self.get_coupon_redeem_success_expected_redirect_url())

@responses.activate
def test_basket_redirect_discount_code_with_paypal(self):
""" Verify the view redirects to the basket view when a discount code is provided with a paypal qs param. """
self.mock_course_api_response(course=self.course)
self.mock_account_api(self.request, self.user.username, data={'is_active': True})
self.mock_access_token_response()

self.create_coupon(catalog=self.catalog, code=COUPON_CODE, benefit_value=5)
self.assert_redemption_page_redirects(
self.get_coupon_redeem_success_expected_redirect_url() + '&paypal_redirect=1',
other_qs_params={'paypal_redirect': '1'}
)

@override_flag(REDIRECT_WITH_WAFFLE_TESTING_QUERYSTRING, active=True)
@responses.activate
def test_basket_redirect_discount_code_with_waffle(self):
Expand Down

0 comments on commit d9ab271

Please sign in to comment.