-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This will fix any unknown change from publisher to a course having mobile seats. After this fix mobile team will see mail and adjust price of the course on playstore or appstore. In the longer run we want to replace this solution by changing the course price directly using mobile platform apis. LEARNER-9377
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# .. toggle_name: mail_mobile_team_for_change_in_course | ||
# .. toggle_type: waffle_switch | ||
# .. toggle_default: False | ||
# .. toggle_description: Alert mobile team for a change in a course having mobile seats. | ||
# .. toggle_use_cases: open_edx | ||
# .. toggle_creation_date: 2023-07-25 | ||
# .. toggle_tickets: LEARNER-9377 | ||
# .. toggle_status: supported | ||
MAIL_MOBILE_TEAM_FOR_CHANGE_IN_COURSE = 'mail_mobile_team_for_change_in_course' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import mock | ||
from testfixtures import LogCapture | ||
|
||
from ecommerce.courses.tests.factories import CourseFactory | ||
from ecommerce.extensions.api.utils import send_mail_to_mobile_team_for_change_in_course | ||
from ecommerce.extensions.iap.models import IAPProcessorConfiguration | ||
from ecommerce.tests.testcases import TestCase | ||
|
||
|
||
class UtilTests(TestCase): | ||
def setUp(self): | ||
super(UtilTests, self).setUp() | ||
self.course = CourseFactory(id='test/course/123', name='Test Course 123') | ||
seat = self.course.create_or_update_seat('verified', True, 60) | ||
second_seat = self.course.create_or_update_seat('verified', True, 70) | ||
self.mock_mobile_team_mail = '[email protected]' | ||
self.mock_email_body = { | ||
'subject': 'Course Change Alert for Test Course 123', | ||
'body': 'Course: Test Course 123, Sku: {}, Price: 70.00\n' | ||
'Course: Test Course 123, Sku: {}, Price: 60.00'.format( | ||
second_seat.stockrecords.all()[0].partner_sku, | ||
seat.stockrecords.all()[0].partner_sku | ||
) | ||
} | ||
|
||
def test_send_mail_to_mobile_team_with_no_email_specified(self): | ||
logger_name = 'ecommerce.extensions.api.utils' | ||
email_sender = 'ecommerce.extensions.communication.utils.Dispatcher.dispatch_direct_messages' | ||
msg_t = "Couldn't mail mobile team for change in {}. No email was specified for mobile team in configurations" | ||
msg = msg_t.format(self.course.name) | ||
with LogCapture(logger_name) as utils_logger,\ | ||
mock.patch(email_sender) as mock_send_email: | ||
|
||
send_mail_to_mobile_team_for_change_in_course(self.course, self.course.seat_products.all()) | ||
utils_logger.check_present( | ||
( | ||
logger_name, | ||
'INFO', | ||
msg | ||
) | ||
) | ||
assert mock_send_email.call_count == 0 | ||
|
||
def test_send_mail_to_mobile_team(self): | ||
logger_name = 'ecommerce.extensions.api.utils' | ||
email_sender = 'ecommerce.extensions.communication.utils.Dispatcher.dispatch_direct_messages' | ||
iap_configs = IAPProcessorConfiguration.get_solo() | ||
iap_configs.mobile_team_email = self.mock_mobile_team_mail | ||
iap_configs.save() | ||
with LogCapture(logger_name) as utils_logger,\ | ||
mock.patch(email_sender) as mock_send_email: | ||
|
||
send_mail_to_mobile_team_for_change_in_course(self.course, self.course.seat_products.all()) | ||
utils_logger.check_present( | ||
( | ||
logger_name, | ||
'INFO', | ||
"Sent change in {} email to mobile team.".format(self.course.name) | ||
) | ||
) | ||
assert mock_send_email.call_count == 1 | ||
mock_send_email.assert_called_with(self.mock_mobile_team_mail, self.mock_email_body) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import logging | ||
|
||
from oscar.core.loading import get_class | ||
|
||
from ecommerce.extensions.iap.models import IAPProcessorConfiguration | ||
|
||
Dispatcher = get_class('communication.utils', 'Dispatcher') | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def send_mail_to_mobile_team_for_change_in_course(course, seats): | ||
recipient = IAPProcessorConfiguration.get_solo().mobile_team_email | ||
if not recipient: | ||
msg = "Couldn't mail mobile team for change in %s. No email was specified for mobile team in configurations" | ||
logger.info(msg, course.name) | ||
return | ||
|
||
def format_seat(seat): | ||
seat_template = "Course: {}, Sku: {}, Price: {}" | ||
stock_record = seat.stockrecords.all()[0] | ||
result = seat_template.format( | ||
course.name, | ||
stock_record.partner_sku, | ||
stock_record.price_excl_tax, | ||
) | ||
return result | ||
|
||
formatted_seats = [format_seat(seat) for seat in seats if seat.stockrecords.all()] | ||
|
||
messages = { | ||
'subject': 'Course Change Alert for {}'.format(course.name), | ||
'body': "\n".join(formatted_seats) | ||
} | ||
|
||
Dispatcher().dispatch_direct_messages(recipient, messages) | ||
logger.info("Sent change in %s email to mobile team.", course.name) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.19 on 2023-08-02 08:00 | ||
|
||
from django.db import migrations, models | ||
Check warning on line 3 in ecommerce/extensions/iap/migrations/0006_iapprocessorconfiguration_mobile_team_email.py Codecov / codecov/patchecommerce/extensions/iap/migrations/0006_iapprocessorconfiguration_mobile_team_email.py#L3
|
||
|
||
|
||
class Migration(migrations.Migration): | ||
Check warning on line 6 in ecommerce/extensions/iap/migrations/0006_iapprocessorconfiguration_mobile_team_email.py Codecov / codecov/patchecommerce/extensions/iap/migrations/0006_iapprocessorconfiguration_mobile_team_email.py#L6
|
||
|
||
dependencies = [ | ||
Check warning on line 8 in ecommerce/extensions/iap/migrations/0006_iapprocessorconfiguration_mobile_team_email.py Codecov / codecov/patchecommerce/extensions/iap/migrations/0006_iapprocessorconfiguration_mobile_team_email.py#L8
|
||
('iap', '0005_paymentprocessorresponseextension_meta_data'), | ||
] | ||
|
||
operations = [ | ||
Check warning on line 12 in ecommerce/extensions/iap/migrations/0006_iapprocessorconfiguration_mobile_team_email.py Codecov / codecov/patchecommerce/extensions/iap/migrations/0006_iapprocessorconfiguration_mobile_team_email.py#L12
|
||
migrations.AddField( | ||
model_name='iapprocessorconfiguration', | ||
name='mobile_team_email', | ||
field=models.EmailField(default='', max_length=254, verbose_name='mobile team email'), | ||
), | ||
] |