Example #1
0
 def test_rendering_course_organization_data(self):
     """
     Test: organization data should render on certificate web view if course has organization.
     """
     test_organization_data = {
         'name': 'test organization',
         'short_name': 'test_organization',
         'description': 'Test Organization Description',
         'active': True,
         'logo': '/logo_test1.png/'
     }
     test_org = organizations_api.add_organization(organization_data=test_organization_data)
     organizations_api.add_organization_course(organization_data=test_org, course_id=unicode(self.course.id))
     self._add_course_certificates(count=1, signatory_count=1, is_active=True)
     test_url = get_certificate_url(
         user_id=self.user.id,
         course_id=unicode(self.course.id)
     )
     response = self.client.get(test_url)
     self.assertIn(
         'a course of study offered by test_organization, an online learning initiative of test organization',
         response.content
     )
     self.assertNotIn(
         'a course of study offered by testorg',
         response.content
     )
     self.assertIn(
         '<title>test_organization {} Certificate |'.format(self.course.number, ),
         response.content
     )
     self.assertIn('logo_test1.png', response.content)
Example #2
0
    def test_enterprise_learner_context_with_multiple_organizations(self):
        """
        Test: Track selection page should show the enterprise context message with multiple organization names
        if user belongs to the Enterprise.
        """
        url = self._generate_enterprise_learner_context()

        # Creating organization
        for i in xrange(2):
            test_organization_data = {
                'name': 'test organization ' + str(i),
                'short_name': 'test_organization_' + str(i),
                'description': 'Test Organization Description',
                'active': True,
                'logo': '/logo_test1.png/'
            }
            test_org = organizations_api.add_organization(organization_data=test_organization_data)
            organizations_api.add_organization_course(organization_data=test_org, course_id=unicode(self.course.id))

        # User visits the track selection page directly without ever enrolling
        response = self.client.get(url)
        self.assertEquals(response.status_code, 200)
        self.assertContains(
            response,
            'Welcome, {username}! You are about to enroll in {course_name}, from test organization 0 and '
            'test organization 1, sponsored by TestShib. Please select your enrollment information below.'.format(
                username=self.user.username,
                course_name=self.course.display_name_with_default_escaped
            )
        )
Example #3
0
def _create_new_course(subject, org, number, run, fields):
    """
    Create a new course.
    Raises DuplicateCourseError if the course already exists
    """
    org_data = get_organization_by_short_name(org)
    if not org_data and organizations_enabled():
        return
    store_for_new_course = modulestore().default_modulestore.get_modulestore_type()
    try:
        user = User.objects.get(username='******')
    except User.DoesNotExist:
        user = User.objects.create(
            username='******',
            email='*****@*****.**',
            first_name='coursecreator',
            last_name='coursecreator',
            is_active=True,
            is_staff=True
        )
        user.set_password('coursecreator')
        user.save()
    try:
        new_course = create_new_course_in_store(store_for_new_course, user, org, number, run, fields)

    except DuplicateCourseError:
        existing_course_key = SlashSeparatedCourseKey.from_deprecated_string('course-v1:'+org+'+'+number+'+'+run)
        new_course = get_course_by_id(existing_course_key)

    add_organization_course(org_data, new_course.id)

    # Set description and images for the course
    course_image_name, course_image_asset_path = store_jacket_image(
        new_course.id, settings.VODECLIC_COURSE_IMAGE_LOCATION,
        subject.get("id") + ".png"
    )
    additional_info = {
        'display_name': subject.get('title'),
        'language': subject.get('language', 'fr'),
        'short_description': subject.get('description', ''),
        'intro_video': None,
        'course_image_name': course_image_name,
        'course_image_asset_path': course_image_asset_path,
        'start_date': new_course.start,
        'end_date': new_course.end,
        'enrollment_start': new_course.start,
        'enrollment_end': new_course.end
    }

    CourseDetails.update_from_json(new_course.id, additional_info, user)
