コード例 #1
0
    def test_resume_course_visibility(self):
        SelfPacedConfiguration(enable_course_home_improvements=True).save()
        chapter = ItemFactory.create(category="chapter",
                                     parent_location=self.course.location)
        section = ItemFactory.create(category='section',
                                     parent_location=chapter.location)
        section_url = reverse('courseware_section',
                              kwargs={
                                  'section': section.url_name,
                                  'chapter': chapter.url_name,
                                  'course_id': self.course.id
                              })
        self.client.get(section_url)
        info_url = reverse('info', args=(six.text_type(self.course.id), ))

        # Assuring a non-authenticated user cannot see the resume course button.
        resume_course_url = self.get_resume_course_url(info_url)
        self.assertEqual(resume_course_url, None)

        # Assuring an unenrolled user cannot see the resume course button.
        self.setup_user()
        resume_course_url = self.get_resume_course_url(info_url)
        self.assertEqual(resume_course_url, None)

        # Assuring an enrolled user can see the resume course button.
        self.enroll(self.course)
        resume_course_url = self.get_resume_course_url(info_url)
        self.assertEqual(resume_course_url, section_url)
コード例 #2
0
 def setUp(self):
     super(BaseCertSignalsTestCase, self).setUp()
     # allow self-paced courses
     SelfPacedConfiguration(enabled=True).save()
     self.course = CourseFactory.create(self_paced=True)
     self.store = modulestore()
     self.mock_app_settings = mock.Mock()
コード例 #3
0
 def test_course_info_feature_flag(self):
     SelfPacedConfiguration(enable_course_home_improvements=False).save()
     self.setup_course_and_user()
     self.client.login(username=self.user.username, password=TEST_PASSWORD)
     url = reverse('info', args=(self.course.id, ))
     response = self.client.get(url)
     self.assertNotIn('date-summary', response.content)
コード例 #4
0
    def setUp(self):
        super(SelfPacedDateOverrideTest, self).setUp()

        SelfPacedConfiguration(enabled=True).save()

        self.non_staff_user, __ = self.create_non_staff_user()
        self.now = datetime.datetime.now(pytz.UTC).replace(microsecond=0)
        self.future = self.now + datetime.timedelta(days=30)
コード例 #5
0
 def test_last_accessed_courseware_not_shown(self):
     """
     Test that the last accessed courseware link is not shown if there
     is no course content.
     """
     SelfPacedConfiguration(enable_course_home_improvements=True).save()
     url = reverse('info', args=(unicode(self.course.id), ))
     response = self.client.get(url)
     content = pq(response.content)
     self.assertEqual(content('.page-header-secondary a').length, 0)
コード例 #6
0
    def test_course_info_feature_flag(self):
        SelfPacedConfiguration(enable_course_home_improvements=False).save()
        course = create_course_run()
        user = create_user()
        CourseEnrollmentFactory(course_id=course.id, user=user, mode=CourseMode.VERIFIED)

        self.client.login(username=user.username, password=TEST_PASSWORD)
        url = reverse('info', args=(course.id,))
        response = self.client.get(url)
        self.assertNotIn('date-summary', response.content)
コード例 #7
0
    def test_toggle_pacing_during_course_run(self):
        SelfPacedConfiguration(enabled=True).save()
        self.course.start = datetime.datetime.now()
        self.store.update_item(self.course, self.user.id)

        details = CourseDetails.fetch(self.course.id)
        with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred,
                                       self.course.id):
            updated_details = CourseDetails.update_from_json(
                self.course.id, dict(details.__dict__, self_paced=True),
                self.user)
        self.assertFalse(updated_details.self_paced)
コード例 #8
0
    def setUp(self):
        self.reset_setting_cache_variables()
        super(SelfPacedDateOverrideTest, self).setUp()

        SelfPacedConfiguration(enabled=True).save()

        self.non_staff_user, __ = self.create_non_staff_user()

        # create a UserProfile for user so user doesn't look like sneak_peek user
        nonstaff_user_profile = UserProfile(user=self.non_staff_user)
        nonstaff_user_profile.save()

        self.now = datetime.datetime.now(pytz.UTC).replace(microsecond=0)
        self.future = self.now + datetime.timedelta(days=30)
