Ejemplo n.º 1
0
 def test_student_view_with_score(self, fragment, render_template):
     # pylint: disable=unused-argument
     """
     Tests scores are displayed correctly on student view.
     """
     block = self.make_one()
     self.personalize(block, **self.make_student(
         block, 'fred', filename='foo.txt', score=10))
     fragment = block.student_view()
     render_template.assert_called_once()
     template_arg = render_template.call_args[0][0]
     self.assertEqual(
         template_arg,
         'templates/staff_graded_assignment/show.html'
     )
     context = render_template.call_args[0][1]
     self.assertEqual(context['is_course_staff'], True)
     self.assertEqual(context['id'], 'name')
     student_state = json.loads(context['student_state'])
     self.assertEqual(
         student_state['display_name'],
         "Staff Graded Assignment"
     )
     self.assertEqual(student_state['uploaded'], {u'filename': u'foo.txt'})
     self.assertEqual(student_state['annotated'], None)
     self.assertEqual(student_state['upload_allowed'], False)
     self.assertEqual(student_state['max_score'], 100)
     self.assertEqual(student_state['graded'],
                      {u'comment': '', u'score': 10})
     fragment.add_css.assert_called_once_with(
         DummyResource("static/css/edx_sga.css"))
     fragment.initialize_js.assert_called_once_with(
         "StaffGradedAssignmentXBlock")
Ejemplo n.º 2
0
 def test_student_view(self, fragment, render_template):
     # pylint: disable=unused-argument
     """
     Test student view renders correctly.
     """
     block = self.make_one("Custom name")
     self.personalize(block, **self.make_student(block, 'fred'))
     fragment = block.student_view()
     render_template.assert_called_once()
     template_arg = render_template.call_args[0][0]
     self.assertEqual(
         template_arg,
         'templates/staff_graded_assignment/show.html'
     )
     context = render_template.call_args[0][1]
     self.assertEqual(context['is_course_staff'], True)
     self.assertEqual(context['id'], 'name')
     self.assertEqual(context['support_email'], '*****@*****.**')
     student_state = json.loads(context['student_state'])
     self.assertEqual(
         student_state['display_name'],
         "Custom name"
     )
     self.assertEqual(student_state['uploaded'], None)
     self.assertEqual(student_state['annotated'], None)
     self.assertEqual(student_state['upload_allowed'], True)
     self.assertEqual(student_state['max_score'], 100)
     self.assertEqual(student_state['graded'], None)
     fragment.add_css.assert_called_once_with(
         DummyResource("static/css/edx_sga.css"))
     fragment.initialize_js.assert_called_once_with(
         "StaffGradedAssignmentXBlock")
Ejemplo n.º 3
0
    def test_student_view(self, fragment, render_template):
        # pylint: disable=unused-argument
        """
        Test student view renders correctly.
        """
        block = self.make_xblock("Custom name")

        with mock.patch(
                'edx_sga.sga.StaffGradedAssignmentXBlock.get_submission',
                return_value={}), mock.patch(
                    'edx_sga.sga.StaffGradedAssignmentXBlock.student_state',
                    return_value={
                        'uploaded': None,
                        'annotated': None,
                        'upload_allowed': True,
                        'max_score': 100,
                        'graded': None
                    }):
            fragment = block.student_view()
            assert render_template.called is True
            template_arg = render_template.call_args[0][0]
            assert template_arg == 'templates/staff_graded_assignment/show.html'
            context = render_template.call_args[0][1]
            assert context['is_course_staff'] is True
            assert context['id'] == 'name'
            student_state = json.loads(context['student_state'])
            assert student_state['uploaded'] is None
            assert student_state['annotated'] is None
            assert student_state['upload_allowed'] is True
            assert student_state['max_score'] == 100
            assert student_state['graded'] is None
            fragment.add_css.assert_called_once_with(
                DummyResource("static/css/edx_sga.css"))
            fragment.initialize_js.assert_called_once_with(
                "StaffGradedAssignmentXBlock")
Ejemplo n.º 4
0
    def test_student_view_with_score(self, fragment, render_template,
                                     get_score, upload_allowed):
        # pylint: disable=unused-argument
        """
        Tests scores are displayed correctly on student view.
        """
        block = self.make_xblock()
        get_score.return_value = 10
        upload_allowed.return_value = True
        block.comment = "ok"

        with self.dummy_upload('foo.txt') as (upload, _):
            with mock.patch(
                    'submissions.api.create_submission',
            ) as mocked_create_submission, mock.patch(
                    'edx_sga.sga.StaffGradedAssignmentXBlock.student_state',
                    return_value={}
            ), mock.patch(
                    'edx_sga.sga.StaffGradedAssignmentXBlock.get_or_create_student_module',
                    return_value=fake_student_module()):
                block.upload_assignment(
                    mock.Mock(params={'assignment': upload}))
            assert mocked_create_submission.called is True

            with mock.patch(
                    'edx_sga.sga.StaffGradedAssignmentXBlock.get_submission',
                    return_value=fake_upload_submission(upload)
            ), mock.patch(
                    'edx_sga.sga.StaffGradedAssignmentXBlock.student_state',
                    return_value={
                        'graded': {
                            'comment': 'ok',
                            'score': 10
                        },
                        'uploaded': {
                            'filename': 'foo.txt'
                        },
                        'max_score': 100
                    }):
                fragment = block.student_view()
                assert render_template.called is True
                template_arg = render_template.call_args[0][0]
                assert template_arg == 'templates/staff_graded_assignment/show.html'
                context = render_template.call_args[0][1]
                assert context['is_course_staff'] is True
                assert context['id'] == 'name'
                student_state = json.loads(context['student_state'])
                assert student_state['uploaded'] == {'filename': 'foo.txt'}
                assert student_state['graded'] == {
                    'comment': 'ok',
                    'score': 10
                }
                assert student_state['max_score'] == 100

                fragment.add_css.assert_called_once_with(
                    DummyResource("static/css/edx_sga.css"))
                fragment.initialize_js.assert_called_once_with(
                    "StaffGradedAssignmentXBlock")
 def test_studio_view(self, fragment, render_template):
     # pylint: disable=unused-argument
     """
     Test studio view is displayed correctly.
     """
     block = self.make_one()
     fragment = block.studio_view()
     render_template.assert_called_once()
     template_arg = render_template.call_args[0][0]
     self.assertEqual(template_arg,
                      'templates/staff_graded_assignment/edit.html')
     cls = type(block)
     context = render_template.call_args[0][1]
     self.assertEqual(
         tuple(context['fields']),
         ((cls.display_name, 'Staff Graded Assignment', 'string'),
          (cls.points, 100, 'number'), (cls.weight, '', 'number')))
     fragment.add_javascript.assert_called_once_with(
         DummyResource("static/js/src/studio.js"))
     fragment.initialize_js.assert_called_once_with(
         "StaffGradedAssignmentXBlock")