-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Add handler_url usable by descriptors #1899
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
cpennington
merged 1 commit into
openedx:master
from
cpennington:descriptor-handler-url
Dec 20, 2013
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
Empty file.
Empty file.
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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """ | ||
| XBlock runtime implementations for edX Studio | ||
| """ | ||
|
|
||
| from django.core.urlresolvers import reverse | ||
|
|
||
| import xmodule.x_module | ||
| from lms.lib.xblock.runtime import quote_slashes | ||
|
|
||
|
|
||
| def handler_url(block, handler_name, suffix='', query='', thirdparty=False): | ||
| """ | ||
| Handler URL function for Studio | ||
| """ | ||
|
|
||
| if thirdparty: | ||
| raise NotImplementedError("edX Studio doesn't support third-party xblock handler urls") | ||
|
|
||
| url = reverse('component_handler', kwargs={ | ||
| 'usage_id': quote_slashes(str(block.scope_ids.usage_id)), | ||
| 'handler': handler_name, | ||
| 'suffix': suffix, | ||
| }).rstrip('/') | ||
|
|
||
| if query: | ||
| url += '?' + query | ||
|
|
||
| return url | ||
|
|
||
| xmodule.x_module.descriptor_global_handler_url = handler_url | ||
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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """ | ||
| Tests of edX Studio runtime functionality | ||
| """ | ||
| from urlparse import urlparse | ||
|
|
||
| from mock import Mock | ||
| from unittest import TestCase | ||
| from cms.lib.xblock.runtime import handler_url | ||
|
|
||
|
|
||
| class TestHandlerUrl(TestCase): | ||
| """Test the LMS handler_url""" | ||
|
|
||
| def setUp(self): | ||
| self.block = Mock() | ||
| self.course_id = "org/course/run" | ||
|
|
||
| def test_trailing_charecters(self): | ||
|
Contributor
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. This test just tests what is not returned... it seems like there should also be some tests verifying that what is returned is correct, as well. |
||
| self.assertFalse(handler_url(self.block, 'handler').endswith('?')) | ||
| self.assertFalse(handler_url(self.block, 'handler').endswith('/')) | ||
|
|
||
| self.assertFalse(handler_url(self.block, 'handler', 'suffix').endswith('?')) | ||
| self.assertFalse(handler_url(self.block, 'handler', 'suffix').endswith('/')) | ||
|
|
||
| self.assertFalse(handler_url(self.block, 'handler', 'suffix', 'query').endswith('?')) | ||
| self.assertFalse(handler_url(self.block, 'handler', 'suffix', 'query').endswith('/')) | ||
|
|
||
| self.assertFalse(handler_url(self.block, 'handler', query='query').endswith('?')) | ||
| self.assertFalse(handler_url(self.block, 'handler', query='query').endswith('/')) | ||
|
|
||
| def _parsed_query(self, query_string): | ||
| """Return the parsed query string from a handler_url generated with the supplied query_string""" | ||
| return urlparse(handler_url(self.block, 'handler', query=query_string)).query | ||
|
|
||
| def test_query_string(self): | ||
| self.assertIn('foo=bar', self._parsed_query('foo=bar')) | ||
| self.assertIn('foo=bar&baz=true', self._parsed_query('foo=bar&baz=true')) | ||
| self.assertIn('foo&bar&baz', self._parsed_query('foo&bar&baz')) | ||
|
|
||
| def _parsed_path(self, handler_name='handler', suffix=''): | ||
| """Return the parsed path from a handler_url with the supplied handler_name and suffix""" | ||
| return urlparse(handler_url(self.block, handler_name, suffix=suffix)).path | ||
|
|
||
| def test_suffix(self): | ||
| self.assertTrue(self._parsed_path(suffix="foo").endswith('foo')) | ||
| self.assertTrue(self._parsed_path(suffix="foo/bar").endswith('foo/bar')) | ||
| self.assertTrue(self._parsed_path(suffix="/foo/bar").endswith('/foo/bar')) | ||
|
|
||
| def test_handler_name(self): | ||
| self.assertIn('handler1', self._parsed_path('handler1')) | ||
| self.assertIn('handler_a', self._parsed_path('handler_a')) | ||
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
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.
thirdpartyis unused. Is that OK? Is it because the way these URLs are made they are always ok for third-party, or because we don't need third-party URLs in Studio?