Exemple #1
0
 def test_remove_organization_course(self):
     """ Unit Test: test_remove_organization_course """
     api.add_organization_course(self.test_organization,
                                 self.test_course_key)
     organizations = api.get_course_organizations(self.test_course_key)
     self.assertEqual(len(organizations), 1)
     with self.assertNumQueries(3):
         api.remove_organization_course(self.test_organization,
                                        self.test_course_key)
     organizations = api.get_course_organizations(self.test_course_key)
     self.assertEqual(len(organizations), 0)
Exemple #2
0
 def test_remove_organization_course_missing_course(self):
     """ Unit Test: test_remove_organization_course_missing_organization """
     api.add_organization_course(self.test_organization,
                                 'edX/DemoX/Demo_Course')
     organizations = api.get_course_organizations('edX/DemoX/Demo_Course')
     self.assertEqual(len(organizations), 1)
     with self.assertNumQueries(1):
         api.remove_organization_course(self.test_organization,
                                        self.test_course_key)
     organizations = api.get_course_organizations(self.test_course_key)
     self.assertEqual(len(organizations), 0)
 def test_remove_organization_course(self):
     """ Unit Test: test_remove_organization_course """
     api.add_organization_course(
         self.test_organization,
         self.test_course_key
     )
     organizations = api.get_course_organizations(self.test_course_key)
     self.assertEqual(len(organizations), 1)
     with self.assertNumQueries(3):
         api.remove_organization_course(self.test_organization, self.test_course_key)
     organizations = api.get_course_organizations(self.test_course_key)
     self.assertEqual(len(organizations), 0)
 def test_remove_organization_course_missing_course(self):
     """ Unit Test: test_remove_organization_course_missing_organization """
     api.add_organization_course(
         self.test_organization,
         'edX/DemoX/Demo_Course'
     )
     organizations = api.get_course_organizations('edX/DemoX/Demo_Course')
     self.assertEqual(len(organizations), 1)
     with self.assertNumQueries(1):
         api.remove_organization_course(self.test_organization, self.test_course_key)
     organizations = api.get_course_organizations(self.test_course_key)
     self.assertEqual(len(organizations), 0)
Exemple #5
0
 def test_remove_organization_course_missing_organization(self):
     """ Unit Test: test_remove_organization_course_missing_organization """
     with self.assertNumQueries(1):
         api.remove_organization_course(self.test_organization,
                                        self.test_course_key)
     organizations = api.get_course_organizations(self.test_course_key)
     self.assertEqual(len(organizations), 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_course_creation_for_known_organization(self,
                                                 organizations_autocreate):
     """
     Tests course creation workflow when course organization exist in system.
     """
     add_organization({
         'name': 'Test Organization',
         'short_name': 'orgX',
         'description': 'Testing Organization Description',
     })
     with override_settings(
             ORGANIZATIONS_AUTOCREATE=organizations_autocreate):
         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 get_course_organizations(course_id):
    """
    Client API operation adapter/wrapper
    """
    if not settings.FEATURES.get('ORGANIZATIONS_APP', False):
        return []
    from organizations import api as organizations_api
    return organizations_api.get_course_organizations(course_id)
Exemple #9
0
def get_course_organizations(course_id):
    """
    Client API operation adapter/wrapper
    """
    if not organizations_enabled():
        return []
    from organizations import api as organizations_api
    return organizations_api.get_course_organizations(course_id)
def get_course_organizations(course_id):
    """
    Client API operation adapter/wrapper
    """
    if not settings.FEATURES.get('ORGANIZATIONS_APP', False):
        return []
    from organizations import api as organizations_api
    return organizations_api.get_course_organizations(course_id)
def get_course_organizations(course_id):
    """
    Client API operation adapter/wrapper
    """
    if not organizations_enabled():
        return []
    from organizations import api as organizations_api
    return organizations_api.get_course_organizations(course_id)
Exemple #12
0
 def test_get_course_organizations(self):
     """ Unit Test: test_get_course_organizations """
     api.add_organization_course(self.test_organization,
                                 self.test_course_key)
     with self.assertNumQueries(1):
         course_organizations = api.get_course_organizations(
             self.test_course_key)
     self.assertEqual(len(course_organizations), 1)
 def test_get_course_organizations(self):
     """ Unit Test: test_get_course_organizations """
     api.add_organization_course(
         self.test_organization,
         self.test_course_key
     )
     with self.assertNumQueries(1):
         course_organizations = api.get_course_organizations(self.test_course_key)
     self.assertEqual(len(course_organizations), 1)
Exemple #14
0
    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,  # lint-amnesty, pylint: disable=no-member
            '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)})  # lint-amnesty, pylint: disable=no-member
        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  # lint-amnesty, pylint: disable=no-member
        else:
            assert course_run.id.course == original_course_run.id.course  # lint-amnesty, pylint: disable=no-member

        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)  # lint-amnesty, pylint: disable=no-member
Exemple #15
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 = organizations_api.get_course_organizations(course_key=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
Exemple #16
0
 def test_course_creation_for_unknown_organization_relaxed(self, store):
     """
     Tests that when ORGANIZATIONS_AUTOCREATE is True,
     creating a course-run with an unknown org slug will create an organization
     and organization-course linkage in the system.
     """
     with self.assertRaises(InvalidOrganizationException):
         get_organization_by_short_name("orgX")
     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)
         self.assertIsNotNone(get_organization_by_short_name("orgX"))
         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')
Exemple #17
0
def get_secondary_orgs_of_course(course_id,
                                 primary_org_short_name,
                                 return_short_name=False):
    """
    Returns list of all secondary organizations linked with the course.
    It will return list of organizations short names if return_short_name is True otherwise it will send
    organizations list.
    """
    if not organizations_enabled():
        return []
    from organizations import api as organizations_api
    all_organizations = organizations_api.get_course_organizations(course_id)

    # exclude primary organization from the list
    secondary_organizations = [
        org for org in all_organizations
        if not (org['short_name'] == primary_org_short_name)
    ]
    if return_short_name:
        secondary_organizations = [
            org['short_name'] for org in secondary_organizations
        ]
    return secondary_organizations
 def test_remove_organization_course_missing_organization(self):
     """ Unit Test: test_remove_organization_course_missing_organization """
     with self.assertNumQueries(1):
         api.remove_organization_course(self.test_organization, self.test_course_key)
     organizations = api.get_course_organizations(self.test_course_key)
     self.assertEqual(len(organizations), 0)