示例#1
0
    def test_request_context_caching(self):
        """
        Test that the RequestContext is cached in the RequestCache.
        """
        with patch(
                'common.djangoapps.edxmako.request_context.get_current_request',
                return_value=None):
            # requestcontext should be None, because the cache isn't filled
            assert get_template_request_context() is None

        with patch(
                'common.djangoapps.edxmako.request_context.get_current_request',
                return_value=self.request):
            # requestcontext should not be None, and should fill the cache
            assert get_template_request_context() is not None

        mock_get_current_request = Mock()
        with patch(
                'common.djangoapps.edxmako.request_context.get_current_request'
        ):
            with patch(
                    'common.djangoapps.edxmako.request_context.RequestContext.__init__'
            ) as mock_context_init:
                # requestcontext should not be None, because the cache is filled
                assert get_template_request_context() is not None
                mock_context_init.assert_not_called()
        mock_get_current_request.assert_not_called()

        RequestCache.clear_all_namespaces()

        with patch(
                'common.djangoapps.edxmako.request_context.get_current_request',
                return_value=None):
            # requestcontext should be None, because the cache isn't filled
            assert get_template_request_context() is None
示例#2
0
 def test_without_current_request(self):
     """
     Test that if get_current_request returns None, then get_template_request_context
     returns None.
     """
     with patch(
             'common.djangoapps.edxmako.request_context.get_current_request',
             return_value=None):
         # requestcontext should be None.
         assert get_template_request_context() is None
示例#3
0
    def test_with_current_request(self):
        """
        Test that if get_current_request returns a request, then get_template_request_context
        returns a RequestContext.
        """

        with patch(
                'common.djangoapps.edxmako.request_context.get_current_request',
                return_value=self.request):
            # requestcontext should not be None.
            assert get_template_request_context() is not None