def _list_libraries(self):
     """
     Use the REST API to get a list of libraries visible to the current user.
     """
     response = self.client.get_json(LIBRARY_REST_URL)
     self.assertEqual(response.status_code, 200)
     return parse_json(response)
示例#2
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 test_studio_user_permissions(self):
        """
        Test that user could attach to the problem only libraries that he has access (or which were created by him).
        This test was created on the basis of bug described in the pull requests on github:
        https://github.com/edx/edx-platform/pull/11331
        https://github.com/edx/edx-platform/pull/11611
        """
        self._create_library(org='admin_org_1', library='lib_adm_1', display_name='admin_lib_1')
        self._create_library(org='admin_org_2', library='lib_adm_2', display_name='admin_lib_2')

        self._login_as_non_staff_user()

        self._create_library(org='staff_org_1', library='lib_staff_1', display_name='staff_lib_1')
        self._create_library(org='staff_org_2', library='lib_staff_2', display_name='staff_lib_2')

        with modulestore().default_store(ModuleStoreEnum.Type.split):
            course = CourseFactory.create()

        instructor_role = CourseInstructorRole(course.id)
        auth.add_users(self.user, instructor_role, self.non_staff_user)

        lib_block = ItemFactory.create(
            category='library_content',
            parent_location=course.location,
            user_id=self.non_staff_user.id,
            publish_item=False
        )

        def _get_settings_html():
            """
            Helper function to get block settings HTML
            Used to check the available libraries.
            """
            edit_view_url = reverse_usage_url("xblock_view_handler", lib_block.location, {"view_name": STUDIO_VIEW})

            resp = self.client.get_json(edit_view_url)
            self.assertEqual(resp.status_code, 200)

            return parse_json(resp)['html']

        self._login_as_staff_user()
        staff_settings_html = _get_settings_html()
        self.assertIn('staff_lib_1', staff_settings_html)
        self.assertIn('staff_lib_2', staff_settings_html)
        self.assertIn('admin_lib_1', staff_settings_html)
        self.assertIn('admin_lib_2', staff_settings_html)

        self._login_as_non_staff_user()
        response = self.client.get_json(LIBRARY_REST_URL)
        staff_libs = parse_json(response)
        self.assertEqual(2, len(staff_libs))

        non_staff_settings_html = _get_settings_html()
        self.assertIn('staff_lib_1', non_staff_settings_html)
        self.assertIn('staff_lib_2', non_staff_settings_html)
        self.assertNotIn('admin_lib_1', non_staff_settings_html)
        self.assertNotIn('admin_lib_2', non_staff_settings_html)
        def _get_settings_html():
            """
            Helper function to get block settings HTML
            Used to check the available libraries.
            """
            edit_view_url = reverse_usage_url("xblock_view_handler", lib_block.location, {"view_name": STUDIO_VIEW})

            resp = self.client.get_json(edit_view_url)
            self.assertEqual(resp.status_code, 200)

            return parse_json(resp)['html']
示例#6
0
    def create_account(self, username, email, password):
        """Create the account and check that it worked"""
        resp = self._create_account(username, email, password)
        self.assertEqual(resp.status_code, 200)
        json_data = parse_json(resp)
        self.assertEqual(json_data['success'], True)

        # Check both that the user is created, and inactive
        self.assertFalse(user(email).is_active)

        return resp
示例#7
0
 def test_no_duplicate_libraries(self):
     """
     We should not be able to create multiple libraries with the same key
     """
     lib = LibraryFactory.create()
     lib_key = lib.location.library_key
     response = self.client.ajax_post(LIBRARY_REST_URL, {
         'org': lib_key.org,
         'library': lib_key.library,
         'display_name': "A Duplicate key, same as 'lib'",
     })
     self.assertIn('already a library defined', parse_json(response)['ErrMsg'])
     self.assertEqual(response.status_code, 400)
 def _create_library(self, org="org", library="lib", display_name="Test Library"):
     """
     Helper method used to create a library. Uses the REST API.
     """
     response = self.client.ajax_post(LIBRARY_REST_URL, {
         'org': org,
         'library': library,
         'display_name': display_name,
     })
     self.assertEqual(response.status_code, 200)
     lib_info = parse_json(response)
     lib_key = CourseKey.from_string(lib_info['library_key'])
     self.assertIsInstance(lib_key, LibraryLocator)
     return lib_key
