Newer
Older
__copyright__ = "Copyright (C) 2018 Dong Zhuang"
__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
from django.test import TestCase, override_settings, RequestFactory, Client
from docker.errors import APIError as DockerAPIError
from socket import error as socket_error, timeout as sock_timeout
import errno
from course.models import FlowSession
CODE_QUESTION_CONTAINER_PORT, request_run_with_retries, InvalidPingResponse,
is_nuisance_failure, PythonCodeQuestionWithHumanTextFeedback)
from course.utils import FlowPageContext, CoursePageContext
from course.constants import MAX_EXTRA_CREDIT_FACTOR
from tests.constants import MESSAGE_ANSWER_SAVED_TEXT, PAGE_ERRORS
SubprocessRunpyContainerMixin, SingleCoursePageTestMixin,
SingleCourseQuizPageTestMixin, MockAddMessageMixing)
)
from tests.utils import LocmemBackendTestsMixin, mock, mail
from . import markdowns
NO_CORRECTNESS_INFO_MSG = "No information on correctness of answer."
NOT_ALLOW_MULTIPLE_SUBMISSION_WARNING = (
"code question does not explicitly "
"allow multiple submission. Either add "
"access_rules/add_permssions/change_answer "
"or add 'single_submission: True' to confirm that you intend "
"for only a single submission to be allowed. "
"While you're at it, consider adding "
"access_rules/add_permssions/see_correctness."
)
MAX_AUTO_FEEDBACK_POINTS_VALICATION_ERROR_MSG_PATTERN = ( # noqa
"'max_auto_feedback_points' is invalid: expecting "
"a value within [0, %(max_extra_credit_factor)s], "
"got %(invalid_value)s."
)
GRADE_CODE_FAILING_MSG = (
"The grading code failed. Sorry about that."
)
RUNCODE_WITH_RETRIES_PATH = "course.page.code.request_run_with_retries"
AUTO_FEEDBACK_POINTS_OUT_OF_RANGE_ERROR_MSG_PATTERN = (
"'correctness' is invalid: expecting "
"a value within [0, %s] or None, "
"got %s."
)
class SingleCourseQuizPageCodeQuestionTest(
SingleCourseQuizPageTestMixin, MockAddMessageMixing,
SubprocessRunpyContainerMixin, TestCase):
@classmethod
def setUpTestData(cls): # noqa
client = Client()
client.force_login(cls.student_participation.user)
cls.start_flow(client, cls.flow_id)
def test_code_page_correct(self):
page_id = "addition"
submit_answer_response, post_grade_response = (
self.default_submit_page_answer_by_page_id_and_test(page_id))
self.assertAddMessageCalledWith(MESSAGE_ANSWER_SAVED_TEXT)
def test_code_page_wrong(self):
page_id = "addition"
submit_answer_response, post_grade_response = (
self.default_submit_page_answer_by_page_id_and_test(
page_id, answer_data={"answer": 'c = a - b\r'},
expected_grade=0))
self.assertAddMessageCalledWith(MESSAGE_ANSWER_SAVED_TEXT)
def test_code_page_identical_to_reference(self):
page_id = "addition"
submit_answer_response, post_grade_response = (
self.default_submit_page_answer_by_page_id_and_test(
page_id, answer_data={"answer": 'c = a + b\r'},
expected_grade=1))
self.assertAddMessageCalledWith(MESSAGE_ANSWER_SAVED_TEXT)
self.assertResponseContextAnswerFeedbackContainsFeedback(
submit_answer_response,
("It looks like you submitted code "
"that is identical to the reference "
"solution. This is not allowed."))
def test_code_human_feedback_page_submit(self):
page_id = "pymult"
submit_answer_response, post_grade_response = (
self.default_submit_page_answer_by_page_id_and_test(page_id))
self.assertAddMessageCalledWith(MESSAGE_ANSWER_SAVED_TEXT)
def test_code_human_feedback_page_grade1(self):
page_id = "pymult"
submit_answer_response, post_grade_response = (
self.default_submit_page_answer_by_page_id_and_test(
page_id, answer_data={"answer": 'c = b * a\r'},
self.assertResponseContextAnswerFeedbackContainsFeedback(
post_grade_response, "The human grader assigned 2/2 points.")
def test_code_human_feedback_page_grade2(self):
page_id = "pymult"
feedback_text = "This is the feedback from instructor."
submit_answer_response, post_grade_response = (
self.default_submit_page_answer_by_page_id_and_test(
page_id, answer_data={"answer": 'c = a / b\r'},
grade_data_extra_kwargs={"feedback_text": feedback_text},
expected_grade=2))
self.assertResponseContextAnswerFeedbackContainsFeedback(
self.assertResponseContextAnswerFeedbackContainsFeedback(
submit_answer_response, "The autograder assigned 0/2 points.")
self.assertResponseContextAnswerFeedbackContainsFeedback(
post_grade_response, "The human grader assigned 2/2 points.")
self.assertResponseContextAnswerFeedbackContainsFeedback(
post_grade_response, "The human grader assigned 2/2 points.")
def test_code_human_feedback_page_grade3(self):
page_id = "py_simple_list"
submit_answer_response, post_grade_response = (
self.default_submit_page_answer_by_page_id_and_test(
page_id, answer_data={"answer": 'b = [a + 1] * 50\r'},
do_grading=False))
# this is testing feedback.finish(0.3, feedback_msg)
# 2 * 0.3 = 0.6
self.assertResponseContextAnswerFeedbackContainsFeedback(
submit_answer_response, "The autograder assigned 0.90/3 points.")
self.assertResponseContextAnswerFeedbackContainsFeedback(
submit_answer_response, "The elements in b have wrong values")
def test_code_human_feedback_page_grade4(self):
page_id = "py_simple_list"
submit_answer_response, post_grade_response = (
self.default_submit_page_answer_by_page_id_and_test(page_id))
self.assertResponseContextAnswerFeedbackContainsFeedback(
self.assertResponseContextAnswerFeedbackContainsFeedback(
post_grade_response, "The human grader assigned 1/1 points.")
resp = self.submit_page_human_grading_by_page_id_and_test(
page_id, grade_data=grade_data, expected_grades=None)
self.assertFormErrorLoose(resp, None)
# not released
feedback_text = "This is the feedback from instructor."
grade_data = {
Loading
Loading full blame...