コード例 #9
0
    def test_masquerade_as_specific_user_on_self_paced(self):
        """
        Test masquerading as a specific user for course info page when self paced configuration
        "enable_course_home_improvements" flag is set

        Login as a staff user and visit course info page.
        set masquerade to view same page as a specific student and revisit the course info page.
        """
        # Log in as staff, and check we can see the info page.
        self.login_staff()
        response = self.get_course_info_page()
        self.assertContains(response, "OOGIE BLOOGIE")

        # Masquerade as the student,enable the self paced configuration, and check we can see the info page.
        SelfPacedConfiguration(enable_course_home_improvements=True).save()
        self.update_masquerade(role='student', username=self.student_user.username)
        response = self.get_course_info_page()
        self.assertContains(response, "OOGIE BLOOGIE")
コード例 #10
0
 def test_last_accessed_shown(self):
     SelfPacedConfiguration(enable_course_home_improvements=True).save()
     chapter = ItemFactory.create(category="chapter",
                                  parent_location=self.course.location)
     section = ItemFactory.create(category='section',
                                  parent_location=chapter.location)
     section_url = reverse('courseware_section',
                           kwargs={
                               'section': section.url_name,
                               'chapter': chapter.url_name,
                               'course_id': self.course.id
                           })
     self.client.get(section_url)
     info_url = reverse('info', args=(unicode(self.course.id), ))
     info_page_response = self.client.get(info_url)
     content = pq(info_page_response.content)
     self.assertEqual(
         content('.page-header-secondary .last-accessed-link').attr('href'),
         section_url)
