-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add watchers functionality to the courses (#4013)
- Loading branch information
1 parent
ae69e29
commit 50dcc9a
Showing
14 changed files
with
288 additions
and
5 deletions.
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
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 |
---|---|---|
|
@@ -1754,7 +1754,8 @@ def test_patch_non_review_fields_does_not_reset_run_status(self): | |
'42YAAAAASUVORK5CYII=', | ||
'video': {'src': 'https://new-videos-r-us/watch?t_s=5'}, | ||
'geolocation': {'location_name': 'Antarctica', 'lng': '32.86', 'lat': '34.21'}, | ||
'location_restriction': {'restriction_type': 'blocklist', 'countries': ['AL'], 'states': ['AZ']} | ||
'location_restriction': {'restriction_type': 'blocklist', 'countries': ['AL'], 'states': ['AZ']}, | ||
'watchers': ['[email protected]'] | ||
} | ||
response = self.client.patch(url, patch_data, format='json') | ||
assert response.status_code == 200 | ||
|
@@ -1764,6 +1765,7 @@ def test_patch_non_review_fields_does_not_reset_run_status(self): | |
official_course_run.refresh_from_db() | ||
assert draft_course_run.status == CourseRunStatus.Reviewed | ||
assert official_course_run.status == CourseRunStatus.Reviewed | ||
assert draft_course.watchers == ['[email protected]'] | ||
|
||
@responses.activate | ||
def test_patch_published(self): | ||
|
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
24 changes: 24 additions & 0 deletions
24
course_discovery/apps/course_metadata/migrations/0329_add_field_watchers.py
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 3.2.20 on 2023-07-17 08:04 | ||
|
||
from django.db import migrations | ||
import multi_email_field.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('course_metadata', '0328_additionalmetadata_display_on_org_page'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='course', | ||
name='watchers', | ||
field=multi_email_field.fields.MultiEmailField(blank=True, default=[], help_text='The list of email addresses that will be notified if any of the course runs is published or scheduled.', verbose_name='Watchers'), | ||
), | ||
migrations.AddField( | ||
model_name='historicalcourse', | ||
name='watchers', | ||
field=multi_email_field.fields.MultiEmailField(blank=True, default=[], help_text='The list of email addresses that will be notified if any of the course runs is published or scheduled.', verbose_name='Watchers'), | ||
), | ||
] |
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
25 changes: 25 additions & 0 deletions
25
...e_discovery/apps/course_metadata/templates/course_metadata/email/watchers_course_url.html
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{% extends "course_metadata/email/email_base.html" %} | ||
{% load i18n %} | ||
{% load django_markup %} | ||
{% block body %} | ||
|
||
<p> | ||
{% if is_course_published %} | ||
{% blocktrans %} | ||
Course '{{course_name}}' has been successfully reviewed by edX and is now published on {{course_publish_date}}. To see live course, go here: <a href="{{course_marketing_url}}">{{course_marketing_url}}</a> | ||
{% endblocktrans %} | ||
{% else %} | ||
{% blocktrans %} | ||
Course '{{course_name}}' has been successfully reviewed by edX and is now ready for publication. The course will be published on {{course_publish_date}}. | ||
To see a preview of the Course About Page, go here: <a href="{{course_marketing_url}}">{{course_marketing_url}}</a> | ||
{% endblocktrans %} | ||
{% endif %} | ||
</p> | ||
|
||
<p> | ||
<strong>Note: The changes will be live on http://edx.org once {{marketing_service_name}} build runs. | ||
The average turnaround time is between 24 to 48 hours.</strong> | ||
</p> | ||
|
||
<!-- End Message Body --> | ||
{% endblock body %} |
14 changes: 14 additions & 0 deletions
14
...se_discovery/apps/course_metadata/templates/course_metadata/email/watchers_course_url.txt
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% load i18n %} | ||
|
||
{% if is_course_published %} | ||
{% blocktrans %} | ||
Course '{{course_name}}' has been successfully reviewed by edX and is now published on {{course_publish_date}}. To see live course, go here: {{course_marketing_url}} | ||
{% endblocktrans %} | ||
{% else %} | ||
{% blocktrans %} | ||
Course '{{course_name}}' has been successfully reviewed by edX and is now ready for publication. The course will be published on {{course_publish_date}}. | ||
To see a preview of the Course About Page, go here: {{course_preview_url}} | ||
{% endblocktrans %} | ||
{% endif %} | ||
Note: The changes will be live on http://edx.org once {{marketing_service_name}} build runs. | ||
The average turnaround time is between 24 to 48 hours. |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from django.conf import settings | ||
from django.contrib.auth.models import Group | ||
from django.core import mail | ||
from django.template.loader import render_to_string | ||
from django.test import TestCase | ||
from opaque_keys.edx.keys import CourseKey | ||
from testfixtures import LogCapture, StringComparison | ||
|
@@ -147,6 +148,32 @@ def test_send_email_for_legal_review(self): | |
], | ||
) | ||
|
||
def test_send_email_to_notify_course_watchers(self): | ||
""" | ||
Verify that send_email_to_notify_course_watchers's happy path works as expected | ||
""" | ||
test_course_run = CourseRunFactory(course=self.course, status=CourseRunStatus.Published) | ||
test_course_run.go_live_date = datetime.datetime.now() | ||
self.course.watchers = ['[email protected]'] | ||
self.course.save() | ||
emails.send_email_to_notify_course_watchers(self.course, test_course_run.go_live_date, test_course_run.status) | ||
email = mail.outbox[0] | ||
|
||
assert email.to == self.course.watchers | ||
assert str(email.subject) == f'Course URL for {self.course.title}' | ||
assert len(mail.outbox) == 1 | ||
assert email.alternatives[0][1] == 'text/html' | ||
|
||
expected_content = render_to_string('course_metadata/email/watchers_course_url.html', { | ||
'is_course_published': True, | ||
'course_name': self.course.title, | ||
'course_publish_date': test_course_run.go_live_date.strftime("%m/%d/%Y"), | ||
'course_marketing_url': self.course.marketing_url, | ||
'marketing_service_name': settings.MARKETING_SERVICE_NAME, | ||
}) | ||
# Compare the expected template content with the email body | ||
assert email.alternatives[0][0] == expected_content | ||
|
||
def test_send_email_for_internal_review(self): | ||
""" | ||
Verify that send_email_for_internal_review's happy path works as expected | ||
|
Oops, something went wrong.