Newer
Older
__copyright__ = "Copyright (C) 2014 Andreas Kloeckner, Zesheng Wang, 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 collections import namedtuple
from course.constants import MAX_EXTRA_CREDIT_FACTOR
from course.page.base import (
AnswerFeedback, get_auto_feedback,
validate_point_count, InvalidFeedbackPointsError)
Andreas Klöckner
committed
SubprocessRunpyContainerMixin)
from tests.utils import mock
from tests import factories
MESSAGE_ANSWER_SAVED_TEXT = "Answer saved."
MESSAGE_ANSWER_FAILED_SAVE_TEXT = "Failed to submit answer."
FIXTURE_PATH = os.path.join(os.path.dirname(__file__), "..", 'fixtures')
def get_upload_file_path(file_name, fixture_path=FIXTURE_PATH):
return os.path.join(fixture_path, file_name)
TEST_TEXT_FILE_PATH = get_upload_file_path("test_file.txt")
TEST_PDF_FILE_PATH = get_upload_file_path("test_file.pdf")
TEST_HGTEXT_MARKDOWN_ANSWER = u"""
type: ChoiceQuestion
id: myquestion
shuffle: True
prompt: |
- "1"
- "2"
- ~CORRECT~ 1/4
- ~CORRECT~ $\\frac{1}{4}$
- 四分之三
"""
TEST_HGTEXT_MARKDOWN_ANSWER_WRONG = u"""
type: ChoiceQuestion
id: myquestion
shuffle: True
prompt: |
- "1"
- "2"
- 1/4
- $\\frac{1}{4}$
- 四分之三
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""
PageTuple = namedtuple(
'PageTuple', [
'page_id',
'group_id',
'need_human_grade',
'expecting_grade',
'need_runpy',
'correct_answer',
'grade_data',
'full_points',
]
)
TEST_AUDIO_OUTPUT_ANSWER = """
import numpy as np
t = np.linspace(0, 1, sample_rate, endpoint=False)
signal = np.sin(2*np.pi*t * 440)
output_audio(signal)
"""
TEST_PAGE_TUPLE = (
PageTuple("welcome", "intro", False, False, False, None, {}, None),
PageTuple("half", "quiz_start", False, True, False, {"answer": '0.5'}, {}, 5),
PageTuple("krylov", "quiz_start", False, True, False, {"choice": ['0']}, {}, 2),
PageTuple("ice_cream_toppings", "quiz_start", False, True, False,
{"choice": ['0', '1', '4']}, {}, 1),
PageTuple("matrix_props", "quiz_start", False, True, False,
{"choice": ['0', '3']}, {}, 1),
PageTuple("inlinemulti", "quiz_start", False, True, False,
{'blank1': 'Bar', 'blank_2': '0.2', 'blank3': '1',
'blank4': '5', 'blank5': 'Bar', 'choice2': '0',
'choice_a': '0'}, {}, 10),
PageTuple("fear", "quiz_start", True, False, False, {"answer": "NOTHING!!!"},
{}, 0),
PageTuple("age_group", "quiz_start", True, False, False, {"choice": 3}, {}, 0),
PageTuple("hgtext", "quiz_tail", True, True, False,
{"answer": TEST_HGTEXT_MARKDOWN_ANSWER},
{"grade_percent": "100", "released": "on"}, 5),
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
PageTuple("addition", "quiz_tail", False, True, True, {"answer": 'c = b + a\r'},
{"grade_percent": "100", "released": "on"}, 1),
PageTuple("pymult", "quiz_tail", True, True, True, {"answer": 'c = a * b\r'},
{"grade_percent": "100", "released": "on"}, None),
PageTuple("neumann", "quiz_tail", False, True, False, {"answer": "1/(1-A)"}, {},
5),
PageTuple("py_simple_list", "quiz_tail", True, True, True,
{"answer": 'b = [a] * 50\r'},
{"grade_percent": "100", "released": "on"}, 4),
# Skipped
# PageTuple("test_audio_output", "quiz_tail", True, True, True,
# {"answer": TEST_AUDIO_OUTPUT_ANSWER}, {}, 1),
PageTuple("quarter", "quiz_tail", False, True, False, {"answer": ['0.25']},
{}, 0),
PageTuple("anyup", "quiz_tail", True, False, False, TEST_TEXT_FILE_PATH,
{"grade_percent": "100", "released": "on"}, 5),
PageTuple("proof", "quiz_tail", True, False, False, TEST_PDF_FILE_PATH,
{"grade_percent": "100", "released": "on"}, 5),
PageTuple("eigvec", "quiz_tail", False, True, False, {"answer": 'matrix'}, {},
2),
PageTuple("lsq", "quiz_tail", False, True, False, {"choice": ['2']}, {}, 1),
)
class SingleCourseQuizPageTestMixin(SingleCoursePageTestMixin,
FallBackStorageMessageTestMixin):
flow_id = QUIZ_FLOW_ID
skip_code_question = True
@classmethod
def ensure_grading_ui_get(cls, page_id):
with cls.temporarily_switch_to_user(cls.instructor_participation.user):
url = cls.get_page_grading_url_by_page_id(page_id)
resp = cls.c.get(url)
assert resp.status_code == 200
@classmethod
def ensure_analytic_page_get(cls, group_id, page_id):
with cls.temporarily_switch_to_user(cls.instructor_participation.user):
resp = cls.get_flow_page_analytics(
flow_id=cls.flow_id, group_id=group_id,
page_id=page_id)
assert resp.status_code == 200
@classmethod
def ensure_download_submission(cls, group_id, page_id):
with cls.temporarily_switch_to_user(cls.instructor_participation.user):
group_page_id = "%s/%s" % (group_id, page_id)
resp = cls.post_download_all_submissions_by_group_page_id(
group_page_id=group_page_id, flow_id=cls.flow_id)
assert resp.status_code == 200
prefix, zip_file = resp["Content-Disposition"].split('=')
assert prefix == "attachment; filename"
assert resp.get('Content-Type') == "application/zip"
def submit_page_answer_by_ordinal_and_test(
cls, page_ordinal, use_correct_answer=True, answer_data=None,
skip_code_question=True,
expected_grade=None, expected_post_answer_status_code=200,
do_grading=False, do_human_grade=False, grade_data=None,
ensure_grading_ui_get_before_grading=False,
ensure_grading_ui_get_after_grading=False,
Loading
Loading full blame...