示例#9
0
 def test_newly_created_course_has_web_certs_enabled(self, store):
     """
     Tests newly created course has web certs enabled by default.
     """
     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 = self.store.get_course(new_course_key)
         self.assertTrue(course.cert_html_view_enabled)
示例#10
0
 def test_library_with_unknown_organization_validation_error(self):
     """
     Test that when automatic organization creation is disabled,
     creating a content library with an unknown organization raises an error.
     """
     with self.assertRaises(InvalidOrganizationException):
         get_organization_by_short_name("org_xyz")
     response = self.client.ajax_post(LIBRARY_REST_URL, {
         'org': "org_xyz",
         'library': "org_test_lib",
         'display_name': "This library's organization doesn't exist!",
     })
     assert response.status_code == 400
     assert "'org_xyz' is not a valid organization identifier" in parse_json(response)['ErrMsg']
     with self.assertRaises(InvalidOrganizationException):
         get_organization_by_short_name("org_xyz")
示例#11
0
    def test_component_limits(self):
        """
        Test that component limits in libraries are respected.
        """
        with self.settings(MAX_BLOCKS_PER_CONTENT_LIBRARY=1):
            library = LibraryFactory.create()
            data = {
                'parent_locator': str(library.location),
                'category': 'html'
            }
            response = self.client.ajax_post(reverse('xblock_handler'), data)
            self.assertEqual(response.status_code, 200)

            # Adding another component should cause failure:
            response = self.client.ajax_post(reverse('xblock_handler'), data)
            self.assertEqual(response.status_code, 400)
            self.assertIn('cannot have more than 1 component', parse_json(response)['error'])
示例#12
0
 def test_course_creation_for_unknown_organization_strict(self, store):
     """
     Tests that when ORGANIZATIONS_AUTOCREATE is False,
     creating a course-run with an unknown org slug will raise a validation error.
     """
     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, 400)
         with self.assertRaises(InvalidOrganizationException):
             get_organization_by_short_name("orgX")
         data = parse_json(response)
         self.assertIn('Organization you selected does not exist in the system', data['error'])
示例#13
0
 def test_course_creation_with_org_not_in_system(self, store):
     """
     Tests course creation workflow when course organization does not exist
     in system.
     """
     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, 400)
         data = parse_json(response)
         self.assertIn(
             u'Organization you selected does not exist in the system',
             data['error'])
示例#14
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, [])
示例#15
0
    def test_list_libraries(self):
        """
        Test that we can GET /library/ to list all libraries visible to the current user.
        """
        # Create some more libraries
        libraries = [LibraryFactory.create() for _ in range(3)]
        lib_dict = {lib.location.library_key: lib for lib in libraries}

        response = self.client.get_json(LIBRARY_REST_URL)
        self.assertEqual(response.status_code, 200)
        lib_list = parse_json(response)
        self.assertEqual(len(lib_list), len(libraries))
        for entry in lib_list:
            self.assertIn("library_key", entry)
            self.assertIn("display_name", entry)
            key = CourseKey.from_string(entry["library_key"])
            self.assertIn(key, lib_dict)
            self.assertEqual(entry["display_name"], lib_dict[key].display_name)
            del lib_dict[key]  # To ensure no duplicates are matched
示例#16
0
    def test_get_lib_info(self):
        """
        Test that we can get data about a library (in JSON format) using /library/:key/
        """
        # Create a library
        lib_key = LibraryFactory.create().location.library_key
        # Re-load the library from the modulestore, explicitly including version information:
        lib = self.store.get_library(lib_key, remove_version=False, remove_branch=False)
        version = lib.location.library_key.version_guid
        self.assertNotEqual(version, None)

        response = self.client.get_json(make_url_for_lib(lib_key))
        self.assertEqual(response.status_code, 200)
        info = parse_json(response)
        self.assertEqual(info['display_name'], lib.display_name)
        self.assertEqual(info['library_id'], text_type(lib_key))
        self.assertEqual(info['previous_version'], None)
        self.assertNotEqual(info['version'], None)
        self.assertNotEqual(info['version'], '')
        self.assertEqual(info['version'], text_type(version))
示例#17
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')
示例#18
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')