Example #1
0
 def test_lessthan(self):
     """
     Tests that `<` in text context is handled properly
     """
     self.assertEqual(
         OpenEndedChild.sanitize_html(self.text_lessthan_noencd),
         self.text_lessthan_encode)
Example #2
0
 def test_combined(self):
     """
     tests a combination of inputs
     """
     test_input = u"{}\n{}\n{}\n\n{}{}\n{}".format(
         self.link_text, self.text, self.script_dirty, self.embed_dirty,
         self.text_lessthan_noencd, self.img_dirty)
     test_output = u"{}<br/>{}<br/>{}<br/><br/>{}{}<br/>{}".format(
         self.link_atag, self.text, self.script_clean, self.embed_clean,
         self.text_lessthan_encode, self.img_clean)
     self.assertEqual(OpenEndedChild.sanitize_html(test_input), test_output)
 def test_combined(self):
     """
     tests a combination of inputs
     """
     test_input = u"{}\n{}\n{}\n\n{}{}\n{}".format(self.link_text,
                                                   self.text,
                                                   self.script_dirty,
                                                   self.embed_dirty,
                                                   self.text_lessthan_noencd,
                                                   self.img_dirty)
     test_output = u"{}<br/>{}<br/>{}<br/><br/>{}{}<br/>{}".format(self.link_atag,
                                                                   self.text,
                                                                   self.script_clean,
                                                                   self.embed_clean,
                                                                   self.text_lessthan_encode,
                                                                   self.img_clean)
     self.assertEqual(OpenEndedChild.sanitize_html(test_input), test_output)
 def test_text(self):
     """
     Test for passing through text unchanged, including unicode
     """
     self.assertEqual(OpenEndedChild.sanitize_html(self.text), self.text)
 def test_iframe(self):
     """
     Basic test for passing through iframe, but stripping bad attr
     """
     self.assertEqual(OpenEndedChild.sanitize_html(self.iframe_dirty), self.iframe_clean)
 def test_embed(self):
     """
     Basic test for passing through embed, but stripping bad attr
     """
     self.assertEqual(OpenEndedChild.sanitize_html(self.embed_dirty), self.embed_clean)
 def test_script(self):
     """
     Basic test for stripping <script>
     """
     self.assertEqual(OpenEndedChild.sanitize_html(self.script_dirty), self.script_clean)
Example #8
0
 def test_script(self):
     """
     Basic test for stripping <script>
     """
     self.assertEqual(OpenEndedChild.sanitize_html(self.script_dirty),
                      self.script_clean)
