Skip to content

Commit 687bdd2

Browse files
authored
feat: stop marketing Old Mongo courses (#3309)
They are being sunset and we no longer want to link to them. DEPR-58
1 parent 11bd89d commit 687bdd2

9 files changed

Lines changed: 31 additions & 14 deletions

File tree

course_discovery/apps/api/tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_generate_data_for_studio_api_without_team(self):
169169
mock_logger.assert_called_with(
170170
'No course team admin specified for course [%s]. This may result in a Studio course run '
171171
'being created without a course team.',
172-
run.key.split('/')[1]
172+
run.key.split('+')[1]
173173
)
174174

175175
def test_calculate_course_run_key_run_value_with_multiple_runs_per_trimester(self):

course_discovery/apps/api/v1/tests/test_views/test_catalog_queries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def setUp(self):
1313
self.user = UserFactory(is_staff=True, is_superuser=True)
1414
self.client.force_authenticate(self.user)
1515
self.course = CourseFactory(partner=self.partner, key='simple_key')
16-
self.course_run = CourseRunFactory(course=self.course)
16+
self.course_run = CourseRunFactory(course=self.course, key='simple/key/run')
1717
self.url_base = reverse('api:v1:catalog-query_contains')
1818
self.error_message = 'CatalogQueryContains endpoint requires query and identifiers list(s)'
1919

course_discovery/apps/api/v1/tests/test_views/test_course_runs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
import urllib
33
from unittest import mock
4+
from urllib.parse import urlencode
45

56
import ddt
67
import pytest
@@ -1031,7 +1032,7 @@ def test_filter_by_keys(self):
10311032
CourseRun.objects.all().delete()
10321033
expected = CourseRunFactory.create_batch(3, course__partner=self.partner)
10331034
keys = ','.join([course.key for course in expected])
1034-
url = '{root}?keys={keys}'.format(root=reverse('api:v1:course_run-list'), keys=keys)
1035+
url = '{root}?{params}'.format(root=reverse('api:v1:course_run-list'), params=urlencode({'keys': keys}))
10351036
self.assert_list_results(url, expected)
10361037

10371038
def test_filter_by_marketable(self):

course_discovery/apps/api/v1/tests/test_views/test_courses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
from unittest import mock
3+
from urllib.parse import urlencode
34

45
import ddt
56
import pytest
@@ -269,7 +270,7 @@ def test_list_key_filter(self):
269270
""" Verify the endpoint returns a list of courses filtered by the specified keys. """
270271
courses = CourseFactory.create_batch(3, partner=self.partner)
271272
keys = ','.join([course.key for course in courses])
272-
url = '{root}?keys={keys}'.format(root=reverse('api:v1:course-list'), keys=keys)
273+
url = '{root}?{params}'.format(root=reverse('api:v1:course-list'), params=urlencode({'keys': keys}))
273274

274275
with self.assertNumQueries(49):
275276
response = self.client.get(url)

course_discovery/apps/course_metadata/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from django_extensions.db.models import TimeStampedModel
2222
from elasticsearch.exceptions import RequestError
2323
from elasticsearch_dsl.query import Q as ESDSLQ
24+
from opaque_keys.edx.keys import CourseKey
2425
from parler.models import TranslatableModel, TranslatedFieldsModel
2526
from simple_history.models import HistoricalRecords
2627
from solo.models import SingletonModel
@@ -1983,6 +1984,8 @@ def could_be_marketable(self):
19831984
"""
19841985
if not self.type.is_marketable:
19851986
return False
1987+
if CourseKey.from_string(self.key).deprecated: # Old Mongo courses are not marketed
1988+
return False
19861989
return not self.draft
19871990

19881991
@property

course_discovery/apps/course_metadata/tests/factories.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def course_run_types(self, create, extracted, **kwargs):
210210

211211
class CourseFactory(SalesforceRecordFactory):
212212
uuid = factory.LazyFunction(uuid4)
213-
key = FuzzyText(prefix='course-id/')
213+
key = FuzzyText(prefix='course-id+')
214214
key_for_reruns = FuzzyText(prefix='OrgX+')
215215
title = FuzzyText(prefix="Test çօմɾʂҽ ")
216216
short_description = FuzzyText(prefix="Test çօմɾʂҽ short description")
@@ -292,7 +292,7 @@ class Meta:
292292
class CourseRunFactory(SalesforceRecordFactory):
293293
status = CourseRunStatus.Published
294294
uuid = factory.LazyFunction(uuid4)
295-
key = FuzzyText(prefix='course-run-id/', suffix='/fake')
295+
key = FuzzyText(prefix='course-v1:org+', suffix='+fake')
296296
external_key = None
297297
course = factory.SubFactory(CourseFactory)
298298
title_override = None

course_discovery/apps/course_metadata/tests/test_emails.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def assertEmailNotSent(self, function, reason):
114114
emails.logger.name,
115115
'INFO',
116116
StringComparison('Not sending notification email for template course_metadata/email/.* because ' +
117-
reason),
117+
re.escape(reason)),
118118
)
119119
)
120120

@@ -149,22 +149,23 @@ def test_send_email_for_internal_review(self):
149149
restricted_url = self.partner.lms_admin_url.rstrip('/') + '/embargo/restrictedcourse/'
150150
self.assertEmailSent(
151151
emails.send_email_for_internal_review,
152-
f'^Review requested: {self.course_run.key} - {self.course_run.title}$',
152+
f'^Review requested: {re.escape(self.course_run.key)} - {self.course_run.title}$',
153153
[self.pc],
154154
both_regexes=[
155155
'Dear %s,' % self.pc.full_name,
156-
'MyOrg has submitted %s for review.' % self.course_run.key,
156+
'MyOrg has submitted %s for review.' % re.escape(self.course_run.key),
157157
],
158158
html_regexes=[
159159
'<a href="%s">View this course run in Publisher</a> to review the changes and mark it as reviewed.' %
160160
self.publisher_url,
161-
'This is a good time to <a href="%s">review this course run in Studio</a>.' % self.studio_url,
161+
'This is a good time to <a href="%s">review this course run in Studio</a>.' %
162+
re.escape(self.studio_url),
162163
'Visit the <a href="%s">restricted course admin page</a> to set embargo rules for this course, '
163164
'as needed.' % restricted_url,
164165
],
165166
text_regexes=[
166167
'\n\nPublisher page: %s\n' % self.publisher_url,
167-
'\n\nStudio page: %s\n' % self.studio_url,
168+
'\n\nStudio page: %s\n' % re.escape(self.studio_url),
168169
'\n\nRestricted Course admin: %s\n' % restricted_url,
169170
],
170171
)
@@ -225,7 +226,7 @@ def test_send_email_for_go_live(self):
225226
**kwargs,
226227
)
227228
self.assertEmailContains(
228-
subject=f'^Published: {self.course_run.key} - {self.course_run.title}$',
229+
subject=f'^Published: {re.escape(self.course_run.key)} - {self.course_run.title}$',
229230
to_users=[self.pc],
230231
index=1,
231232
**kwargs,

course_discovery/apps/course_metadata/tests/test_lookups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from urllib.parse import quote
2+
from urllib.parse import quote, urlencode
33

44
import pytest
55
from django.test import TestCase
@@ -17,7 +17,7 @@
1717
class TestAutocomplete:
1818
def assert_valid_query_result(self, client, path, query, expected_result):
1919
""" Asserts a query made against the given endpoint returns the expected result. """
20-
response = client.get(path + f'?q={query}')
20+
response = client.get(path + f'?{urlencode({"q": query})}')
2121
data = json.loads(response.content.decode('utf-8'))
2222
assert len(data['results']) == 1
2323
assert data['results'][0]['text'] == str(expected_result)

course_discovery/apps/course_metadata/tests/test_models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,17 @@ def test_could_be_marketable(self, draft, type_is_marketable, expected):
896896
course_run.save()
897897
assert mock_publish_obj.called == expected
898898

899+
@ddt.data(
900+
('old/mongo/key', False),
901+
('course-v1:modern+style+key', True),
902+
)
903+
@ddt.unpack
904+
def test_old_mongo_not_marketable(self, key, expected):
905+
course_run = factories.CourseRunFactory.create(key=key)
906+
factories.SeatFactory.create(course_run=course_run)
907+
assert course_run.is_marketable == expected
908+
assert course_run.could_be_marketable == expected
909+
899910

900911
class CourseRunTestsThatNeedSetUp(OAuth2Mixin, TestCase):
901912
"""

0 commit comments

Comments
 (0)