Exemplo n.º 1
0
 def test_lti20_request_handler_bad_user(self):
     """
     Test that we get a 404 when the supplied user does not exist
     """
     self.setup_system_xmodule_mocks_for_lti20_request_test()
     self.system._services['user'] = StubUserService(user=None)  # pylint: disable=protected-access
     mock_request = self.get_signed_lti20_mock_request(self.GOOD_JSON_PUT)
     response = self.xmodule.lti_2_0_result_rest_handler(
         mock_request, "user/abcd")
     assert response.status_code == 404
Exemplo n.º 2
0
    def _set_up_block(self, parent, index_in_parent):
        """
        Sets up the stub sequence module for testing.
        """
        block = parent.get_children()[index_in_parent]

        self._set_up_module_system(block)

        block.xmodule_runtime._services['bookmarks'] = Mock()  # pylint: disable=protected-access
        block.xmodule_runtime._services['user'] = StubUserService()  # pylint: disable=protected-access
        block.xmodule_runtime.xmodule_instance = getattr(block, '_xmodule', None)  # pylint: disable=protected-access
        block.parent = parent.location
        return block
Exemplo n.º 3
0
    def test_render_student_view(self, context):
        """
        Test the rendering of the student view.
        """
        self.module_system._services['bookmarks'] = Mock()  # pylint: disable=protected-access
        self.module_system._services['user'] = StubUserService()  # pylint: disable=protected-access

        html = self.module_system.render(
            self.vertical, STUDENT_VIEW,
            self.default_context if context is None else context).content
        self.assertIn(self.test_html_1, html)
        self.assertIn(self.test_html_2, html)
        self.assert_bookmark_info_in(html)
Exemplo n.º 4
0
    def _set_up_block(self, parent, index_in_parent):
        """
        Sets up the stub sequence module for testing.
        """
        block = parent.get_children()[index_in_parent]

        self._set_up_module_system(block)

        block.xmodule_runtime._services['bookmarks'] = Mock()  # pylint: disable=protected-access
        block.xmodule_runtime._services['completion'] = Mock(  # pylint: disable=protected-access
            return_value=Mock(vertical_is_complete=Mock(return_value=True)))
        block.xmodule_runtime._services['user'] = StubUserService()  # pylint: disable=protected-access
        block.parent = parent.location
        return block
Exemplo n.º 5
0
 def test_real_user_is_none(self):
     """
     If we have no real user, we should send back failure response.
     """
     self.system._services['user'] = StubUserService(user=None)  # pylint: disable=protected-access
     self.xmodule.verify_oauth_body_sign = Mock()
     self.xmodule.has_score = True
     request = Request(self.environ)
     request.body = self.get_request_body()
     response = self.xmodule.grade_handler(request, '')
     real_response = self.get_response_values(response)
     expected_response = {
         'action': None,
         'code_major': 'failure',
         'description': 'User not found.',
         'messageIdentifier': self.defaults['messageIdentifier'],
     }
     assert response.status_code == 200
     self.assertDictEqual(expected_response, real_response)
Exemplo n.º 6
0
def get_test_system(
    course_id=CourseKey.from_string('/'.join(['org', 'course', 'run'])),
    user=None,
    user_is_staff=False,
    user_location=None,
    render_template=None,
):
    """
    Construct a test ModuleSystem instance.

    By default, the descriptor system's render_template() method simply returns the repr of the
    context it is passed.  You can override this by passing in a different render_template argument.
    """
    if not user:
        user = Mock(name='get_test_system.user', is_staff=False)
    if not user_location:
        user_location = Mock(name='get_test_system.user_location')
    user_service = StubUserService(
        user=user,
        anonymous_user_id='student',
        user_is_staff=user_is_staff,
        user_role='student',
        request_country_code=user_location,
    )

    mako_service = StubMakoService(render_template=render_template)

    replace_url_service = StubReplaceURLService()

    descriptor_system = get_test_descriptor_system()

    def get_module(descriptor):
        """Mocks module_system get_module function"""

        # Unlike XBlock Runtimes or DescriptorSystems,
        # each XModule is provided with a new ModuleSystem.
        # Construct one for the new XModule.
        module_system = get_test_system()

        # Descriptors can all share a single DescriptorSystem.
        # So, bind to the same one as the current descriptor.
        module_system.descriptor_runtime = descriptor._runtime  # pylint: disable=protected-access

        descriptor.bind_for_student(module_system, user.id)

        return descriptor

    return TestModuleSystem(
        static_url='/static',
        track_function=Mock(name='get_test_system.track_function'),
        get_module=get_module,
        debug=True,
        hostname="edx.org",
        services={
            'user': user_service,
            'mako': mako_service,
            'xqueue': XQueueService(
                url='http://xqueue.url',
                django_auth={},
                basic_auth=[],
                default_queuename='testqueue',
                waittime=10,
                construct_callback=Mock(name='get_test_system.xqueue.construct_callback', side_effect="/"),
            ),
            'replace_urls': replace_url_service
        },
        node_path=os.environ.get("NODE_PATH", "/usr/local/lib/node_modules"),
        course_id=course_id,
        error_descriptor_class=ErrorBlock,
        descriptor_runtime=descriptor_system,
    )