class OpenEndedChildTest(unittest.TestCase):
    """
    Test the open ended child class
    """
    location = Location(["i4x", "edX", "sa_test", "selfassessment",
                         "SampleQuestion"])

    metadata = json.dumps({'attempts': '10'})
    prompt = etree.XML("<prompt>This is a question prompt</prompt>")
    rubric = '''<rubric><rubric>
        <category>
        <description>Response Quality</description>
        <option>The response is not a satisfactory answer to the question.  It either fails to address the question or does so in a limited way, with no evidence of higher-order thinking.</option>
        <option>Second option</option>
        </category>
         </rubric></rubric>'''
    max_score = 1

    static_data = {
        'max_attempts': 20,
        'prompt': prompt,
        'rubric': rubric,
        'max_score': max_score,
        'display_name': 'Name',
        'accept_file_upload': False,
        'close_date': None,
        's3_interface': "",
        'open_ended_grading_interface': {},
        'skip_basic_checks': False,
        'control': {
            'required_peer_grading': 1,
            'peer_grader_count': 1,
            'min_to_calibrate': 3,
            'max_to_calibrate': 6,
            'peer_grade_finished_submissions_when_none_pending': False,
        }
    }
    definition = Mock()
    descriptor = Mock()

    def setUp(self):
        self.test_system = get_test_system()
        self.test_system.open_ended_grading_interface = None
        self.openendedchild = OpenEndedChild(self.test_system, self.location,
                                             self.definition, self.descriptor, self.static_data, self.metadata)

    def test_latest_answer_empty(self):
        answer = self.openendedchild.latest_answer()
        self.assertEqual(answer, "")

    def test_latest_score_empty(self):
        answer = self.openendedchild.latest_score()
        self.assertEqual(answer, None)

    def test_latest_post_assessment_empty(self):
        answer = self.openendedchild.latest_post_assessment(self.test_system)
        self.assertEqual(answer, "")

    def test_new_history_entry(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)
        answer = self.openendedchild.latest_answer()
        self.assertEqual(answer, new_answer)

        new_answer = "Newer Answer"
        self.openendedchild.new_history_entry(new_answer)
        answer = self.openendedchild.latest_answer()
        self.assertEqual(new_answer, answer)

    def test_record_latest_score(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)
        new_score = 3
        self.openendedchild.record_latest_score(new_score)
        score = self.openendedchild.latest_score()
        self.assertEqual(score, 3)

        new_score = 4
        self.openendedchild.new_history_entry(new_answer)
        self.openendedchild.record_latest_score(new_score)
        score = self.openendedchild.latest_score()
        self.assertEqual(score, 4)

    def test_record_latest_post_assessment(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)

        post_assessment = "Post assessment"
        self.openendedchild.record_latest_post_assessment(post_assessment)
        self.assertEqual(post_assessment,
                         self.openendedchild.latest_post_assessment(self.test_system))

    def test_get_score(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)

        score = self.openendedchild.get_score()
        self.assertEqual(score['score'], 0)
        self.assertEqual(score['total'], self.static_data['max_score'])

        new_score = 4
        self.openendedchild.new_history_entry(new_answer)
        self.openendedchild.record_latest_score(new_score)
        score = self.openendedchild.get_score()
        self.assertEqual(score['score'], new_score)
        self.assertEqual(score['total'], self.static_data['max_score'])

    def test_reset(self):
        self.openendedchild.reset(self.test_system)
        state = json.loads(self.openendedchild.get_instance_state())
        self.assertEqual(state['child_state'], OpenEndedChild.INITIAL)

    def test_is_last_response_correct(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)
        self.openendedchild.record_latest_score(self.static_data['max_score'])
        self.assertEqual(self.openendedchild.is_last_response_correct(),
                         'correct')

        self.openendedchild.new_history_entry(new_answer)
        self.openendedchild.record_latest_score(0)
        self.assertEqual(self.openendedchild.is_last_response_correct(),
                         'incorrect')
 def test_linkify(self):
     """
     tests the replace_newlines function
     """
     self.assertEqual(OpenEndedChild.sanitize_html(self.link_text), self.link_atag)
Example #11
0
 def test_linkify(self):
     """
     tests the replace_newlines function
     """
     self.assertEqual(OpenEndedChild.sanitize_html(self.link_text),
                      self.link_atag)
Example #12
0
 def test_linebreaks(self):
     """
     tests the replace_newlines function
     """
     self.assertEqual(OpenEndedChild.replace_newlines(self.text_linebreaks),
                      self.text_brs)
Example #13
0
 def test_text(self):
     """
     Test for passing through text unchanged, including unicode
     """
     self.assertEqual(OpenEndedChild.sanitize_html(self.text), self.text)
Example #14
0
 def test_iframe(self):
     """
     Basic test for passing through iframe, but stripping bad attr
     """
     self.assertEqual(OpenEndedChild.sanitize_html(self.iframe_dirty),
                      self.iframe_clean)
Example #15
0
 def test_embed(self):
     """
     Basic test for passing through embed, but stripping bad attr
     """
     self.assertEqual(OpenEndedChild.sanitize_html(self.embed_dirty),
                      self.embed_clean)
 def test_lessthan(self):
     """
     Tests that `<` in text context is handled properly
     """
     self.assertEqual(OpenEndedChild.sanitize_html(self.text_lessthan_noencd), self.text_lessthan_encode)
 def test_linebreaks(self):
     """
     tests the replace_newlines function
     """
     self.assertEqual(OpenEndedChild.replace_newlines(self.text_linebreaks), self.text_brs)
Example #18
0
 def setUp(self):
     self.test_system = get_test_system()
     self.test_system.open_ended_grading_interface = None
     self.openendedchild = OpenEndedChild(self.test_system, self.location,
                                          self.definition, self.descriptor,
                                          self.static_data, self.metadata)
