Esempio n. 1
0
 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)
Esempio n. 2
0
 def test_create_course_duplicate_course(self):
     """Test new course creation - error path"""
     resp = self.client.post(reverse('create_new_course'), self.course_data)
     resp = self.client.post(reverse('create_new_course'), self.course_data)
     data = parse_json(resp)
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(data['ErrMsg'], 'There is already a course defined with this name.')
Esempio n. 3
0
 def test_create_course_check_forum_seeding(self):
     """Test new course creation and verify forum seeding """
     resp = self.client.post(reverse('create_new_course'), self.course_data)
     self.assertEqual(resp.status_code, 200)
     data = parse_json(resp)
     self.assertEqual(data['id'], 'i4x://MITx/999/course/Robot_Super_Course')
     self.assertTrue(are_permissions_roles_seeded('MITx/999/Robot_Super_Course'))
    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)
Esempio n. 5
0
    def test_clone_course(self):

        course_data = {
            'template': 'i4x://edx/templates/course/Empty',
            'org': 'MITx',
            'number': '999',
            'display_name': 'Robot Super Course',
        }

        module_store = modulestore('direct')
        import_from_xml(module_store, 'common/test/data/', ['full'])

        resp = self.client.post(reverse('create_new_course'), course_data)
        self.assertEqual(resp.status_code, 200)
        data = parse_json(resp)
        self.assertEqual(data['id'], 'i4x://MITx/999/course/Robot_Super_Course')

        content_store = contentstore()

        source_location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012')
        dest_location = CourseDescriptor.id_to_location('MITx/999/Robot_Super_Course')

        clone_course(module_store, content_store, source_location, dest_location)

        # now loop through all the units in the course and verify that the clone can render them, which
        # means the objects are at least present
        items = module_store.get_items(Location(['i4x', 'edX', 'full', 'vertical', None]))
        self.assertGreater(len(items), 0)
        clone_items = module_store.get_items(Location(['i4x', 'MITx', '999', 'vertical', None]))
        self.assertGreater(len(clone_items), 0)
        for descriptor in items:
            new_loc = descriptor.location.replace(org='MITx', course='999')
            print "Checking {0} should now also be at {1}".format(descriptor.location.url(), new_loc.url())
            resp = self.client.get(reverse('edit_unit', kwargs={'location': new_loc.url()}))
            self.assertEqual(resp.status_code, 200)
    def test_clone_course(self):

        course_data = {
            "template": "i4x://edx/templates/course/Empty",
            "org": "MITx",
            "number": "999",
            "display_name": "Robot Super Course",
        }

        module_store = modulestore("direct")
        import_from_xml(module_store, "common/test/data/", ["full"])

        resp = self.client.post(reverse("create_new_course"), course_data)
        self.assertEqual(resp.status_code, 200)
        data = parse_json(resp)
        self.assertEqual(data["id"], "i4x://MITx/999/course/Robot_Super_Course")

        content_store = contentstore()

        source_location = CourseDescriptor.id_to_location("edX/full/6.002_Spring_2012")
        dest_location = CourseDescriptor.id_to_location("MITx/999/Robot_Super_Course")

        clone_course(module_store, content_store, source_location, dest_location)

        # now loop through all the units in the course and verify that the clone can render them, which
        # means the objects are at least present
        items = module_store.get_items(Location(["i4x", "edX", "full", "vertical", None]))
        self.assertGreater(len(items), 0)
        clone_items = module_store.get_items(Location(["i4x", "MITx", "999", "vertical", None]))
        self.assertGreater(len(clone_items), 0)
        for descriptor in items:
            new_loc = descriptor.location.replace(org="MITx", course="999")
            print "Checking {0} should now also be at {1}".format(descriptor.location.url(), new_loc.url())
            resp = self.client.get(reverse("edit_unit", kwargs={"location": new_loc.url()}))
            self.assertEqual(resp.status_code, 200)
Esempio n. 7
0
 def test_create_course(self):
     """Test new course creation - happy path"""
     resp = self.client.post(reverse('create_new_course'), self.course_data)
     self.assertEqual(resp.status_code, 200)
     data = parse_json(resp)
     self.assertEqual(data['id'],
                      'i4x://MITx/999/course/Robot_Super_Course')
 def test_create_course(self):
     """Test new course creation - happy path"""
     resp = self.client.post(reverse('create_new_course'), self.course_data)
     self.assertEqual(resp.status_code, 200)
     data = parse_json(resp)
     self.assertEqual(data[
                      'id'], 'i4x://MITx/999/course/Robot_Super_Course')
 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)
