diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index 8777a11c08..6e88882be0 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -230,8 +230,8 @@ class InputTypeBase(object): self.setup() except Exception as err: # Something went wrong: add xml to message, but keep the traceback - msg = "Error in xml '{x}': {err} ".format( - x=etree.tostring(xml), err=str(err)) + msg = u"Error in xml '{x}': {err} ".format( + x=etree.tostring(xml), err=err.message) raise Exception, msg, sys.exc_info()[2] @classmethod @@ -1746,7 +1746,7 @@ class ChoiceTextGroup(InputTypeBase): for choice in element: if choice.tag != 'choice': - msg = "[capa.inputtypes.extract_choices] {0}".format( + msg = u"[capa.inputtypes.extract_choices] {0}".format( # Translators: a "tag" is an XML element, such as "" in HTML _("Expected a {expected_tag} tag; got {given_tag} instead").format( expected_tag=u"", diff --git a/common/lib/capa/capa/templates/matlabinput.html b/common/lib/capa/capa/templates/matlabinput.html index 63187f214b..ce61e38808 100644 --- a/common/lib/capa/capa/templates/matlabinput.html +++ b/common/lib/capa/capa/templates/matlabinput.html @@ -39,7 +39,7 @@
${msg|n}
-
+
${queue_msg|n}
@@ -51,6 +51,7 @@ diff --git a/common/test/acceptance/pages/lms/matlab_problem.py b/common/test/acceptance/pages/lms/matlab_problem.py new file mode 100644 index 0000000000..c75b80fc57 --- /dev/null +++ b/common/test/acceptance/pages/lms/matlab_problem.py @@ -0,0 +1,43 @@ +""" +Matlab Problem Page. +""" +from bok_choy.page_object import PageObject + + +class MatlabProblemPage(PageObject): + """ + View of matlab problem page. + """ + + url = None + + def is_browser_on_page(self): + return self.q(css='.ungraded-matlab-result').present + + @property + def problem_name(self): + """ + Return the current problem name. + """ + return self.q(css='.problem-header').text[0] + + def set_response(self, response_str): + """ + Input a response to the prompt. + """ + input_css = "$('.CodeMirror')[0].CodeMirror.setValue('{}');".format(response_str) + self.browser.execute_script(input_css) + + def click_run_code(self): + """ + Click the run code button. + """ + self.q(css='input.save').click() + self.wait_for_ajax() + + def get_grader_msg(self, class_name): + """ + Returns the text value of given class. + """ + self.wait_for_ajax() + return self.q(css=class_name).text diff --git a/common/test/acceptance/tests/test_matlab_problem.py b/common/test/acceptance/tests/test_matlab_problem.py new file mode 100644 index 0000000000..d2e7e9d90a --- /dev/null +++ b/common/test/acceptance/tests/test_matlab_problem.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +""" +E2E tests for the LMS. +""" +import time + +from .helpers import UniqueCourseTest +from ..pages.studio.auto_auth import AutoAuthPage +from ..pages.lms.courseware import CoursewarePage +from ..pages.lms.matlab_problem import MatlabProblemPage +from ..fixtures.course import CourseFixture, XBlockFixtureDesc +from ..fixtures.xqueue import XQueueResponseFixture +from textwrap import dedent + + +class MatlabProblemTest(UniqueCourseTest): + """ + Tests that verify matlab problem "Run Code". + """ + USERNAME = "STAFF_TESTER" + EMAIL = "johndoe@example.com" + + def setUp(self): + super(MatlabProblemTest, self).setUp() + + self.XQUEUE_GRADE_RESPONSE = None + + self.courseware_page = CoursewarePage(self.browser, self.course_id) + + # Install a course with sections/problems, tabs, updates, and handouts + course_fix = CourseFixture( + self.course_info['org'], self.course_info['number'], + self.course_info['run'], self.course_info['display_name'] + ) + + problem_data = dedent(""" + + +

+ Write MATLAB code to create the following row vector and store it in a variable named V. +

+ + + + +
[1 1 2 3 5 8 13]
+

+ + + + + + + + + + + + + +

+
+
+ """) + + course_fix.add_children( + XBlockFixtureDesc('chapter', 'Test Section').add_children( + XBlockFixtureDesc('sequential', 'Test Subsection').add_children( + XBlockFixtureDesc('problem', 'Test Matlab Problem', data=problem_data) + ) + ) + ).install() + + # Auto-auth register for the course. + AutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL, + course_id=self.course_id, staff=False).visit() + + def _goto_matlab_problem_page(self): + """ + Open matlab problem page with assertion. + """ + self.courseware_page.visit() + matlab_problem_page = MatlabProblemPage(self.browser) + self.assertEqual(matlab_problem_page.problem_name, 'TEST MATLAB PROBLEM') + return matlab_problem_page + + def test_run_code(self): + """ + Test "Run Code" button functionality. + """ + + # Enter a submission, which will trigger a pre-defined response from the XQueue stub. + self.submission = "a=1" + self.unique_id[0:5] + + self.XQUEUE_GRADE_RESPONSE = {'msg': self.submission} + + matlab_problem_page = self._goto_matlab_problem_page() + + # Configure the XQueue stub's response for the text we will submit + if self.XQUEUE_GRADE_RESPONSE is not None: + XQueueResponseFixture(self.submission, self.XQUEUE_GRADE_RESPONSE).install() + + matlab_problem_page.set_response(self.submission) + matlab_problem_page.click_run_code() + + self.assertEqual( + u'Submitted. As soon as a response is returned, this message will be replaced by that feedback.', + matlab_problem_page.get_grader_msg(".external-grader-message")[0] + ) + + # Wait 5 seconds for xqueue stub server grader response sent back to lms. + time.sleep(5) + + self.assertEqual(u'', matlab_problem_page.get_grader_msg(".external-grader-message")[0]) + self.assertEqual( + self.XQUEUE_GRADE_RESPONSE.get("msg"), + matlab_problem_page.get_grader_msg(".ungraded-matlab-result")[0] + ) diff --git a/requirements/edx/github.txt b/requirements/edx/github.txt index 2a5424d6c0..aba6a1b234 100644 --- a/requirements/edx/github.txt +++ b/requirements/edx/github.txt @@ -27,5 +27,5 @@ -e git+https://github.com/edx-solutions/django-splash.git@9965a53c269666a30bb4e2b3f6037c138aef2a55#egg=django-splash -e git+https://github.com/edx/acid-block.git@459aff7b63db8f2c5decd1755706c1a64fb4ebb1#egg=acid-xblock -e git+https://github.com/edx/edx-ora2.git@release-2014-06-13T11.52#egg=edx-ora2 --e git+https://github.com/edx/opaque-keys.git@91b7ec93cfb57c6739332e85805296626b4fb1db#egg=opaque-keys +-e git+https://github.com/edx/opaque-keys.git@5929789900b3d0a354ce7274bde74edfd0430f03#egg=opaque-keys git+https://github.com/edx/ease.git@a990b25ed4238acb1b15ee6f027465db3a10960e#egg=ease