class OpenEndedChildTest(unittest.TestCase):
    """
    Test the open ended child class
    """
    location = Location(["i4x", "edX", "sa_test", "selfassessment",
                         "SampleQuestion"])

    metadata = json.dumps({'attempts': '10'})
    prompt = etree.XML("<prompt>This is a question prompt</prompt>")
    rubric = '''<rubric><rubric>
        <category>
        <description>Response Quality</description>
        <option>The response is not a satisfactory answer to the question.  It either fails to address the question or does so in a limited way, with no evidence of higher-order thinking.</option>
        <option>Second option</option>
        </category>
         </rubric></rubric>'''
    max_score = 1

    static_data = {
        'max_attempts': 20,
        'prompt': prompt,
        'rubric': rubric,
        'max_score': max_score,
        'display_name': 'Name',
        'accept_file_upload': False,
        'close_date': None,
        's3_interface': "",
        'open_ended_grading_interface': {},
        'skip_basic_checks': False,
    }
    definition = Mock()
    descriptor = Mock()

    def setUp(self):
        self.test_system = get_test_system()
        self.openendedchild = OpenEndedChild(self.test_system, self.location,
                                             self.definition, self.descriptor, self.static_data, self.metadata)

    def test_latest_answer_empty(self):
        answer = self.openendedchild.latest_answer()
        self.assertEqual(answer, "")

    def test_latest_score_empty(self):
        answer = self.openendedchild.latest_score()
        self.assertEqual(answer, None)

    def test_latest_post_assessment_empty(self):
        answer = self.openendedchild.latest_post_assessment(self.test_system)
        self.assertEqual(answer, "")

    def test_new_history_entry(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)
        answer = self.openendedchild.latest_answer()
        self.assertEqual(answer, new_answer)

        new_answer = "Newer Answer"
        self.openendedchild.new_history_entry(new_answer)
        answer = self.openendedchild.latest_answer()
        self.assertEqual(new_answer, answer)

    def test_record_latest_score(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)
        new_score = 3
        self.openendedchild.record_latest_score(new_score)
        score = self.openendedchild.latest_score()
        self.assertEqual(score, 3)

        new_score = 4
        self.openendedchild.new_history_entry(new_answer)
        self.openendedchild.record_latest_score(new_score)
        score = self.openendedchild.latest_score()
        self.assertEqual(score, 4)

    def test_record_latest_post_assessment(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)

        post_assessment = "Post assessment"
        self.openendedchild.record_latest_post_assessment(post_assessment)
        self.assertEqual(post_assessment,
                         self.openendedchild.latest_post_assessment(self.test_system))

    def test_get_score(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)

        score = self.openendedchild.get_score()
        self.assertEqual(score['score'], 0)
        self.assertEqual(score['total'], self.static_data['max_score'])

        new_score = 4
        self.openendedchild.new_history_entry(new_answer)
        self.openendedchild.record_latest_score(new_score)
        score = self.openendedchild.get_score()
        self.assertEqual(score['score'], new_score)
        self.assertEqual(score['total'], self.static_data['max_score'])

    def test_reset(self):
        self.openendedchild.reset(self.test_system)
        state = json.loads(self.openendedchild.get_instance_state())
        self.assertEqual(state['child_state'], OpenEndedChild.INITIAL)

    def test_is_last_response_correct(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)
        self.openendedchild.record_latest_score(self.static_data['max_score'])
        self.assertEqual(self.openendedchild.is_last_response_correct(),
                         'correct')

        self.openendedchild.new_history_entry(new_answer)
        self.openendedchild.record_latest_score(0)
        self.assertEqual(self.openendedchild.is_last_response_correct(),
                         'incorrect')
 def setUp(self):
     self.test_system = get_test_system()
     self.openendedchild = OpenEndedChild(self.test_system, self.location,
                                          self.definition, self.descriptor, self.static_data, self.metadata)
 def setUp(self):
     self.test_system = get_test_system()
     self.test_system.open_ended_grading_interface = None
     self.openendedchild = OpenEndedChild(self.test_system, self.location,
                                          self.definition, self.descriptor, self.static_data, self.metadata)
