def test_reset_fail(self): """ Test the flow of the module if we complete the self assessment step and then reset Since the problem only allows one attempt, should fail. @return: """ assessment = [0, 1] # Simulate a student saving an answer self._handle_ajax("save_answer", {"student_answer": self.answer}) # Mock a student submitting an assessment assessment_dict = MultiDict({'assessment': sum(assessment)}) assessment_dict.extend(('score_list[]', val) for val in assessment) self._handle_ajax("save_assessment", assessment_dict) task_one_json = json.loads(self._module().task_states[0]) self.assertEqual(json.loads(task_one_json['child_history'][0]['post_assessment']), assessment) # Move to the next step in the problem self._handle_ajax("next_problem", {}) self.assertEqual(self._module().current_task_number, 0) html = self._module().render('student_view').content self.assertIsInstance(html, basestring) # Module should now be done rubric = self._handle_ajax("get_combined_rubric", {}) self.assertIsInstance(rubric, basestring) self.assertEqual(self._module().state, "done") # Try to reset, should fail because only 1 attempt is allowed reset_data = json.loads(self._handle_ajax("reset", {})) self.assertEqual(reset_data['success'], False)
def test_open_ended_flow_reset(self): """ Test the flow of the module if we complete the self assessment step and then reset @return: """ assessment = [0, 1] module = self.get_module_from_location(self.problem_location, COURSE) # Simulate a student saving an answer html = module.handle_ajax("get_html", {}) module.save() module.handle_ajax("save_answer", {"student_answer": self.answer}) module.save() html = module.handle_ajax("get_html", {}) module.save() # Mock a student submitting an assessment assessment_dict = MultiDict({'assessment': sum(assessment)}) assessment_dict.extend(('score_list[]', val) for val in assessment) module.handle_ajax("save_assessment", assessment_dict) module.save() task_one_json = json.loads(module.task_states[0]) self.assertEqual(json.loads(task_one_json['child_history'][0]['post_assessment']), assessment) rubric = module.handle_ajax("get_combined_rubric", {}) module.save() # Move to the next step in the problem module.handle_ajax("next_problem", {}) module.save() self.assertEqual(module.current_task_number, 0) html = module.render('student_view').content self.assertIsInstance(html, basestring) rubric = module.handle_ajax("get_combined_rubric", {}) module.save() self.assertIsInstance(rubric, basestring) self.assertEqual(module.state, "assessing") module.handle_ajax("reset", {}) module.save() self.assertEqual(module.current_task_number, 0)
def test_open_ended_flow_reset(self): """ Test the flow of the module if we complete the self assessment step and then reset @return: """ assessment = [0, 1] # Simulate a student saving an answer self._handle_ajax("get_html", {}) self._handle_ajax("save_answer", {"student_answer": self.answer}) self._handle_ajax("get_html", {}) # Mock a student submitting an assessment assessment_dict = MultiDict({'assessment': sum(assessment)}) assessment_dict.extend(('score_list[]', val) for val in assessment) self._handle_ajax("save_assessment", assessment_dict) task_one_json = json.loads(self._module().task_states[0]) self.assertEqual( json.loads(task_one_json['child_history'][0]['post_assessment']), assessment) self._handle_ajax("get_combined_rubric", {}) # Move to the next step in the problem self._handle_ajax("next_problem", {}) self.assertEqual(self._module().current_task_number, 0) html = self._module().render('student_view').content self.assertIsInstance(html, basestring) rubric = self._handle_ajax("get_combined_rubric", {}) self.assertIsInstance(rubric, basestring) self.assertEqual(self._module().state, "assessing") self._handle_ajax("reset", {}) self.assertEqual(self._module().current_task_number, 0)
def _build_query(self): """ Build query string parameters as a dictionary. """ query_dict = MultiDict({ "query": self.freetext_constraint, "type": self.search_type, "latest": self.latest, "facets": self.facets, "fields": self.fields, "replica": self.replica }) query_dict.extend(self.facet_constraints) # !TODO: encode datetime start, end = self.temporal_constraint query_dict.update(start=start, end=end) return query_dict
def _build_query(self, query_dict, limit=None, offset=None, shards=None): if shards is not None: if self._available_shards is None: self._load_available_shards() shard_specs = [] for shard in shards: if shard not in self._available_shards: raise EsgfSearchException('Shard %s is not available' % shard) else: for port, suffix in self._available_shards[shard]: # suffix should be ommited when querying if not port: port_string = "" else: port_string = ":%s" % port shard_specs.append('%s%s/solr' % (shard, port_string)) shard_str = ','.join(shard_specs) else: shard_str = None full_query = MultiDict({ 'format': RESPONSE_FORMAT, 'limit': limit, 'distrib': 'true' if self.distrib else 'false', 'offset': offset, 'shards': shard_str, }) full_query.extend(query_dict) # Remove all None valued items full_query = MultiDict(item for item in list(full_query.items()) if item[1] is not None) return full_query
def test_reset_fail(self): """ Test the flow of the module if we complete the self assessment step and then reset Since the problem only allows one attempt, should fail. @return: """ assessment = [0, 1] # Simulate a student saving an answer self._handle_ajax("save_answer", {"student_answer": self.answer}) # Mock a student submitting an assessment assessment_dict = MultiDict({'assessment': sum(assessment)}) assessment_dict.extend(('score_list[]', val) for val in assessment) self._handle_ajax("save_assessment", assessment_dict) task_one_json = json.loads(self._module().task_states[0]) self.assertEqual( json.loads(task_one_json['child_history'][0]['post_assessment']), assessment) # Move to the next step in the problem self._handle_ajax("next_problem", {}) self.assertEqual(self._module().current_task_number, 0) html = self._module().render('student_view').content self.assertIsInstance(html, basestring) # Module should now be done rubric = self._handle_ajax("get_combined_rubric", {}) self.assertIsInstance(rubric, basestring) self.assertEqual(self._module().state, "done") # Try to reset, should fail because only 1 attempt is allowed reset_data = json.loads(self._handle_ajax("reset", {})) self.assertEqual(reset_data['success'], False)
def update_request_params (request_params, update_dict = None): result_data = MultiDict(request_params) result_data.extend(update_dict or {}) return result_data
def test_open_ended_flow_correct(self): """ Test a two step problem where the student first goes through the self assessment step, and then the open ended step. @return: """ assessment = [1, 1] # Simulate a student saving an answer self._handle_ajax("save_answer", {"student_answer": self.answer}) status = self._handle_ajax("get_status", {}) self.assertIsInstance(status, basestring) # Mock a student submitting an assessment assessment_dict = MultiDict({'assessment': sum(assessment)}) assessment_dict.extend(('score_list[]', val) for val in assessment) self._handle_ajax("save_assessment", assessment_dict) task_one_json = json.loads(self._module().task_states[0]) self.assertEqual( json.loads(task_one_json['child_history'][0]['post_assessment']), assessment) # Move to the next step in the problem try: self._handle_ajax("next_problem", {}) except GradingServiceError: # This error is okay. We don't have a grading service to connect to! pass self.assertEqual(self._module().current_task_number, 1) try: self._module().render('student_view') except GradingServiceError: # This error is okay. We don't have a grading service to connect to! pass # Try to get the rubric from the module self._handle_ajax("get_combined_rubric", {}) # Make a fake reply from the queue queue_reply = { 'queuekey': "", 'xqueue_body': json.dumps({ 'score': 0, 'feedback': json.dumps({ "spelling": "Spelling: Ok.", "grammar": "Grammar: Ok.", "markup-text": " all of us can think of a book that we hope none of our children or any other children have taken off the shelf . but if i have the right to remove that book from the shelf that work i abhor then you also have exactly the same right and so does everyone else . and then we <bg>have no books left</bg> on the shelf for any of us . <bs>katherine</bs> <bs>paterson</bs> , author write a persuasive essay to a newspaper reflecting your vies on censorship <bg>in libraries . do</bg> you believe that certain materials , such as books , music , movies , magazines , <bg>etc . , should be</bg> removed from the shelves if they are found <bg>offensive ? support your</bg> position with convincing arguments from your own experience , observations <bg>, and or reading .</bg> " }), 'grader_type': "ML", 'success': True, 'grader_id': 1, 'submission_id': 1, 'rubric_xml': "<rubric><category><description>Writing Applications</description><score>0</score><option points='0'> The essay loses focus, has little information or supporting details, and the organization makes it difficult to follow.</option><option points='1'> The essay presents a mostly unified theme, includes sufficient information to convey the theme, and is generally organized well.</option></category><category><description> Language Conventions </description><score>0</score><option points='0'> The essay demonstrates a reasonable command of proper spelling and grammar. </option><option points='1'> The essay demonstrates superior command of proper spelling and grammar.</option></category></rubric>", 'rubric_scores_complete': True, }) } self._handle_ajax("check_for_score", {}) # Update the module with the fake queue reply self._handle_ajax("score_update", queue_reply) module = self._module() self.assertFalse(module.ready_to_reset) self.assertEqual(module.current_task_number, 1) # Get html and other data client will request module.render('student_view') self._handle_ajax("skip_post_assessment", {}) # Get all results self._handle_ajax("get_combined_rubric", {}) # reset the problem self._handle_ajax("reset", {}) self.assertEqual(self._module().state, "initial")
def test_open_ended_flow_correct(self): """ Test a two step problem where the student first goes through the self assessment step, and then the open ended step. @return: """ assessment = [1, 1] # Simulate a student saving an answer self._handle_ajax("save_answer", {"student_answer": self.answer}) status = self._handle_ajax("get_status", {}) self.assertIsInstance(status, basestring) # Mock a student submitting an assessment assessment_dict = MultiDict({'assessment': sum(assessment)}) assessment_dict.extend(('score_list[]', val) for val in assessment) self._handle_ajax("save_assessment", assessment_dict) task_one_json = json.loads(self._module().task_states[0]) self.assertEqual(json.loads(task_one_json['child_history'][0]['post_assessment']), assessment) # Move to the next step in the problem try: self._handle_ajax("next_problem", {}) except GradingServiceError: # This error is okay. We don't have a grading service to connect to! pass self.assertEqual(self._module().current_task_number, 1) try: self._module().render('student_view') except GradingServiceError: # This error is okay. We don't have a grading service to connect to! pass # Try to get the rubric from the module self._handle_ajax("get_combined_rubric", {}) # Make a fake reply from the queue queue_reply = { 'queuekey': "", 'xqueue_body': json.dumps({ 'score': 0, 'feedback': json.dumps({"spelling": "Spelling: Ok.", "grammar": "Grammar: Ok.", "markup-text": " all of us can think of a book that we hope none of our children or any other children have taken off the shelf . but if i have the right to remove that book from the shelf that work i abhor then you also have exactly the same right and so does everyone else . and then we <bg>have no books left</bg> on the shelf for any of us . <bs>katherine</bs> <bs>paterson</bs> , author write a persuasive essay to a newspaper reflecting your vies on censorship <bg>in libraries . do</bg> you believe that certain materials , such as books , music , movies , magazines , <bg>etc . , should be</bg> removed from the shelves if they are found <bg>offensive ? support your</bg> position with convincing arguments from your own experience , observations <bg>, and or reading .</bg> "}), 'grader_type': "ML", 'success': True, 'grader_id': 1, 'submission_id': 1, 'rubric_xml': "<rubric><category><description>Writing Applications</description><score>0</score><option points='0'> The essay loses focus, has little information or supporting details, and the organization makes it difficult to follow.</option><option points='1'> The essay presents a mostly unified theme, includes sufficient information to convey the theme, and is generally organized well.</option></category><category><description> Language Conventions </description><score>0</score><option points='0'> The essay demonstrates a reasonable command of proper spelling and grammar. </option><option points='1'> The essay demonstrates superior command of proper spelling and grammar.</option></category></rubric>", 'rubric_scores_complete': True, }) } self._handle_ajax("check_for_score", {}) # Update the module with the fake queue reply self._handle_ajax("score_update", queue_reply) module = self._module() self.assertFalse(module.ready_to_reset) self.assertEqual(module.current_task_number, 1) # Get html and other data client will request module.render('student_view') self._handle_ajax("skip_post_assessment", {}) # Get all results self._handle_ajax("get_combined_rubric", {}) # reset the problem self._handle_ajax("reset", {}) self.assertEqual(self._module().state, "initial")