Course Overview - require manual seeding of the table.

This commit is contained in:
Nimisha Asthagiri
2015-12-11 12:58:19 -05:00
parent c14c146d0e
commit d6364312f4
6 changed files with 48 additions and 62 deletions

View File

@@ -140,6 +140,7 @@ class PreRequisiteCourseCatalog(ModuleStoreTestCase, LoginEnrollmentTestCase):
org='edX',
course='900',
display_name='pre requisite course',
emit_signals=True,
)
pre_requisite_courses = [unicode(pre_requisite_course.id)]
@@ -155,6 +156,7 @@ class PreRequisiteCourseCatalog(ModuleStoreTestCase, LoginEnrollmentTestCase):
start=datetime.datetime(2013, 1, 1),
end=datetime.datetime(2030, 1, 1),
pre_requisite_courses=pre_requisite_courses,
emit_signals=True,
)
set_prerequisite_courses(course.id, pre_requisite_courses)
@@ -180,7 +182,8 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase):
metadata={
'start': datetime.datetime.now(UTC) + datetime.timedelta(days=4),
'announcement': datetime.datetime.now(UTC) + datetime.timedelta(days=3),
}
},
emit_signals=True,
)
self.starting_earlier = CourseFactory.create(
org='MITx',
@@ -189,12 +192,14 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase):
metadata={
'start': datetime.datetime.now(UTC) + datetime.timedelta(days=2),
'announcement': datetime.datetime.now(UTC) + datetime.timedelta(days=1),
}
},
emit_signals=True,
)
self.course_with_default_start_date = CourseFactory.create(
org='MITx',
number='1002',
display_name='Tech Beta Course',
emit_signals=True,
)
self.factory = RequestFactory()

View File

@@ -34,7 +34,11 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase):
# IMPORTANT: For these tests to work, this domain must be defined via
# DNS configuration (either local or published)
self.course = CourseFactory.create(display_name='Robot_Super_Course', org='TestMicrositeX')
self.course = CourseFactory.create(
display_name='Robot_Super_Course',
org='TestMicrositeX',
emit_signals=True,
)
self.chapter0 = ItemFactory.create(parent_location=self.course.location,
display_name='Overview')
self.chapter9 = ItemFactory.create(parent_location=self.course.location,
@@ -44,13 +48,18 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.section9 = ItemFactory.create(parent_location=self.chapter9.location,
display_name='factory_section')
self.course_outside_microsite = CourseFactory.create(display_name='Robot_Course_Outside_Microsite', org='FooX')
self.course_outside_microsite = CourseFactory.create(
display_name='Robot_Course_Outside_Microsite',
org='FooX',
emit_signals=True,
)
# have a course which explicitly sets visibility in catalog to False
self.course_hidden_visibility = CourseFactory.create(
display_name='Hidden_course',
org='TestMicrositeX',
catalog_visibility=CATALOG_VISIBILITY_NONE,
emit_signals=True,
)
# have a course which explicitly sets visibility in catalog and about to true
@@ -59,6 +68,7 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase):
org='TestMicrositeX',
course="foo",
catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT,
emit_signals=True,
)
def setup_users(self):

View File

@@ -33,12 +33,10 @@ class Command(BaseCommand):
def handle(self, *args, **options):
course_keys = []
if options['all']:
# Have CourseOverview generate course overviews for all
# the courses in the system.
CourseOverview.get_all_courses(force_reseeding=True)
course_keys = [course.id for course in modulestore().get_courses()]
else:
course_keys = []
if len(args) < 1:
raise CommandError('At least one course or --all must be specified.')
try:
@@ -49,4 +47,4 @@ class Command(BaseCommand):
if not course_keys:
log.fatal('No courses specified.')
CourseOverview.get_select_courses(course_keys)
CourseOverview.get_select_courses(course_keys)

View File

@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('course_overviews', '0004_courseoverview_org'),
]
operations = [
migrations.DeleteModel(
name='CourseOverviewGeneratedHistory',
),
]

View File

@@ -447,45 +447,20 @@ class CourseOverview(TimeStampedModel):
return course_overviews
@classmethod
def get_all_courses(cls, force_reseeding=False, org=None):
def get_all_courses(cls, org=None):
"""
Returns all CourseOverview objects in the database.
Arguments:
force_reseeding (bool): Optional parameter.
If True, the modulestore is used as the source of truth for
the list of courses, even if the CourseOverview table was
previously seeded. However, only non-existing CourseOverview
entries or those with older data model versions or will get
populated.
If False, the list of courses is retrieved from the
CourseOverview table if it was previously seeded, falling
back to the modulestore if it wasn't seeded.
org (string): Optional parameter that allows filtering
by organization.
"""
if force_reseeding or not CourseOverviewGeneratedHistory.objects.first():
# Seed the CourseOverview table with data for all
# courses in the system.
course_keys = [course.id for course in modulestore().get_courses()]
course_overviews = cls.get_select_courses(course_keys)
num_courses = len(course_overviews)
CourseOverviewGeneratedHistory.objects.create(num_courses=num_courses)
if org:
course_overviews = [c for c in course_overviews if c.org == org]
else:
# Note: If a newly created course is not returned in this QueryList,
# make sure the "publish" signal was emitted when the course was
# created. For tests using CourseFactory, use emit_signals=True.
# Or pass True for force_reseeding.
course_overviews = CourseOverview.objects.all()
if org:
course_overviews = course_overviews.filter(org=org)
# Note: If a newly created course is not returned in this QueryList,
# make sure the "publish" signal was emitted when the course was
# created. For tests using CourseFactory, use emit_signals=True.
course_overviews = CourseOverview.objects.all()
if org:
course_overviews = course_overviews.filter(org=org)
return course_overviews
@classmethod
@@ -516,14 +491,3 @@ class CourseOverviewTab(models.Model):
"""
tab_id = models.CharField(max_length=50)
course_overview = models.ForeignKey(CourseOverview, db_index=True, related_name="tabs")
class CourseOverviewGeneratedHistory(TimeStampedModel):
"""
Model for keeping track of when CourseOverview Models are
generated/seeded.
"""
num_courses = IntegerField(null=True)
def __unicode__(self):
return self.num_courses

View File

@@ -450,7 +450,7 @@ class CourseOverviewTestCase(ModuleStoreTestCase):
)
def test_get_all_courses(self):
course_ids = [CourseFactory.create().id for __ in range(3)]
course_ids = [CourseFactory.create(emit_signals=True).id for __ in range(3)]
self.assertSetEqual(
{course_overview.id for course_overview in CourseOverview.get_all_courses()},
set(course_ids),
@@ -462,22 +462,14 @@ class CourseOverviewTestCase(ModuleStoreTestCase):
CourseOverview.get_all_courses()
self.assertFalse(mock_get_from_id.called)
CourseOverview.get_all_courses(force_reseeding=True)
self.assertTrue(mock_get_from_id.called)
def test_get_all_courses_by_org(self):
org_courses = [] # list of lists of courses
for index in range(2):
org_courses.append([
CourseFactory.create(org='test_org_' + unicode(index))
CourseFactory.create(org='test_org_' + unicode(index), emit_signals=True)
for __ in range(3)
])
self.assertSetEqual(
{c.id for c in CourseOverview.get_all_courses(org='test_org_0', force_reseeding=True)},
{c.id for c in org_courses[0]},
)
self.assertSetEqual(
{c.id for c in CourseOverview.get_all_courses(org='test_org_1')},
{c.id for c in org_courses[1]},