forked from openedx-unsupported/ecommerce
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Enable mobile payments for new upcoming courses #15
Open
jawad-khan
wants to merge
2
commits into
2u/main
Choose a base branch
from
LEARNER-9951
base: 2u/main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -24,6 +24,7 @@ | |||||||
from ecommerce.entitlements.utils import create_or_update_course_entitlement | ||||||||
from ecommerce.extensions.api.v2.tests.views import JSON_CONTENT_TYPE | ||||||||
from ecommerce.extensions.catalogue.tests.mixins import DiscoveryTestMixin | ||||||||
from ecommerce.extensions.iap.constants import CREATE_APPSTORE_PRODUCTS_FOR_INAPP | ||||||||
from ecommerce.extensions.iap.utils import create_child_products_for_mobile | ||||||||
from ecommerce.tests.testcases import TestCase | ||||||||
|
||||||||
|
@@ -158,6 +159,7 @@ def setUp(self): | |||||||
self.client.login(username=self.user.username, password=self.password) | ||||||||
|
||||||||
self.publication_switch = toggle_switch('publish_course_modes_to_lms', True) | ||||||||
self.appstore_product_switch = toggle_switch(CREATE_APPSTORE_PRODUCTS_FOR_INAPP, False) | ||||||||
|
||||||||
def _toggle_publication(self, is_enabled): | ||||||||
"""Toggle LMS publication.""" | ||||||||
|
@@ -233,7 +235,7 @@ def assert_entitlement_saved(self, course, expected): | |||||||
self.assertEqual(entitlement.attr.UUID, self.course_uuid) | ||||||||
self.assertEqual(entitlement.stockrecords.get(partner=self.partner).price_excl_tax, expected['price']) | ||||||||
|
||||||||
def assert_seat_saved(self, course, expected, test_mobile_seats=False): | ||||||||
def assert_seat_saved(self, course, expected, test_mobile_seats=True): | ||||||||
certificate_type = '' | ||||||||
verified_product = False | ||||||||
|
||||||||
|
@@ -258,17 +260,17 @@ def assert_seat_saved(self, course, expected, test_mobile_seats=False): | |||||||
self.assertEqual(seat.stockrecords.get(partner=self.partner).price_excl_tax, expected['price']) | ||||||||
|
||||||||
if test_mobile_seats and verified_product: | ||||||||
android_seat = course.seat_products.get(title='Android ' + seat_title) | ||||||||
android_seat = course.seat_products.get(title='Android ' + seat_title.lower()) | ||||||||
self.assertEqual(android_seat.expires, expires) | ||||||||
self.assertEqual(android_seat.stockrecords.get(partner=self.partner).price_excl_tax, expected['price']) | ||||||||
|
||||||||
ios_seat = course.seat_products.get(title='Ios ' + seat_title) | ||||||||
ios_seat = course.seat_products.get(title='Ios ' + seat_title.lower()) | ||||||||
self.assertEqual(ios_seat.expires, expires) | ||||||||
self.assertEqual(ios_seat.stockrecords.get(partner=self.partner).price_excl_tax, expected['price']) | ||||||||
|
||||||||
return seat | ||||||||
|
||||||||
def assert_course_saved(self, course_id, expected, enrollment_code_count=0, test_mobile_seats=False): | ||||||||
def assert_course_saved(self, course_id, expected, enrollment_code_count=0, test_mobile_seats=True): | ||||||||
"""Verify that the expected Course and associated products have been saved.""" | ||||||||
# Verify that Course was saved. | ||||||||
self.assertTrue(Course.objects.filter(id=course_id).exists()) | ||||||||
|
@@ -343,7 +345,7 @@ def test_update(self): | |||||||
response = self.client.put(self.update_path, json.dumps(updated_data), JSON_CONTENT_TYPE) | ||||||||
self.assertEqual(response.status_code, 500) | ||||||||
self.assertEqual(response.data.get('error'), error_msg) | ||||||||
self.assert_course_saved(self.course_id, expected=self.data) | ||||||||
self.assert_course_saved(self.course_id, expected=self.data, test_mobile_seats=False) | ||||||||
|
||||||||
# If publication succeeds, the view should return a 200 and data should be saved. | ||||||||
mock_publish.return_value = None | ||||||||
|
@@ -512,8 +514,8 @@ def test_mobile_seats_update(self, _, __): | |||||||
|
||||||||
# Since we are only concerned with expiry date and price | ||||||||
# therefore we are setting title manually here. | ||||||||
android_seat.product.title = 'Android Seat in A New Name with verified certificate' | ||||||||
ios_seat.product.title = 'Ios Seat in A New Name with verified certificate' | ||||||||
android_seat.product.title = 'Android seat in a new name with verified certificate' | ||||||||
ios_seat.product.title = 'Ios seat in a new name with verified certificate' | ||||||||
android_seat.product.save() | ||||||||
ios_seat.product.save() | ||||||||
with mock.patch.object(LMSPublisher, 'publish') as mock_publish: | ||||||||
|
@@ -523,5 +525,21 @@ def test_mobile_seats_update(self, _, __): | |||||||
response = self.client.put(self.update_path, json.dumps(updated_data), JSON_CONTENT_TYPE) | ||||||||
|
||||||||
self.assertEqual(response.status_code, 200) | ||||||||
self.assert_course_saved(self.course_id, expected=updated_data, | ||||||||
enrollment_code_count=1, test_mobile_seats=True) | ||||||||
self.assert_course_saved(self.course_id, expected=updated_data, enrollment_code_count=1) | ||||||||
|
||||||||
@mock.patch('ecommerce.extensions.api.serializers.create_ios_product') | ||||||||
def test_ios_seat_created(self, mock_create_ios_product): | ||||||||
"""Verify that a Course and associated mobile products can be updated and published.""" | ||||||||
self.create_course_and_seats() | ||||||||
updated_data = self.generate_update_payload() | ||||||||
|
||||||||
with mock.patch.object(LMSPublisher, 'publish') as mock_publish: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you remove mock from here and add something like this
Suggested change
|
||||||||
# If publication succeeds, the view should return a 200 and data should be saved. | ||||||||
mock_publish.return_value = None | ||||||||
self.appstore_product_switch.active = True | ||||||||
self.appstore_product_switch.save() | ||||||||
|
||||||||
response = self.client.put(self.update_path, json.dumps(updated_data), JSON_CONTENT_TYPE) | ||||||||
mock_create_ios_product.assert_called_once() | ||||||||
self.assertEqual(response.status_code, 200) | ||||||||
self.assert_course_saved(self.course_id, expected=updated_data, enrollment_code_count=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap
create_mobile_seat
calls in try-except to catch specific failures (e.g., Android or iOS creation).something like this