Esempio n. 10
0
    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.assertEquals(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.assertEquals(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 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.assertEquals(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.assertEquals(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)
Esempio n. 12
0
    def test_create_course_with_bad_organization(self):
        """Test new course creation - error path for bad organization name"""
        self.course_data['org'] = 'University of California, Berkeley'
        resp = self.client.post(reverse('create_new_course'), self.course_data)
        data = parse_json(resp)

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(data['ErrMsg'],
                         "Unable to create course 'Robot Super Course'.\n\nInvalid characters in 'University of California, Berkeley'.")
Esempio n. 13
0
    def test_excessive_login_failures(self):
        # try logging in 3 times, the account should get locked for 3 seconds
        # note we want to keep the lockout time short, so we don't slow down the tests

        with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MAX_FAILED_LOGIN_ATTEMPTS': True}):
            self.create_account(self.username, self.email, self.pw)
            self.activate_user(self.email)

            for i in xrange(3):
                resp = self._login(self.email, 'wrong_password{0}'.format(i))
                self.assertEqual(resp.status_code, 200)
                data = parse_json(resp)
                self.assertFalse(data['success'])
                self.assertIn(
                    'Email or password is incorrect.',
                    data['value']
                )

            # now the account should be locked

            resp = self._login(self.email, 'wrong_password')
            self.assertEqual(resp.status_code, 200)
            data = parse_json(resp)
            self.assertFalse(data['success'])
            self.assertIn(
                'This account has been temporarily locked due to excessive login failures.',
                data['value']
            )

            with freeze_time('2100-01-01'):
                self.login(self.email, self.pw)

            # make sure the failed attempt counter gets reset on successful login
            resp = self._login(self.email, 'wrong_password')
            self.assertEqual(resp.status_code, 200)
            data = parse_json(resp)
            self.assertFalse(data['success'])

            # account should not be locked out after just one attempt
            self.login(self.email, self.pw)

            # do one more login when there is no bad login counter row at all in the database to
            # test the "ObjectNotFound" case
            self.login(self.email, self.pw)
Esempio n. 14
0
    def test_excessive_login_failures(self):
        # try logging in 3 times, the account should get locked for 3 seconds
        # note we want to keep the lockout time short, so we don't slow down the tests

        with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MAX_FAILED_LOGIN_ATTEMPTS': True}):
            self.create_account(self.username, self.email, self.pw)
            self.activate_user(self.email)

            for i in xrange(3):
                resp = self._login(self.email, 'wrong_password{0}'.format(i))
                self.assertEqual(resp.status_code, 200)
                data = parse_json(resp)
                self.assertFalse(data['success'])
                self.assertIn(
                    'Email or password is incorrect.',
                    data['value']
                )

            # now the account should be locked

            resp = self._login(self.email, 'wrong_password')
            self.assertEqual(resp.status_code, 200)
            data = parse_json(resp)
            self.assertFalse(data['success'])
            self.assertIn(
                'This account has been temporarily locked due to excessive login failures. Try again later.',
                data['value']
            )

            with freeze_time('2100-01-01'):
                self.login(self.email, self.pw)

            # make sure the failed attempt counter gets reset on successful login
            resp = self._login(self.email, 'wrong_password')
            self.assertEqual(resp.status_code, 200)
            data = parse_json(resp)
            self.assertFalse(data['success'])

            # account should not be locked out after just one attempt
            self.login(self.email, self.pw)

            # do one more login when there is no bad login counter row at all in the database to
            # test the "ObjectNotFound" case
            self.login(self.email, self.pw)
Esempio n. 15
0
        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.assertEquals(resp.status_code, 200)

            return parse_json(resp)['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.assertEquals(resp.status_code, 200)

            return parse_json(resp)['html']
Esempio n. 17
0
 def test_login_ratelimited(self):
     # try logging in 30 times, the default limit in the number of failed
     # login attempts in one 5 minute period before the rate gets limited
     for i in xrange(30):
         resp = self._login(self.email, 'wrong_password{0}'.format(i))
         self.assertEqual(resp.status_code, 200)
     resp = self._login(self.email, 'wrong_password')
     self.assertEqual(resp.status_code, 200)
     data = parse_json(resp)
     self.assertFalse(data['success'])
     self.assertIn('Too many failed login attempts.', data['value'])
Esempio n. 18
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)
        data = parse_json(resp)
        self.assertEqual(data['success'], True)

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

        return resp
Esempio n. 19
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)
        data = parse_json(resp)
        self.assertEqual(data['success'], True)

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

        return resp
Esempio n. 20
0
 def test_login_ratelimited(self):
     # try logging in 30 times, the default limit in the number of failed
     # login attempts in one 5 minute period before the rate gets limited
     for i in xrange(30):
         resp = self._login(self.email, 'wrong_password{0}'.format(i))
         self.assertEqual(resp.status_code, 200)
     resp = self._login(self.email, 'wrong_password')
     self.assertEqual(resp.status_code, 200)
     data = parse_json(resp)
     self.assertFalse(data['success'])
     self.assertIn('Too many failed login attempts.', data['value'])
Esempio n. 21
0
    def test_create_course_duplicate_number(self):
        """Test new course creation - error path"""
        resp = self.client.post(reverse('create_new_course'), self.course_data)
        self.course_data['display_name'] = 'Robot Super Course Two'

        resp = self.client.post(reverse('create_new_course'), self.course_data)
        data = parse_json(resp)

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(data['ErrMsg'],
                         'There is already a course defined with the same organization and course number.')
Esempio n. 22
0
 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
Esempio n. 23
0
    def test_login(self):
        self.create_account(self.username, self.email, self.pw)

        # Not activated yet.  Login should fail.
        resp = self._login(self.email, self.pw)
        data = parse_json(resp)
        self.assertFalse(data['success'])

        self.activate_user(self.email)

        # Now login should work
        self.login(self.email, self.pw)
Esempio n. 24
0
    def test_login(self):
        self.create_account(self.username, self.email, self.pw)

        # Not activated yet.  Login should fail.
        resp = self._login(self.email, self.pw)
        data = parse_json(resp)
        self.assertFalse(data['success'])

        self.activate_user(self.email)

        # Now login should work
        self.login(self.email, self.pw)
Esempio n. 25
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
    def test_clone_item(self):
        """Test cloning an item. E.g. creating a new section"""
        CourseFactory.create(org="MITx", course="999", display_name="Robot Super Course")

        section_data = {
            "parent_location": "i4x://MITx/999/course/Robot_Super_Course",
            "template": "i4x://edx/templates/chapter/Empty",
            "display_name": "Section One",
        }

        resp = self.client.post(reverse("clone_item"), section_data)

        self.assertEqual(resp.status_code, 200)
        data = parse_json(resp)
        self.assertRegexpMatches(data["id"], r"^i4x://MITx/999/chapter/([0-9]|[a-f]){32}$")
 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'])
 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'])
    def test_rerun(self):
        """
        Just testing the functionality the view handler adds over the tasks tested in test_clone_course
        """
        response = self.client.ajax_post(self.course_create_rerun_url, {
            'source_course_key': unicode(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')
        dest_course = self.store.get_course(dest_course_key)
        self.assertEqual(dest_course.start, CourseFields.start.default)
 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)
 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)
    def test_rerun(self):
        """
        Just testing the functionality the view handler adds over the tasks tested in test_clone_course
        """
        response = self.client.ajax_post('/course/', {
            'source_course_key': unicode(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')
        dest_course = self.store.get_course(dest_course_key)
        self.assertEqual(dest_course.start, CourseFields.start.default)
 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, [])
 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, [])
Esempio n. 36
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'])
Esempio n. 37
0
    def test_clone_item(self):
        """Test cloning an item. E.g. creating a new section"""
        CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course')

        section_data = {
            'parent_location': 'i4x://MITx/999/course/Robot_Super_Course',
            'template': 'i4x://edx/templates/chapter/Empty',
            'display_name': 'Section One',
        }

        resp = self.client.post(reverse('clone_item'), section_data)

        self.assertEqual(resp.status_code, 200)
        data = parse_json(resp)
        self.assertRegexpMatches(
            data['id'],
            r"^i4x://MITx/999/chapter/([0-9]|[a-f]){32}$"
        )
Esempio n. 38
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 = 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
Esempio n. 39
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 = 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
Esempio n. 40
0
    def test_capa_module(self):
        """Test that a problem treats markdown specially."""
        CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course')

        problem_data = {
            'parent_location': 'i4x://MITx/999/course/Robot_Super_Course',
            'template': 'i4x://edx/templates/problem/Blank_Common_Problem'
        }

        resp = self.client.post(reverse('clone_item'), problem_data)

        self.assertEqual(resp.status_code, 200)
        payload = parse_json(resp)
        problem_loc = payload['id']
        problem = get_modulestore(problem_loc).get_item(problem_loc)
        # should be a CapaDescriptor
        self.assertIsInstance(problem, CapaDescriptor, "New problem is not a CapaDescriptor")
        context = problem.get_context()
        self.assertIn('markdown', context, "markdown is missing from context")
        self.assertNotIn('markdown', problem.editable_metadata_fields, "Markdown slipped into the editable metadata fields")
Esempio n. 41
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'], unicode(lib_key))
        self.assertEqual(info['previous_version'], None)
        self.assertNotEqual(info['version'], None)
        self.assertNotEqual(info['version'], '')
        self.assertEqual(info['version'], unicode(version))
 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_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')
Esempio n. 44
0
 def test_create_account_errors(self):
     # No post data -- should fail
     resp = self.client.post('/create_account', {})
     self.assertEqual(resp.status_code, 400)
     data = parse_json(resp)
     self.assertEqual(data['success'], False)
Esempio n. 45
0
 def login(self, email, password):
     """Login, check that it worked."""
     resp = self._login(email, password)
     data = parse_json(resp)
     self.assertTrue(data['success'])
     return resp
Esempio n. 46
0
 def login(self, email, password):
     """Login, check that it worked."""
     resp = self._login(email, password)
     data = parse_json(resp)
     self.assertTrue(data['success'])
     return resp
Esempio n. 47
0
 def test_create_account_errors(self):
     # No post data -- should fail
     resp = self.client.post('/create_account', {})
     self.assertEqual(resp.status_code, 200)
     data = parse_json(resp)
     self.assertEqual(data['success'], False)