Example #4
0
    def test_enterprise_learner_context_with_multiple_organizations(self):
        """
        Test: Track selection page should show the enterprise context message with multiple organization names
        if user belongs to the Enterprise.
        """
        # Create the course modes
        for mode in ('audit', 'honor', 'verified'):
            CourseModeFactory.create(mode_slug=mode, course_id=self.course.id)

        self.mock_enterprise_learner_api()
        # Create a service user and log in.
        UserFactory.create(
            username='******',
            email="*****@*****.**",
            password="******",
        )

        # Creating organization
        for i in xrange(2):
            test_organization_data = {
                'name': 'test organization ' + str(i),
                'short_name': 'test_organization_' + str(i),
                'description': 'Test Organization Description',
                'active': True,
                'logo': '/logo_test1.png/'
            }
            test_org = organizations_api.add_organization(
                organization_data=test_organization_data)
            organizations_api.add_organization_course(
                organization_data=test_org, course_id=unicode(self.course.id))

        # User visits the track selection page directly without ever enrolling
        url = reverse('course_modes_choose', args=[unicode(self.course.id)])
        response = self.client.get(url)
        self.assertEquals(response.status_code, 200)
        self.assertContains(
            response,
            'Welcome, {username}! You are about to enroll in {course_name}, from test organization 0 and '
            'test organization 1, sponsored by TestShib. Please select your enrollment information below.'
            .format(username=self.user.username,
                    course_name=self.course.display_name_with_default_escaped))
Example #5
0
    def test_enterprise_learner_context_with_multiple_organizations(self):
        """
        Test: Track selection page should show the enterprise context message with multiple organization names
        if user belongs to the Enterprise.
        """
        # Create the course modes
        for mode in ('audit', 'honor', 'verified'):
            CourseModeFactory.create(mode_slug=mode, course_id=self.course.id)

        self.mock_enterprise_learner_api()
        self.mock_course_discovery_api_for_catalog_contains(
            catalog_id=1, course_run_ids=[str(self.course.id)]
        )

        # Creating organization
        for i in xrange(2):
            test_organization_data = {
                'name': 'test organization ' + str(i),
                'short_name': 'test_organization_' + str(i),
                'description': 'Test Organization Description',
                'active': True,
                'logo': '/logo_test1.png/'
            }
            test_org = organizations_api.add_organization(organization_data=test_organization_data)
            organizations_api.add_organization_course(organization_data=test_org, course_id=unicode(self.course.id))

        # User visits the track selection page directly without ever enrolling
        url = reverse('course_modes_choose', args=[unicode(self.course.id)])
        response = self.client.get(url)
        self.assertEquals(response.status_code, 200)
        self.assertContains(
            response,
            'Welcome, {username}! You are about to enroll in {course_name}, from test organization 0 and '
            'test organization 1, sponsored by TestShib. Please select your enrollment information below.'.format(
                username=self.user.username,
                course_name=self.course.display_name_with_default_escaped
            )
        )