コード例 #11
0
class ProgressPageTests(ModuleStoreTestCase):
    """
    Tests that verify that the progress page works correctly.
    """

    def setUp(self):
        super(ProgressPageTests, self).setUp()
        self.request_factory = RequestFactory()
        self.user = UserFactory.create()
        self.request = self.request_factory.get("foo")
        self.request.user = self.user

        mako_middleware_process_request(self.request)

        self.setup_course()

    def setup_course(self, **options):
        """Create the test course."""
        course = CourseFactory.create(
            start=datetime(2013, 9, 16, 7, 17, 28),
            grade_cutoffs={u'çü†øƒƒ': 0.75, 'Pass': 0.5},
            **options
        )

        # pylint: disable=attribute-defined-outside-init
        self.course = modulestore().get_course(course.id)
        CourseEnrollmentFactory(user=self.user, course_id=self.course.id)

        self.chapter = ItemFactory.create(category='chapter', parent_location=self.course.location)
        self.section = ItemFactory.create(category='sequential', parent_location=self.chapter.location)
        self.vertical = ItemFactory.create(category='vertical', parent_location=self.section.location)

    @ddt.data('"><script>alert(1)</script>', '<script>alert(1)</script>', '</script><script>alert(1)</script>')
    def test_progress_page_xss_prevent(self, malicious_code):
        """
        Test that XSS attack is prevented
        """
        resp = views.progress(self.request, course_id=unicode(self.course.id), student_id=self.user.id)
        self.assertEqual(resp.status_code, 200)
        # Test that malicious code does not appear in html
        self.assertNotIn(malicious_code, resp.content)

    def test_pure_ungraded_xblock(self):
        ItemFactory.create(category='acid', parent_location=self.vertical.location)

        resp = views.progress(self.request, course_id=self.course.id.to_deprecated_string())
        self.assertEqual(resp.status_code, 200)

    @ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
    def test_student_progress_with_valid_and_invalid_id(self, default_store):
        """
         Check that invalid 'student_id' raises Http404 for both old mongo and
         split mongo courses.
        """

        # Create new course with respect to 'default_store'
        self.course = CourseFactory.create(default_store=default_store)

        # Invalid Student Ids (Integer and Non-int)
        invalid_student_ids = [
            991021,
            'azU3N_8$',
        ]
        for invalid_id in invalid_student_ids:

            self.assertRaises(
                Http404, views.progress,
                self.request,
                course_id=unicode(self.course.id),
                student_id=invalid_id
            )

        # Enroll student into course
        CourseEnrollment.enroll(self.user, self.course.id, mode='honor')
        resp = views.progress(self.request, course_id=self.course.id.to_deprecated_string(), student_id=self.user.id)
        # Assert that valid 'student_id' returns 200 status
        self.assertEqual(resp.status_code, 200)

    def test_non_asci_grade_cutoffs(self):
        resp = views.progress(self.request, course_id=self.course.id.to_deprecated_string())

        self.assertEqual(resp.status_code, 200)

    def test_generate_cert_config(self):
        resp = views.progress(self.request, course_id=unicode(self.course.id))
        self.assertNotContains(resp, 'Request Certificate')

        # Enable the feature, but do not enable it for this course
        CertificateGenerationConfiguration(enabled=True).save()
        resp = views.progress(self.request, course_id=unicode(self.course.id))
        self.assertNotContains(resp, 'Request Certificate')

        # Enable certificate generation for this course
        certs_api.set_cert_generation_enabled(self.course.id, True)
        resp = views.progress(self.request, course_id=unicode(self.course.id))
        self.assertNotContains(resp, 'Request Certificate')

    @patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': True})
    @patch('courseware.grades.grade', Mock(return_value={'grade': 'Pass', 'percent': 0.75, 'section_breakdown': [],
                                                         'grade_breakdown': []}))
    def test_view_certificate_link(self):
        """
        If certificate web view is enabled then certificate web view button should appear for user who certificate is
        available/generated
        """
        certificate = GeneratedCertificateFactory.create(
            user=self.user,
            course_id=self.course.id,
            status=CertificateStatuses.downloadable,
            download_url="http://www.example.com/certificate.pdf",
            mode='honor'
        )

        # Enable the feature, but do not enable it for this course
        CertificateGenerationConfiguration(enabled=True).save()

        # Enable certificate generation for this course
        certs_api.set_cert_generation_enabled(self.course.id, True)

        #course certificate configurations
        certificates = [
            {
                'id': 1,
                'name': 'Name 1',
                'description': 'Description 1',
                'course_title': 'course_title_1',
                'signatories': [],
                'version': 1,
                'is_active': True
            }
        ]

        self.course.certificates = {'certificates': certificates}
        self.course.cert_html_view_enabled = True
        self.course.save()
        self.store.update_item(self.course, self.user.id)

        resp = views.progress(self.request, course_id=unicode(self.course.id))
        self.assertContains(resp, u"View Certificate")

        self.assertContains(resp, u"You can keep working for a higher grade")
        cert_url = certs_api.get_certificate_url(
            user_id=self.user.id,
            course_id=self.course.id
        )
        self.assertContains(resp, cert_url)

        # when course certificate is not active
        certificates[0]['is_active'] = False
        self.store.update_item(self.course, self.user.id)

        resp = views.progress(self.request, course_id=unicode(self.course.id))
        self.assertNotContains(resp, u"View Your Certificate")
        self.assertNotContains(resp, u"You can now view your certificate")
        self.assertContains(resp, u"We're creating your certificate.")

    @patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': False})
    @patch('courseware.grades.grade', Mock(return_value={'grade': 'Pass', 'percent': 0.75, 'section_breakdown': [],
                                                         'grade_breakdown': []}))
    def test_view_certificate_link_hidden(self):
        """
        If certificate web view is disabled then certificate web view button should not appear for user who certificate
        is available/generated
        """
        GeneratedCertificateFactory.create(
            user=self.user,
            course_id=self.course.id,
            status=CertificateStatuses.downloadable,
            download_url="http://www.example.com/certificate.pdf",
            mode='honor'
        )

        # Enable the feature, but do not enable it for this course
        CertificateGenerationConfiguration(enabled=True).save()

        # Enable certificate generation for this course
        certs_api.set_cert_generation_enabled(self.course.id, True)

        resp = views.progress(self.request, course_id=unicode(self.course.id))
        self.assertContains(resp, u"Download Your Certificate")

    @ddt.data(
        *itertools.product(((18, 4, True), (18, 4, False)), (True, False))
    )
    @ddt.unpack
    def test_query_counts(self, (sql_calls, mongo_calls, self_paced), self_paced_enabled):
        """Test that query counts remain the same for self-paced and instructor-led courses."""
        SelfPacedConfiguration(enabled=self_paced_enabled).save()
        self.setup_course(self_paced=self_paced)
        with self.assertNumQueries(sql_calls), check_mongo_calls(mongo_calls):
            resp = views.progress(self.request, course_id=unicode(self.course.id))
        self.assertEqual(resp.status_code, 200)
コード例 #12
0
ファイル: utils.py プロジェクト: fangqian/edx-platform
def is_self_paced(course):
    """
    Returns True if course is self-paced, False otherwise.
    """
    return course and course.self_paced and SelfPacedConfiguration.current(
    ).enabled
