-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Fixes and improvement to LTI. #1987
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,9 +36,8 @@ def setup_mock_lti_server(): | |
| 'lti_endpoint': 'correct_lti_endpoint' | ||
| } | ||
|
|
||
| # Flag for acceptance tests used for creating right callback_url and sending | ||
| # graded result. Used in MockLTIRequestHandler. | ||
| server.test_mode = True | ||
| # For testing on localhost make callback url using referer host. | ||
|
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. typo: referrer
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. not typo :) http://en.wikipedia.org/wiki/HTTP_referer
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. LOL, HTTP referer (originally a misspelling of referrer) you are right) Sincerely, среда, 25 декабря 2013 г. в 16:35, Oleg Marshev написал:
|
||
| server.real_callback_url_on = False | ||
|
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. please rename to use_real_callback_url
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. fixed |
||
|
|
||
| # Store the server instance in lettuce's world | ||
| # so that other steps can access it | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,7 @@ def do_POST(self): | |
| ''' | ||
| if 'grade' in self.path and self._send_graded_result().status_code == 200: | ||
| status_message = 'LTI consumer (edX) responded with XML content:<br>' + self.server.grade_data['TC answer'] | ||
| self.server.grade_data['callback_url'] = None | ||
| self.server.grade_data = None | ||
| self._send_response(status_message, 200) | ||
| # Respond to request with correct lti endpoint: | ||
| elif self._is_correct_lti_request(): | ||
|
|
@@ -152,12 +152,14 @@ def _send_graded_result(self): | |
| </imsx_POXEnvelopeRequest> | ||
| """) | ||
| data = payload.format(**values) | ||
| # get relative part, because host name is different in a) manual tests b) acceptance tests c) demos | ||
| if getattr(self.server, 'test_mode', None): | ||
| if getattr(self.server, 'use_real_callback_url', None): | ||
| # Use exact URL that was sent from TC when using this Stub LTI server | ||
| # as TP in real standalone environment. | ||
| url = self.server.grade_data['callback_url'] | ||
| else: | ||
| # Use relative URL when using TP locally for manual testing or jenkins. | ||
| relative_url = urlparse.urlparse(self.server.grade_data['callback_url']).path | ||
| url = self.server.referer_host + relative_url | ||
| else: | ||
| url = self.server.grade_data['callback_url'] | ||
|
|
||
| headers = {'Content-Type': 'application/xml', 'X-Requested-With': 'XMLHttpRequest'} | ||
| headers['Authorization'] = self.oauth_sign(url, data) | ||
|
|
@@ -167,11 +169,12 @@ def _send_graded_result(self): | |
| if getattr(self.server, 'run_inside_unittest_flag', None): | ||
| response = mock.Mock(status_code=200, url=url, data=data, headers=headers) | ||
| return response | ||
|
|
||
| # Send request ignoring verification of SSL certificate | ||
| response = requests.post( | ||
| url, | ||
| data=data, | ||
| headers=headers | ||
| headers=headers, | ||
| verify=False | ||
|
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. add comment here, why we need it |
||
| ) | ||
| self.server.grade_data['TC answer'] = response.content | ||
| return response | ||
|
|
@@ -182,6 +185,7 @@ def _send_response(self, message, status_code): | |
| ''' | ||
| self._send_head(status_code) | ||
| if getattr(self.server, 'grade_data', False): # lti can be graded | ||
| url = "//{}:{}".format(self.server.server_host, self.server.server_port) | ||
| response_str = textwrap.dedent(""" | ||
| <html> | ||
| <head> | ||
|
|
@@ -198,7 +202,7 @@ def _send_response(self, message, status_code): | |
| </form> | ||
| </body> | ||
| </html> | ||
| """).format(message, url="http://%s:%s" % self.server.server_address) | ||
| """).format(message, url=url) | ||
| else: # lti can't be graded | ||
| response_str = textwrap.dedent(""" | ||
| <html> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,10 @@ | |
| 'lti_endpoint': 'correct_lti_endpoint' | ||
| } | ||
| server.server_host = server_host | ||
| server.server_port = server_port | ||
|
|
||
| # If in test mode mock lti server will make callback url using referer host. | ||
| # Used in MockLTIRequestHandler when sending graded result. | ||
| server.test_mode = True | ||
| # For testing on localhost make callback url using referer host. | ||
|
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. please add some helpful defaults: |
||
| server.use_real_callback_url = False | ||
|
|
||
| try: | ||
| server.serve_forever() | ||
|
|
||
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.
add doc string to every test that checks exception rising.