test_lms_matlab_problem.py 3.39 KB
Newer Older
1 2
# -*- coding: utf-8 -*-
"""
3
Test for matlab problems
4 5 6
"""
import time

7
from ...pages.lms.matlab_problem import MatlabProblemPage
8
from ...fixtures.course import XBlockFixtureDesc
9
from ...fixtures.xqueue import XQueueResponseFixture
10
from .test_lms_problems import ProblemsTest
11 12 13
from textwrap import dedent


14
class MatlabProblemTest(ProblemsTest):
15 16 17
    """
    Tests that verify matlab problem "Run Code".
    """
18 19 20 21
    def get_problem(self):
        """
        Create a matlab problem for the test.
        """
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
        problem_data = dedent("""
            <problem markdown="null">
                  <text>
                    <p>
                        Write MATLAB code to create the following row vector and store it in a variable named <code>V</code>.
                    </p>
                    <table id="a0000000466" class="equation" width="100%" cellspacing="0" cellpadding="7" style="table-layout:auto">
                      <tr>
                        <td class="equation">[1 1 2 3 5 8 13]</td>
                      </tr>
                    </table>
                    <p>
                      <coderesponse queuename="matlab">
                        <matlabinput rows="10" cols="40" mode="" tabsize="4">
                            <plot_payload>
                            </plot_payload>
                        </matlabinput>
                        <codeparam>
                          <initial_display/>
                            <answer_display>
                            </answer_display>
                            <grader_payload>
                            </grader_payload>
                        </codeparam>
                      </coderesponse>
                    </p>
                  </text>
            </problem>
        """)
51
        return XBlockFixtureDesc('problem', 'Test Matlab Problem', data=problem_data)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

    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]

70
        self.xqueue_grade_response = {'msg': self.submission}
71 72 73 74

        matlab_problem_page = self._goto_matlab_problem_page()

        # Configure the XQueue stub's response for the text we will submit
75 76
        if self.xqueue_grade_response is not None:
            XQueueResponseFixture(self.submission, self.xqueue_grade_response).install()
77 78 79 80 81 82 83 84 85 86 87 88 89 90

        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(
91
            self.xqueue_grade_response.get("msg"),
92 93
            matlab_problem_page.get_grader_msg(".ungraded-matlab-result")[0]
        )