示例#1
0
    def test_rerun(self):
        """
        Just testing the functionality the view handler adds over the tasks tested in test_clone_course
        """
        add_organization({
            'name': 'Test Organization',
            'short_name': self.source_course_key.org,
            'description': 'Testing Organization Description',
        })
        response = self.client.ajax_post(
            self.course_create_rerun_url, {
                'source_course_key': six.text_type(self.source_course_key),
                'org': self.source_course_key.org,
                'course': self.source_course_key.course,
                'run': 'copy',
                'display_name': 'not the same old name',
            })
        self.assertEqual(response.status_code, 200)
        data = parse_json(response)
        dest_course_key = CourseKey.from_string(data['destination_course_key'])

        self.assertEqual(dest_course_key.run, 'copy')
        source_course = self.store.get_course(self.source_course_key)
        dest_course = self.store.get_course(dest_course_key)
        self.assertEqual(dest_course.start, CourseFields.start.default)
        self.assertEqual(dest_course.end, source_course.end)
        self.assertEqual(dest_course.enrollment_start, None)
        self.assertEqual(dest_course.enrollment_end, None)
        course_orgs = get_course_organizations(dest_course_key)
        self.assertEqual(len(course_orgs), 1)
        self.assertEqual(course_orgs[0]['short_name'],
                         self.source_course_key.org)
    def test_rerun(self, pacing_type, expected_self_paced_value, number):
        original_course_run = ToyCourseFactory()
        add_organization({
            'name': 'Test Organization',
            'short_name': original_course_run.id.org,
            'description': 'Testing Organization Description',
        })
        start = datetime.datetime.now(pytz.UTC).replace(microsecond=0)
        end = start + datetime.timedelta(days=30)
        user = UserFactory()
        role = 'instructor'
        run = '3T2017'
        url = reverse('api:v1:course_run-rerun',
                      kwargs={'pk': str(original_course_run.id)})
        data = {
            'run': run,
            'schedule': {
                'start': serialize_datetime(start),
                'end': serialize_datetime(end),
            },
            'team': [{
                'user': user.username,
                'role': role,
            }],
            'pacing_type': pacing_type,
        }
        # If number is supplied, this should become the course number used in the course run key
        # If not, it should default to the original course run number that the rerun is based on.
        if number:
            data.update({'number': number})
        response = self.client.post(url, data, format='json')
        assert response.status_code == 201

        course_run_key = CourseKey.from_string(response.data['id'])
        course_run = modulestore().get_course(course_run_key)

        assert course_run.id.run == run
        assert course_run.self_paced is expected_self_paced_value

        if number:
            assert course_run.id.course == number
            assert course_run.id.course != original_course_run.id.course
        else:
            assert course_run.id.course == original_course_run.id.course

        self.assert_course_run_schedule(course_run, start, end)
        self.assert_access_role(course_run, user, role)
        self.assert_course_access_role_count(course_run, 1)
        course_orgs = get_course_organizations(course_run_key)
        self.assertEqual(len(course_orgs), 1)
        self.assertEqual(course_orgs[0]['short_name'],
                         original_course_run.id.org)
示例#3
0
 def test_course_creation_without_org_app_enabled(self, store):
     """
     Tests course creation workflow should not create course to org
     link if organizations_app is not enabled.
     """
     with modulestore().default_store(store):
         response = self.client.ajax_post(
             self.course_create_rerun_url, {
                 'org': 'orgX',
                 'number': 'CS101',
                 'display_name': 'Course with web certs enabled',
                 'run': '2015_T2'
             })
         self.assertEqual(response.status_code, 200)
         data = parse_json(response)
         new_course_key = CourseKey.from_string(data['course_key'])
         course_orgs = get_course_organizations(new_course_key)
         self.assertEqual(course_orgs, [])
示例#4
0
def _update_organization_context(context, course):
    """
    Updates context with organization related info.
    """
    partner_long_name, organization_logo = None, None
    partner_short_name = course.display_organization if course.display_organization else course.org
    organizations = organization_api.get_course_organizations(course_id=course.id)
    if organizations:
        #TODO Need to add support for multiple organizations, Currently we are interested in the first one.
        organization = organizations[0]
        partner_long_name = organization.get('name', partner_long_name)
        partner_short_name = organization.get('short_name', partner_short_name)
        organization_logo = organization.get('logo', None)

    context['organization_long_name'] = partner_long_name
    context['organization_short_name'] = partner_short_name
    context['accomplishment_copy_course_org'] = partner_short_name
    context['organization_logo'] = organization_logo
示例#5
0
 def test_course_creation_with_org_in_system(self, store):
     """
     Tests course creation workflow when course organization exist in system.
     """
     add_organization({
         'name': 'Test Organization',
         'short_name': 'orgX',
         'description': 'Testing Organization Description',
     })
     with modulestore().default_store(store):
         response = self.client.ajax_post(
             self.course_create_rerun_url, {
                 'org': 'orgX',
                 'number': 'CS101',
                 'display_name': 'Course with web certs enabled',
                 'run': '2015_T2'
             })
         self.assertEqual(response.status_code, 200)
         data = parse_json(response)
         new_course_key = CourseKey.from_string(data['course_key'])
         course_orgs = get_course_organizations(new_course_key)
         self.assertEqual(len(course_orgs), 1)
         self.assertEqual(course_orgs[0]['short_name'], 'orgX')
 def test_get_course_organizations_returns_none_when_app_disabled(self):
     response = organizations_helpers.get_course_organizations(
         six.text_type(self.course.id))
     self.assertEqual(len(response), 0)