コード例 #13
0
    def update_from_json(cls, course_key, jsondict, user):  # pylint: disable=too-many-statements
        """
        Decode the json into CourseDetails and save any changed attrs to the db
        """
        module_store = modulestore()
        descriptor = module_store.get_course(course_key)

        dirty = False

        # In the descriptor's setter, the date is converted to JSON
        # using Date's to_json method. Calling to_json on something that
        # is already JSON doesn't work. Since reaching directly into the
        # model is nasty, convert the JSON Date to a Python date, which
        # is what the setter expects as input.
        date = Date()

        if 'start_date' in jsondict:
            converted = date.from_json(jsondict['start_date'])
        else:
            converted = None
        if converted != descriptor.start:
            dirty = True
            descriptor.start = converted

        if 'end_date' in jsondict:
            converted = date.from_json(jsondict['end_date'])
        else:
            converted = None

        if converted != descriptor.end:
            dirty = True
            descriptor.end = converted

        if 'enrollment_start' in jsondict:
            converted = date.from_json(jsondict['enrollment_start'])
        else:
            converted = None

        if converted != descriptor.enrollment_start:
            dirty = True
            descriptor.enrollment_start = converted

        if 'enrollment_end' in jsondict:
            converted = date.from_json(jsondict['enrollment_end'])
        else:
            converted = None

        if converted != descriptor.enrollment_end:
            dirty = True
            descriptor.enrollment_end = converted

        if 'certificate_available_date' in jsondict:
            converted = date.from_json(jsondict['certificate_available_date'])
        else:
            converted = None

        if converted != descriptor.certificate_available_date:
            dirty = True
            descriptor.certificate_available_date = converted

        if 'course_image_name' in jsondict and jsondict[
                'course_image_name'] != descriptor.course_image:
            descriptor.course_image = jsondict['course_image_name']
            dirty = True

        if 'banner_image_name' in jsondict and jsondict[
                'banner_image_name'] != descriptor.banner_image:
            descriptor.banner_image = jsondict['banner_image_name']
            dirty = True

        if 'video_thumbnail_image_name' in jsondict \
                and jsondict['video_thumbnail_image_name'] != descriptor.video_thumbnail_image:
            descriptor.video_thumbnail_image = jsondict[
                'video_thumbnail_image_name']
            dirty = True

        if 'pre_requisite_courses' in jsondict \
                and sorted(jsondict['pre_requisite_courses']) != sorted(descriptor.pre_requisite_courses):
            descriptor.pre_requisite_courses = jsondict[
                'pre_requisite_courses']
            dirty = True

        if 'license' in jsondict:
            descriptor.license = jsondict['license']
            dirty = True

        if 'learning_info' in jsondict:
            descriptor.learning_info = jsondict['learning_info']
            dirty = True

        if 'instructor_info' in jsondict:
            descriptor.instructor_info = jsondict['instructor_info']
            dirty = True

        if 'language' in jsondict and jsondict[
                'language'] != descriptor.language:
            descriptor.language = jsondict['language']
            dirty = True

        if (SelfPacedConfiguration.current().enabled
                and descriptor.can_toggle_course_pacing
                and 'self_paced' in jsondict
                and jsondict['self_paced'] != descriptor.self_paced):
            descriptor.self_paced = jsondict['self_paced']
            dirty = True

        if dirty:
            module_store.update_item(descriptor, user.id)

        # NOTE: below auto writes to the db w/o verifying that any of
        # the fields actually changed to make faster, could compare
        # against db or could have client send over a list of which
        # fields changed.
        for attribute in ABOUT_ATTRIBUTES:
            if attribute in jsondict:
                cls.update_about_item(descriptor, attribute,
                                      jsondict[attribute], user.id)

        cls.update_about_video(descriptor, jsondict['intro_video'], user.id)

        # Could just return jsondict w/o doing any db reads, but I put
        # the reads in as a means to confirm it persisted correctly
        return CourseDetails.fetch(course_key)
コード例 #14
0
 def enabled_for(cls, block):
     """This provider is enabled for self-paced courses only."""
     return block is not None and block.self_paced and SelfPacedConfiguration.current(
     ).enabled
コード例 #15
0
 def setUp(self):
     SelfPacedConfiguration(enable_course_home_improvements=True).save()
     super(CourseDateSummaryTest, self).setUp()
コード例 #16
0
 def enabled_for(cls, block):
     """This provider is enabled for self-paced courses only."""
     return block is not None and block.self_paced and SelfPacedConfiguration.current().enabled