class OpenEndedChildTest(unittest.TestCase):
    """
    Test the open ended child class
    """

    location = Location(["i4x", "edX", "sa_test", "selfassessment", "SampleQuestion"])

    metadata = json.dumps({"attempts": "10"})
    prompt = etree.XML("<prompt>This is a question prompt</prompt>")
    rubric = """<rubric><rubric>
        <category>
        <description>Response Quality</description>
        <option>The response is not a satisfactory answer to the question.  It either fails to address the question or does so in a limited way, with no evidence of higher-order thinking.</option>
        <option>Second option</option>
        </category>
         </rubric></rubric>"""
    max_score = 1

    static_data = {
        "max_attempts": 20,
        "prompt": prompt,
        "rubric": rubric,
        "max_score": max_score,
        "display_name": "Name",
        "accept_file_upload": False,
        "close_date": None,
        "s3_interface": "",
        "open_ended_grading_interface": {},
        "skip_basic_checks": False,
        "control": {
            "required_peer_grading": 1,
            "peer_grader_count": 1,
            "min_to_calibrate": 3,
            "max_to_calibrate": 6,
            "peer_grade_finished_submissions_when_none_pending": False,
        },
    }
    definition = Mock()
    descriptor = Mock()

    def setUp(self):
        self.test_system = get_test_system()
        self.test_system.open_ended_grading_interface = None
        self.openendedchild = OpenEndedChild(
            self.test_system, self.location, self.definition, self.descriptor, self.static_data, self.metadata
        )

    def test_latest_answer_empty(self):
        answer = self.openendedchild.latest_answer()
        self.assertEqual(answer, "")

    def test_latest_score_empty(self):
        answer = self.openendedchild.latest_score()
        self.assertEqual(answer, None)

    def test_latest_post_assessment_empty(self):
        answer = self.openendedchild.latest_post_assessment(self.test_system)
        self.assertEqual(answer, "")

    def test_new_history_entry(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)
        answer = self.openendedchild.latest_answer()
        self.assertEqual(answer, new_answer)

        new_answer = "Newer Answer"
        self.openendedchild.new_history_entry(new_answer)
        answer = self.openendedchild.latest_answer()
        self.assertEqual(new_answer, answer)

    def test_record_latest_score(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)
        new_score = 3
        self.openendedchild.record_latest_score(new_score)
        score = self.openendedchild.latest_score()
        self.assertEqual(score, 3)

        new_score = 4
        self.openendedchild.new_history_entry(new_answer)
        self.openendedchild.record_latest_score(new_score)
        score = self.openendedchild.latest_score()
        self.assertEqual(score, 4)

    def test_record_latest_post_assessment(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)

        post_assessment = "Post assessment"
        self.openendedchild.record_latest_post_assessment(post_assessment)
        self.assertEqual(post_assessment, self.openendedchild.latest_post_assessment(self.test_system))

    def test_get_score(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)

        score = self.openendedchild.get_score()
        self.assertEqual(score["score"], 0)
        self.assertEqual(score["total"], self.static_data["max_score"])

        new_score = 4
        self.openendedchild.new_history_entry(new_answer)
        self.openendedchild.record_latest_score(new_score)
        score = self.openendedchild.get_score()
        self.assertEqual(score["score"], new_score)
        self.assertEqual(score["total"], self.static_data["max_score"])

    def test_reset(self):
        self.openendedchild.reset(self.test_system)
        state = json.loads(self.openendedchild.get_instance_state())
        self.assertEqual(state["child_state"], OpenEndedChild.INITIAL)

    def test_is_last_response_correct(self):
        new_answer = "New Answer"
        self.openendedchild.new_history_entry(new_answer)
        self.openendedchild.record_latest_score(self.static_data["max_score"])
        self.assertEqual(self.openendedchild.is_last_response_correct(), "correct")

        self.openendedchild.new_history_entry(new_answer)
        self.openendedchild.record_latest_score(0)
        self.assertEqual(self.openendedchild.is_last_response_correct(), "incorrect")