Esempio n. 1
0
class HelpURLMiddlewareTests(TestCase):
    def setUp(self):
        self.middleware = HelpURLMiddleware()

    def assertHelpURLEqual(self, page_token, expected_url):
        request = http.HttpRequest()

        context = {}
        if page_token is not None:
            context[HELP_CONTEXT_TOKEN_NAME] = page_token

        response = TemplateResponse(request, None, context)

        response = self.middleware.process_template_response(request, response)
        self.assertEqual(response.context_data['help_url'], expected_url)

    def test_process_template_response(self):
        # If the context has no page_token set, help_url should be set to the default docs page.
        self.assertHelpURLEqual(None, DOC_INDEX)

        # If the context has an invalid page_token set, help_url should be set to the default docs page.
        self.assertHelpURLEqual('Not a real token', DOC_INDEX)

        # If the context has a valid page_token set, help_url should be set to the corresponding docs page.
        self.assertHelpURLEqual('course_enrollment_activity', DOC_ENROLLMENT_ACTIVITY)

    def test_process_template_response_with_error(self):
        """
        The middleware should NOT process error responses.
        """
        response = http.HttpResponseServerError()
        request = http.HttpRequest()
        response = self.middleware.process_template_response(request, response)
        self.assertFalse(hasattr(response, 'context_data'))
class HelpURLMiddlewareTests(TestCase):
    def setUp(self):
        self.middleware = HelpURLMiddleware()

    def assertHelpURLEqual(self, page_token, expected_url):
        request = http.HttpRequest()

        context = {}
        if page_token is not None:
            context[HELP_CONTEXT_TOKEN_NAME] = page_token

        response = TemplateResponse(request, None, context)

        response = self.middleware.process_template_response(request, response)
        self.assertEqual(response.context_data['help_url'], expected_url)

    def test_process_template_response(self):
        # If the context has no page_token set, help_url should be set to the default docs page.
        self.assertHelpURLEqual(None, DOC_INDEX)

        # If the context has an invalid page_token set, help_url should be set to the default docs page.
        self.assertHelpURLEqual('Not a real token', DOC_INDEX)

        # If the context has a valid page_token set, help_url should be set to the corresponding docs page.
        self.assertHelpURLEqual('enrollment_activity', DOC_ENROLLMENT_ACTIVITY)

    def test_process_template_response_with_error(self):
        """
        The middleware should NOT process error responses.
        """
        response = http.HttpResponseServerError()
        request = http.HttpRequest()
        response = self.middleware.process_template_response(request, response)
        self.assertFalse(hasattr(response, 'context_data'))
Esempio n. 3
0
 def setUp(self):
     self.middleware = HelpURLMiddleware()
 def setUp(self):
     self.middleware = HelpURLMiddleware()