コード例 #17
0
 def test_update_and_fetch(self):
     SelfPacedConfiguration(enabled=True).save()
     jsondetails = CourseDetails.fetch(self.course.id)
     jsondetails.syllabus = "<a href='foo'>bar</a>"
     # encode - decode to convert date fields and other data which changes form
     with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred,
                                    self.course.id):
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).syllabus,
             jsondetails.syllabus, "After set syllabus")
         jsondetails.short_description = "Short Description"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).short_description,
             jsondetails.short_description, "After set short_description")
         jsondetails.overview = "Overview"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).overview,
             jsondetails.overview, "After set overview")
         jsondetails.intro_video = "intro_video"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).intro_video,
             jsondetails.intro_video, "After set intro_video")
         jsondetails.about_sidebar_html = "About Sidebar HTML"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).about_sidebar_html,
             jsondetails.about_sidebar_html, "After set about_sidebar_html")
         jsondetails.effort = "effort"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).effort,
             jsondetails.effort, "After set effort")
         jsondetails.self_paced = True
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).self_paced,
             jsondetails.self_paced)
         jsondetails.start_date = datetime.datetime(2010,
                                                    10,
                                                    1,
                                                    0,
                                                    tzinfo=UTC())
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).start_date,
             jsondetails.start_date)
         jsondetails.end_date = datetime.datetime(2011,
                                                  10,
                                                  1,
                                                  0,
                                                  tzinfo=UTC())
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).end_date,
             jsondetails.end_date)
         jsondetails.course_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).course_image_name,
             jsondetails.course_image_name)
         jsondetails.banner_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).banner_image_name,
             jsondetails.banner_image_name)
         jsondetails.video_thumbnail_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(
                 self.course.id, jsondetails.__dict__,
                 self.user).video_thumbnail_image_name,
             jsondetails.video_thumbnail_image_name)
         jsondetails.language = "hr"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).language,
             jsondetails.language)
         jsondetails.learning_info = ["test", "test"]
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).learning_info,
             jsondetails.learning_info)
         jsondetails.instructor_info = {
             "instructors": [{
                 "name": "test",
                 "title": "test",
                 "organization": "test",
                 "image": "test",
                 "bio": "test"
             }]
         }
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).instructor_info,
             jsondetails.instructor_info)
コード例 #18
0
 def setUp(self):
     SelfPacedConfiguration(enabled=True).save()
     super(SelfPacedDateOverrideTest, self).setUp()
     self.due_date = datetime(2015, 5, 26, 8, 30,
                              00).replace(tzinfo=tzutc())
コード例 #19
0
 def setUp(self):
     super(SelfGeneratedCertsSignalTest, self).setUp()
     SelfPacedConfiguration(enabled=True).save()
     CertificateGenerationConfiguration.objects.create(enabled=True)
コード例 #20
0
 def enabled_for(cls, course):
     """This provider is enabled for self-paced courses only."""
     return SelfPacedConfiguration.current().enabled and course.self_paced
コード例 #21
0
 def setUp(self):
     super(TestRenderXBlockSelfPaced, self).setUp()
     SelfPacedConfiguration(enabled=True).save()
コード例 #22
0
def is_self_paced(course):
    """
    Returns True if course is self-paced, False otherwise.
    """
    return course and course.self_paced and SelfPacedConfiguration.current().enabled
コード例 #23
0
 def test_update_and_fetch(self):
     SelfPacedConfiguration(enabled=True).save()
     jsondetails = CourseDetails.fetch(self.course.id)
     jsondetails.syllabus = "<a href='foo'>bar</a>"
     # encode - decode to convert date fields and other data which changes form
     with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred,
                                    self.course.id):
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).syllabus,
             jsondetails.syllabus, "After set syllabus")
         jsondetails.short_description = "Short Description"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).short_description,
             jsondetails.short_description, "After set short_description")
         jsondetails.overview = "Overview"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).overview,
             jsondetails.overview, "After set overview")
         jsondetails.intro_video = "intro_video"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).intro_video,
             jsondetails.intro_video, "After set intro_video")
         jsondetails.effort = "effort"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).effort,
             jsondetails.effort, "After set effort")
         jsondetails.self_paced = True
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).self_paced,
             jsondetails.self_paced)
         jsondetails.start_date = datetime.datetime(2010,
                                                    10,
                                                    1,
                                                    0,
                                                    tzinfo=UTC())
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).start_date,
             jsondetails.start_date)
         jsondetails.end_date = datetime.datetime(2011,
                                                  10,
                                                  1,
                                                  0,
                                                  tzinfo=UTC())
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).end_date,
             jsondetails.end_date)
         jsondetails.course_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).course_image_name,
             jsondetails.course_image_name)
         jsondetails.language = "hr"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).language,
             jsondetails.language)