Example #6
0
    def test_rendering_maximum_data(self):
        """
        Tests at least one data item from different context update methods to
        make sure every context update method is invoked while rendering certificate template.
        """
        long_org_name = 'Long org name'
        short_org_name = 'short_org_name'
        test_organization_data = {
            'name': long_org_name,
            'short_name': short_org_name,
            'description': 'Test Organization Description',
            'active': True,
            'logo': '/logo_test1.png'
        }
        test_org = organizations_api.add_organization(organization_data=test_organization_data)
        organizations_api.add_organization_course(organization_data=test_org, course_id=unicode(self.course.id))
        self._add_course_certificates(count=1, signatory_count=1, is_active=True)
        BadgeAssertionFactory.create(
            user=self.user, course_id=self.course_id,
        )
        self.course.cert_html_view_overrides = {
            "logo_src": "/static/certificates/images/course_override_logo.png"
        }

        self.course.save()
        self.store.update_item(self.course, self.user.id)

        test_url = get_certificate_url(
            user_id=self.user.id,
            course_id=unicode(self.course.id)
        )
        response = self.client.get(test_url, HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME)

        # Test an item from basic info
        self.assertIn(
            'Terms of Service &amp; Honor Code',
            response.content
        )
        self.assertIn(
            'Certificate ID Number',
            response.content
        )
        # Test an item from html cert configuration
        self.assertIn(
            '<a class="logo" href="http://test_microsite.localhost">',
            response.content
        )
        # Test an item from course info
        self.assertIn(
            'course_title_0',
            response.content
        )
        # Test an item from user info
        self.assertIn(
            "{fullname}, you earned a certificate!".format(fullname=self.user.profile.name),
            response.content
        )
        # Test an item from social info
        self.assertIn(
            "Post on Facebook",
            response.content
        )
        self.assertIn(
            "Share on Twitter",
            response.content
        )
        # Test an item from certificate/org info
        self.assertIn(
            "a course of study offered by {partner_short_name}, "
            "an online learning initiative of "
            "{partner_long_name}.".format(
                partner_short_name=short_org_name,
                partner_long_name=long_org_name,
                platform_name='Test Microsite'
            ),
            response.content
        )
        # Test item from badge info
        self.assertIn(
            "Add to Mozilla Backpack",
            response.content
        )
        # Test item from microsite info
        self.assertIn(
            "http://www.testmicrosite.org/about-us",
            response.content
        )
        # Test course overrides
        self.assertIn(
            "/static/certificates/images/course_override_logo.png",
            response.content
        )
 def test_add_organization_course_returns_none_when_app_disabled(self):
     response = organizations_helpers.add_organization_course(self.organization, self.course.id)
     self.assertIsNone(response)
 def test_add_organization_course_returns_none_when_app_disabled(self):
     response = organizations_helpers.add_organization_course(
         self.organization, self.course.id)
     self.assertIsNone(response)
Example #9
0
def rerun_course(source_course_key_string,
                 destination_course_key_string,
                 user_id,
                 fields=None):
    """
    Reruns a course in a new celery task.
    """
    # import here, at top level this import prevents the celery workers from starting up correctly
    from edxval.api import copy_course_videos

    source_course_key = CourseKey.from_string(source_course_key_string)
    destination_course_key = CourseKey.from_string(
        destination_course_key_string)
    try:
        # deserialize the payload
        fields = deserialize_fields(fields) if fields else None

        # use the split modulestore as the store for the rerun course,
        # as the Mongo modulestore doesn't support multiple runs of the same course.
        store = modulestore()
        with store.default_store('split'):
            store.clone_course(source_course_key,
                               destination_course_key,
                               user_id,
                               fields=fields)

        # set initial permissions for the user to access the course.
        initialize_permissions(destination_course_key,
                               User.objects.get(id=user_id))

        # update state: Succeeded
        CourseRerunState.objects.succeeded(course_key=destination_course_key)

        # call edxval to attach videos to the rerun
        copy_course_videos(source_course_key, destination_course_key)

        # Copy OrganizationCourse
        organization_course = OrganizationCourse.objects.filter(
            course_id=source_course_key_string).first()

        if organization_course:
            clone_instance(organization_course,
                           {'course_id': destination_course_key_string})

        # Copy RestrictedCourse
        restricted_course = RestrictedCourse.objects.filter(
            course_key=source_course_key).first()

        if restricted_course:
            country_access_rules = CountryAccessRule.objects.filter(
                restricted_course=restricted_course)
            new_restricted_course = clone_instance(
                restricted_course, {'course_key': destination_course_key})
            for country_access_rule in country_access_rules:
                clone_instance(country_access_rule,
                               {'restricted_course': new_restricted_course})

        org_data = get_organization_by_short_name(source_course_key.org)
        add_organization_course(org_data, destination_course_key)
        return "succeeded"

    except DuplicateCourseError:
        # do NOT delete the original course, only update the status
        CourseRerunState.objects.failed(course_key=destination_course_key)
        LOGGER.exception(u'Course Rerun Error')
        return "duplicate course"

    # catch all exceptions so we can update the state and properly cleanup the course.
    except Exception as exc:  # pylint: disable=broad-except
        # update state: Failed
        CourseRerunState.objects.failed(course_key=destination_course_key)
        LOGGER.exception(u'Course Rerun Error')

        try:
            # cleanup any remnants of the course
            modulestore().delete_course(destination_course_key, user_id)
        except ItemNotFoundError:
            # it's possible there was an error even before the course module was created
            pass

        return u"exception: " + text_type(exc)