Add eligible for financial aid and sync with course discovery
ECOM-7532
This commit is contained in:
@@ -35,7 +35,9 @@ class Command(BaseCommand):
|
||||
course_metadata_updated = 0
|
||||
|
||||
for course_run in course_runs:
|
||||
is_course_metadata_updated = False
|
||||
marketing_url = course_run['marketing_url']
|
||||
eligible_for_financial_aid = course_run['eligible_for_financial_aid']
|
||||
course_key = CourseKey.from_string(course_run['key'])
|
||||
try:
|
||||
course_overview = CourseOverview.objects.get(id=course_key)
|
||||
@@ -50,6 +52,14 @@ class Command(BaseCommand):
|
||||
# Check whether course overview's marketing url is outdated - this saves a db hit.
|
||||
if course_overview.marketing_url != marketing_url:
|
||||
course_overview.marketing_url = marketing_url
|
||||
is_course_metadata_updated = True
|
||||
|
||||
# Check whether course overview's eligible for financial aid is outdated
|
||||
if course_overview.eligible_for_financial_aid != eligible_for_financial_aid:
|
||||
course_overview.eligible_for_financial_aid = eligible_for_financial_aid
|
||||
is_course_metadata_updated = True
|
||||
|
||||
if is_course_metadata_updated:
|
||||
course_overview.save()
|
||||
course_metadata_updated += 1
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ class TestSyncCourseRunsCommand(ModuleStoreTestCase):
|
||||
# create a catalog course run with the same course id.
|
||||
self.catalog_course_run = CourseRunFactory(
|
||||
key=unicode(self.course.id),
|
||||
marketing_url='test_marketing_url'
|
||||
marketing_url='test_marketing_url',
|
||||
eligible_for_financial_aid=False
|
||||
)
|
||||
|
||||
def get_course_overview_marketing_url(self, course_id):
|
||||
@@ -38,18 +39,25 @@ class TestSyncCourseRunsCommand(ModuleStoreTestCase):
|
||||
"""
|
||||
return CourseOverview.objects.get(id=course_id).marketing_url
|
||||
|
||||
def test_marketing_url_on_sync(self, mock_catalog_course_runs):
|
||||
def test_course_run_sync(self, mock_catalog_course_runs):
|
||||
"""
|
||||
Verify the updated marketing url on execution of the management command.
|
||||
Verify on executing management command course overview data is updated
|
||||
with course run data from course discovery.
|
||||
"""
|
||||
mock_catalog_course_runs.return_value = [self.catalog_course_run]
|
||||
earlier_marketing_url = self.get_course_overview_marketing_url(self.course.id)
|
||||
course_overview = CourseOverview.objects.get(id=self.course.id)
|
||||
earlier_eligible_for_financial_aid = course_overview.eligible_for_financial_aid
|
||||
|
||||
call_command('sync_course_runs')
|
||||
course_overview.refresh_from_db()
|
||||
updated_marketing_url = self.get_course_overview_marketing_url(self.course.id)
|
||||
updated_eligible_for_financial_aid = course_overview.eligible_for_financial_aid
|
||||
# Assert that the Marketing URL has changed.
|
||||
self.assertNotEqual(earlier_marketing_url, updated_marketing_url)
|
||||
self.assertNotEqual(earlier_eligible_for_financial_aid, updated_eligible_for_financial_aid)
|
||||
self.assertEqual(updated_marketing_url, 'test_marketing_url')
|
||||
self.assertEqual(updated_eligible_for_financial_aid, False)
|
||||
|
||||
@mock.patch(COMMAND_MODULE + '.log.info')
|
||||
def test_course_overview_does_not_exist(self, mock_log_info, mock_catalog_course_runs):
|
||||
|
||||
@@ -88,6 +88,7 @@ class CourseRunFactory(DictFactoryBase):
|
||||
image = ImageFactory()
|
||||
key = factory.LazyFunction(generate_course_run_key)
|
||||
marketing_url = factory.Faker('url')
|
||||
eligible_for_financial_aid = True
|
||||
seats = factory.LazyFunction(partial(generate_instances, SeatFactory))
|
||||
pacing_type = 'self_paced'
|
||||
short_description = factory.Faker('sentence')
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('course_overviews', '0011_courseoverview_marketing_url'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='courseoverview',
|
||||
name='eligible_for_financial_aid',
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
]
|
||||
@@ -98,6 +98,7 @@ class CourseOverview(TimeStampedModel):
|
||||
effort = TextField(null=True)
|
||||
self_paced = BooleanField(default=False)
|
||||
marketing_url = TextField(null=True)
|
||||
eligible_for_financial_aid = BooleanField(default=True)
|
||||
|
||||
@classmethod
|
||||
def _create_from_course(cls, course):
|
||||
|
||||
Reference in New Issue
Block a user