コード例 #24
0
 def test_self_paced_disabled(self):
     SelfPacedConfiguration(enabled=False).save()
     __, sp_section = self.setup_course("Self-Paced Course", True)
     self.assertEqual(self.due_date, sp_section.due)
コード例 #25
0
 def test_self_paced_disabled_due_date(self):
     SelfPacedConfiguration(enabled=False).save()
     __, sp_section = self.setup_course(display_name="Self-Paced Course",
                                        self_paced=True)
     self.assertEqual(sp_section.due, self.now)
コード例 #26
0
 def setUp(self):
     SelfPacedConfiguration(enabled=True).save()
     super(SelfPacedCourseInfoTestCase, self).setUp()
     self.setup_user()
コード例 #27
0
ファイル: course_details.py プロジェクト: edxzw/edx-platform
    def update_from_json(cls, course_key, jsondict, user):  # pylint: disable=too-many-statements
        """
        Decode the json into CourseDetails and save any changed attrs to the db
        """
        module_store = modulestore()
        descriptor = module_store.get_course(course_key)

        dirty = False

        # In the descriptor's setter, the date is converted to JSON
        # using Date's to_json method. Calling to_json on something that
        # is already JSON doesn't work. Since reaching directly into the
        # model is nasty, convert the JSON Date to a Python date, which
        # is what the setter expects as input.
        date = Date()

        if 'start_date' in jsondict:
            converted = date.from_json(jsondict['start_date'])
        else:
            converted = None
        if converted != descriptor.start:
            dirty = True
            descriptor.start = converted

        if 'end_date' in jsondict:
            converted = date.from_json(jsondict['end_date'])
        else:
            converted = None

        if converted != descriptor.end:
            dirty = True
            descriptor.end = converted

        if 'enrollment_start' in jsondict:
            converted = date.from_json(jsondict['enrollment_start'])
        else:
            converted = None

        if converted != descriptor.enrollment_start:
            dirty = True
            descriptor.enrollment_start = converted

        if 'enrollment_end' in jsondict:
            converted = date.from_json(jsondict['enrollment_end'])
        else:
            converted = None

        if converted != descriptor.enrollment_end:
            dirty = True
            descriptor.enrollment_end = converted

        if 'course_image_name' in jsondict and jsondict['course_image_name'] != descriptor.course_image:
            descriptor.course_image = jsondict['course_image_name']
            dirty = True

        if 'pre_requisite_courses' in jsondict \
                and sorted(jsondict['pre_requisite_courses']) != sorted(descriptor.pre_requisite_courses):
            descriptor.pre_requisite_courses = jsondict['pre_requisite_courses']
            dirty = True

        if 'license' in jsondict:
            descriptor.license = jsondict['license']
            dirty = True

        if 'language' in jsondict and jsondict['language'] != descriptor.language:
            descriptor.language = jsondict['language']
            dirty = True

        if (SelfPacedConfiguration.current().enabled
                and descriptor.can_toggle_course_pacing
                and 'self_paced' in jsondict
                and jsondict['self_paced'] != descriptor.self_paced):
            descriptor.self_paced = jsondict['self_paced']
            dirty = True

        if dirty:
            module_store.update_item(descriptor, user.id)

        # NOTE: below auto writes to the db w/o verifying that any of
        # the fields actually changed to make faster, could compare
        # against db or could have client send over a list of which
        # fields changed.
        for attribute in ABOUT_ATTRIBUTES:
            if attribute in jsondict:
                cls.update_about_item(descriptor, attribute, jsondict[attribute], user.id)

        cls.update_about_video(descriptor, jsondict['intro_video'], user.id)

        # Could just return jsondict w/o doing any db reads, but I put
        # the reads in as a means to confirm it persisted correctly
        return CourseDetails.fetch(course_key)
コード例 #28
0
 def setUp(self):
     super(SelfGeneratedCertsSignalTest, self).setUp()
     SelfPacedConfiguration(enabled=True).save()
     self.course = CourseFactory.create(self_paced=True)
     # Enable the feature
     CertificateGenerationConfiguration.objects.create(enabled=True)
コード例 #29
0
 def setUp(self):
     SelfPacedConfiguration(enabled=True).save()
     super(SelfPacedCourseInfoTestCase, self).setUp()
     self.instructor_paced_course = CourseFactory.create(self_paced=False)
     self.self_paced_course = CourseFactory.create(self_paced=True)
     self.setup_user()