def assert_elements_in_schedule(self, url, n_chapters=2, n_sequentials=4, n_verticals=8): """ Helper function to count visible elements in the schedule """ response = self.client.get(url) self.assertEqual(response.status_code, 200) # the schedule contains chapters chapters = json.loads(response.mako_context['schedule']) # pylint: disable=no-member sequentials = flatten( [chapter.get('children', []) for chapter in chapters]) verticals = flatten( [sequential.get('children', []) for sequential in sequentials]) # check that the numbers of nodes at different level are the expected ones self.assertEqual(n_chapters, len(chapters)) self.assertEqual(n_sequentials, len(sequentials)) self.assertEqual(n_verticals, len(verticals)) # extract the locations of all the nodes all_elements = chapters + sequentials + verticals return [ elem['location'] for elem in all_elements if 'location' in elem ]
def setUpClass(cls): """ Course is created here and shared by all the class's tests. """ super(TestFieldOverrides, cls).setUpClass() cls.course = CourseFactory.create() cls.course.enable_ccx = True # Create a course outline start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC) due = datetime.datetime(2010, 7, 7, 0, 0, tzinfo=pytz.UTC) chapters = [ ItemFactory.create(start=start, parent=cls.course) for _ in xrange(2) ] sequentials = flatten( [[ItemFactory.create(parent=chapter) for _ in xrange(2)] for chapter in chapters]) verticals = flatten([[ ItemFactory.create(due=due, parent=sequential) for _ in xrange(2) ] for sequential in sequentials]) blocks = flatten([ # pylint: disable=unused-variable [ItemFactory.create(parent=vertical) for _ in xrange(2)] for vertical in verticals ])
def setUp(self): """ Set up tests """ super(TestFieldOverrides, self).setUp() self.course = course = CourseFactory.create() self.course.enable_ccx = True # Create a course outline self.mooc_start = start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC) self.mooc_due = due = datetime.datetime(2010, 7, 7, 0, 0, tzinfo=pytz.UTC) chapters = [ ItemFactory.create(start=start, parent=course) for _ in xrange(2) ] sequentials = flatten( [[ItemFactory.create(parent=chapter) for _ in xrange(2)] for chapter in chapters]) verticals = flatten([[ ItemFactory.create(due=due, parent=sequential) for _ in xrange(2) ] for sequential in sequentials]) blocks = flatten([ # pylint: disable=unused-variable [ItemFactory.create(parent=vertical) for _ in xrange(2)] for vertical in verticals ]) self.ccx = ccx = CustomCourseForEdX(course_id=course.id, display_name='Test CCX', coach=AdminFactory.create()) ccx.save() patch = mock.patch('ccx.overrides.get_current_ccx') self.get_ccx = get_ccx = patch.start() get_ccx.return_value = ccx self.addCleanup(patch.stop) self.addCleanup(RequestCache.clear_request_cache) inject_field_overrides(iter_blocks(ccx.course), course, AdminFactory.create()) def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes)
def setUp(self): super(TestCoachDashboardSchedule, self).setUp() self.course = course = CourseFactory.create() # Create a course outline self.mooc_start = start = datetime.datetime( 2010, 5, 12, 2, 42, tzinfo=pytz.UTC ) self.mooc_due = due = datetime.datetime( 2010, 7, 7, 0, 0, tzinfo=pytz.UTC ) self.chapters = [ ItemFactory.create(start=start, parent=course) for _ in xrange(2) ] self.sequentials = flatten([ [ ItemFactory.create(parent=chapter) for _ in xrange(2) ] for chapter in self.chapters ]) self.verticals = flatten([ [ ItemFactory.create( start=start, due=due, parent=sequential, graded=True, format='Homework', category=u'vertical' ) for _ in xrange(2) ] for sequential in self.sequentials ]) # Trying to wrap the whole thing in a bulk operation fails because it # doesn't find the parents. But we can at least wrap this part... with self.store.bulk_operations(course.id, emit_signals=False): blocks = flatten([ # pylint: disable=unused-variable [ ItemFactory.create(parent=vertical) for _ in xrange(2) ] for vertical in self.verticals ]) # Create instructor account self.coach = UserFactory.create() # create an instance of modulestore self.mstore = modulestore() # Login with the instructor account self.client.login(username=self.coach.username, password="******") # adding staff to master course. staff = UserFactory() allow_access(self.course, staff, 'staff') self.assertTrue(CourseStaffRole(self.course.id).has_user(staff)) # adding instructor to master course. instructor = UserFactory() allow_access(self.course, instructor, 'instructor') self.assertTrue(CourseInstructorRole(self.course.id).has_user(instructor)) self.assertTrue(modulestore().has_course(self.course.id))
def assert_elements_in_schedule(self, url, n_chapters=2, n_sequentials=4, n_verticals=8): """ Helper function to count visible elements in the schedule """ response = self.client.get(url) # the schedule contains chapters chapters = json.loads(response.mako_context['schedule']) # pylint: disable=no-member sequentials = flatten([chapter.get('children', []) for chapter in chapters]) verticals = flatten([sequential.get('children', []) for sequential in sequentials]) # check that the numbers of nodes at different level are the expected ones self.assertEqual(n_chapters, len(chapters)) self.assertEqual(n_sequentials, len(sequentials)) self.assertEqual(n_verticals, len(verticals)) # extract the locations of all the nodes all_elements = chapters + sequentials + verticals return [elem['location'] for elem in all_elements if 'location' in elem]
def setUp(self): """ Set up tests """ super(TestFieldOverrides, self).setUp() self.course = course = CourseFactory.create() self.course.enable_ccx = True # Create a course outline self.mooc_start = start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC) self.mooc_due = due = datetime.datetime(2010, 7, 7, 0, 0, tzinfo=pytz.UTC) chapters = [ItemFactory.create(start=start, parent=course) for _ in xrange(2)] sequentials = flatten([[ItemFactory.create(parent=chapter) for _ in xrange(2)] for chapter in chapters]) verticals = flatten( [[ItemFactory.create(due=due, parent=sequential) for _ in xrange(2)] for sequential in sequentials] ) blocks = flatten( [ # pylint: disable=unused-variable [ItemFactory.create(parent=vertical) for _ in xrange(2)] for vertical in verticals ] ) self.ccx = ccx = CustomCourseForEdX(course_id=course.id, display_name="Test CCX", coach=AdminFactory.create()) ccx.save() patch = mock.patch("ccx.overrides.get_current_ccx") self.get_ccx = get_ccx = patch.start() get_ccx.return_value = ccx self.addCleanup(patch.stop) self.addCleanup(RequestCache.clear_request_cache) inject_field_overrides(iter_blocks(ccx.course), course, AdminFactory.create()) def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes)
def setUpClass(cls): """ Course is created here and shared by all the class's tests. """ super(TestFieldOverrides, cls).setUpClass() cls.course = CourseFactory.create() cls.course.enable_ccx = True # Create a course outline start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC) due = datetime.datetime(2010, 7, 7, 0, 0, tzinfo=pytz.UTC) chapters = [ItemFactory.create(start=start, parent=cls.course) for _ in xrange(2)] sequentials = flatten([ [ItemFactory.create(parent=chapter) for _ in xrange(2)] for chapter in chapters]) verticals = flatten([ [ItemFactory.create(due=due, parent=sequential) for _ in xrange(2)] for sequential in sequentials]) blocks = flatten([ # pylint: disable=unused-variable [ItemFactory.create(parent=vertical) for _ in xrange(2)] for vertical in verticals])
def setUpClass(cls): """ Set up tests """ super().setUpClass() start = datetime.datetime(2016, 7, 1, 0, 0, tzinfo=UTC) due = datetime.datetime(2016, 7, 8, 0, 0, tzinfo=UTC) cls.course = course = CourseFactory.create(enable_ccx=True, start=start) chapter = ItemFactory.create(start=start, parent=course, category='chapter') sequential = ItemFactory.create( parent=chapter, start=start, due=due, category='sequential', metadata={'graded': True, 'format': 'Homework'} ) vertical = ItemFactory.create( parent=sequential, start=start, due=due, category='vertical', metadata={'graded': True, 'format': 'Homework'} ) # Trying to wrap the whole thing in a bulk operation fails because it # doesn't find the parents. But we can at least wrap this part... with cls.store.bulk_operations(course.id, emit_signals=False): flatten([ItemFactory.create( parent=vertical, start=start, due=due, category="problem", data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'} )] for _ in range(2))