-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Handle anonymous and unenrolled users on the new course home page #15456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,141 +0,0 @@ | ||
| """ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reviewers: I moved this code to helpers.py as otherwise there are circular imports when accessing this package. |
||
| integration tests for xmodule | ||
|
|
||
| Contains: | ||
|
|
||
| 1. BaseTestXmodule class provides course and users | ||
| for testing Xmodules with mongo store. | ||
| """ | ||
|
|
||
| from django.core.urlresolvers import reverse | ||
| from django.test.client import Client | ||
|
|
||
| from edxmako.shortcuts import render_to_string | ||
| from lms.djangoapps.lms_xblock.field_data import LmsFieldData | ||
| from openedx.core.lib.url_utils import quote_slashes | ||
| from student.tests.factories import UserFactory, CourseEnrollmentFactory | ||
| from xblock.field_data import DictFieldData | ||
| from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE | ||
| from xmodule.tests import get_test_system, get_test_descriptor_system | ||
| from xmodule.modulestore.django import modulestore | ||
| from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory | ||
| from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase | ||
|
|
||
|
|
||
| class BaseTestXmodule(ModuleStoreTestCase): | ||
| """Base class for testing Xmodules with mongo store. | ||
|
|
||
| This class prepares course and users for tests: | ||
| 1. create test course; | ||
| 2. create, enroll and login users for this course; | ||
|
|
||
| Any xmodule should overwrite only next parameters for test: | ||
| 1. CATEGORY | ||
| 2. DATA or METADATA | ||
| 3. MODEL_DATA | ||
| 4. COURSE_DATA and USER_COUNT if needed | ||
|
|
||
| This class should not contain any tests, because CATEGORY | ||
| should be defined in child class. | ||
| """ | ||
| MODULESTORE = TEST_DATA_MONGO_MODULESTORE | ||
|
|
||
| USER_COUNT = 2 | ||
| COURSE_DATA = {} | ||
|
|
||
| # Data from YAML common/lib/xmodule/xmodule/templates/NAME/default.yaml | ||
| CATEGORY = "vertical" | ||
| DATA = '' | ||
| # METADATA must be overwritten for every instance that uses it. Otherwise, | ||
| # if we'll change it in the tests, it will be changed for all other instances | ||
| # of parent class. | ||
| METADATA = {} | ||
| MODEL_DATA = {'data': '<some_module></some_module>'} | ||
|
|
||
| def new_module_runtime(self): | ||
| """ | ||
| Generate a new ModuleSystem that is minimally set up for testing | ||
| """ | ||
| return get_test_system(course_id=self.course.id) | ||
|
|
||
| def new_descriptor_runtime(self): | ||
| runtime = get_test_descriptor_system() | ||
| runtime.get_block = modulestore().get_item | ||
| return runtime | ||
|
|
||
| def initialize_module(self, **kwargs): | ||
| kwargs.update({ | ||
| 'parent_location': self.section.location, | ||
| 'category': self.CATEGORY | ||
| }) | ||
|
|
||
| self.item_descriptor = ItemFactory.create(**kwargs) | ||
|
|
||
| self.runtime = self.new_descriptor_runtime() | ||
|
|
||
| field_data = {} | ||
| field_data.update(self.MODEL_DATA) | ||
| student_data = DictFieldData(field_data) | ||
| self.item_descriptor._field_data = LmsFieldData(self.item_descriptor._field_data, student_data) | ||
|
|
||
| self.item_descriptor.xmodule_runtime = self.new_module_runtime() | ||
|
|
||
| self.item_url = unicode(self.item_descriptor.location) | ||
|
|
||
| def setup_course(self): | ||
| self.course = CourseFactory.create(data=self.COURSE_DATA) | ||
|
|
||
| # Turn off cache. | ||
| modulestore().request_cache = None | ||
| modulestore().metadata_inheritance_cache_subsystem = None | ||
|
|
||
| chapter = ItemFactory.create( | ||
| parent_location=self.course.location, | ||
| category="sequential", | ||
| ) | ||
| self.section = ItemFactory.create( | ||
| parent_location=chapter.location, | ||
| category="sequential" | ||
| ) | ||
|
|
||
| # username = robot{0}, password = 'test' | ||
| self.users = [ | ||
| UserFactory.create() | ||
| for dummy0 in range(self.USER_COUNT) | ||
| ] | ||
|
|
||
| for user in self.users: | ||
| CourseEnrollmentFactory.create(user=user, course_id=self.course.id) | ||
|
|
||
| # login all users for acces to Xmodule | ||
| self.clients = {user.username: Client() for user in self.users} | ||
| self.login_statuses = [ | ||
| self.clients[user.username].login( | ||
| username=user.username, password='test') | ||
| for user in self.users | ||
| ] | ||
|
|
||
| self.assertTrue(all(self.login_statuses)) | ||
|
|
||
| def setUp(self): | ||
| super(BaseTestXmodule, self).setUp() | ||
| self.setup_course() | ||
| self.initialize_module(metadata=self.METADATA, data=self.DATA) | ||
|
|
||
| def get_url(self, dispatch): | ||
| """Return item url with dispatch.""" | ||
| return reverse( | ||
| 'xblock_handler', | ||
| args=(unicode(self.course.id), quote_slashes(self.item_url), 'xmodule_handler', dispatch) | ||
| ) | ||
|
|
||
|
|
||
| class XModuleRenderingTestBase(BaseTestXmodule): | ||
|
|
||
| def new_module_runtime(self): | ||
| """ | ||
| Create a runtime that actually does html rendering | ||
| """ | ||
| runtime = super(XModuleRenderingTestBase, self).new_module_runtime() | ||
| runtime.render_template = render_to_string | ||
| return runtime | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
access_response = has_access(user, action, course, course.id)would never deny access for staff?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good questions:
My understanding is that this isn't changing the logic, because
has_accesswould return true for staff. It just moves the staff check earlier to make it clearer (to my mind) that staff gets to skip all the other logic.I'm not sure what you're saying. Are you thinking there's a performance impact to moving the staff check earlier? That probably is why some of the counts increased, so we could optimize it. However, I think that the clarity of understanding that staff always get access is a worthwhile trade off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @andy-armstrong.