Commit 0173eaf9 by Dave St.Germain

Updated payload for new matlab endpoint.

parent 964e73f0
......@@ -14,6 +14,7 @@ PROBLEM_WEIGHT = "Problem Weight"
RANDOMIZATION = 'Randomization'
SHOW_ANSWER = "Show Answer"
TIMER_BETWEEN_ATTEMPTS = "Timer Between Attempts"
MATLAB_API_KEY = "Matlab API key"
@step('I have created a Blank Common Problem$')
def i_created_blank_common_problem(step):
......@@ -40,11 +41,12 @@ def i_see_advanced_settings_with_values(step):
world.verify_all_setting_entries(
[
[DISPLAY_NAME, "Blank Common Problem", True],
[MATLAB_API_KEY, "", False],
[MAXIMUM_ATTEMPTS, "", False],
[PROBLEM_WEIGHT, "", False],
[RANDOMIZATION, "Never", False],
[SHOW_ANSWER, "Finished", False],
[TIMER_BETWEEN_ATTEMPTS, "0", False]
[TIMER_BETWEEN_ATTEMPTS, "0", False],
])
......
......@@ -804,20 +804,7 @@ class MatlabInput(CodeInput):
xml = self.xml
# the new way to define the api key is to set it in the course advanced settings
api_key = getattr(self.capa_system, 'matlab_api_key', None)
if api_key:
plot_payload = '%api_key={}'.format(api_key)
else:
plot_payload = ''
# the old way to define api_key is to add it to the plot_payload xml.
# are there other things that go in the payload?
xml_payload = xml.findtext('./plot_payload')
if xml_payload:
plot_payload += '\n{}'.format(xml_payload)
self.plot_payload = plot_payload
self.plot_payload = xml.findtext('./plot_payload')
# Check if problem has been queued
self.queuename = 'matlab'
self.queue_msg = ''
......@@ -966,7 +953,10 @@ class MatlabInput(CodeInput):
contents = {
'grader_payload': self.plot_payload,
'student_info': json.dumps(student_info),
'student_response': response
'student_response': response,
'token': getattr(self.capa_system, 'matlab_api_key', None),
'endpoint_version': "2",
'requestor_id': anonymous_student_id,
}
(error, msg) = qinterface.send_to_queue(header=xheader,
......
......@@ -1878,13 +1878,16 @@ class CodeResponse(LoncapaResponse):
"""
grader_payload = codeparam.find('grader_payload')
grader_payload = grader_payload.text if grader_payload is not None else ''
self.payload = {
'grader_payload': grader_payload,
}
# matlab api key can be defined in course settings. if so, add it to the grader payload
# only if the problem didn't have an api key already defined.
api_key = getattr(self.capa_system, 'matlab_api_key', None)
if self.xml.find('matlabinput') and api_key and 'api_key' not in grader_payload:
grader_payload += '\n%api_key={}'.format(api_key)
self.payload = {'grader_payload': grader_payload}
if self.xml.find('matlabinput') and api_key:
self.payload['token'] = api_key
self.payload['endpoint_version'] = "2"
self.payload['requestor_id'] = self.capa_system.anonymous_student_id
self.initial_display = find_with_default(
codeparam, 'initial_display', '')
......
......@@ -642,7 +642,8 @@ class MatlabTest(unittest.TestCase):
body = system.xqueue['interface'].send_to_queue.call_args[1]['body']
payload = json.loads(body)
self.assertIn('%api_key=test_api_key', payload['grader_payload'])
self.assertEqual('test_api_key', payload['token'])
self.assertEqual('2', payload['endpoint_version'])
def test_get_html(self):
# usual output
......
......@@ -189,7 +189,15 @@ class CapaFields(object):
default=False,
scope=Scope.settings
)
matlab_api_key = String(help="API key for Matlab problems", scope=Scope.settings)
matlab_api_key = String(
display_name="Matlab API key",
help="Enter the API key provided by MathWorks for accessing the MATLAB Hosted Service. "
"This key is granted for exclusive use by this course for the specified duration. "
"Please do not share the API key with other courses and notify MathWorks immediately "
"if you believe the key is exposed or compromised. To obtain a key for your course, "
"or to report and issue, please contact moocsupport@mathworks.com",
scope=Scope.settings
)
class CapaMixin(CapaFields):
......
......@@ -87,7 +87,12 @@ class InheritanceMixin(XBlockMixin):
values={"min": 0}, scope=Scope.settings
)
matlab_api_key = String(
help="API key for Matlab problems",
display_name="Matlab API key",
help="Enter the API key provided by MathWorks for accessing the MATLAB Hosted Service. "
"This key is granted for exclusive use by this course for the specified duration. "
"Please do not share the API key with other courses and notify MathWorks immediately "
"if you believe the key is exposed or compromised. To obtain a key for your course, "
"or to report and issue, please contact moocsupport@mathworks.com",
scope=Scope.settings
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment