def process_request(self, language_session_key=UNSET, accept=UNSET, preview_lang=UNSET, clear_lang=UNSET): """ Build a request and then process it using the ``DarkLangMiddleware``. Args: language_session_key (str): The language code to set in request.session[LANUGAGE_SESSION_KEY] accept (str): The accept header to set in request.META['HTTP_ACCEPT_LANGUAGE'] preview_lang (str): The value to set in request.GET['preview_lang'] clear_lang (str): The value to set in request.GET['clear_lang'] """ session = {} set_if_set(session, LANGUAGE_SESSION_KEY, language_session_key) meta = {} set_if_set(meta, 'HTTP_ACCEPT_LANGUAGE', accept) get = {} set_if_set(get, 'preview-lang', preview_lang) set_if_set(get, 'clear-lang', clear_lang) request = Mock(spec=HttpRequest, session=session, META=meta, GET=get, user=UserFactory()) self.assertIsNone(DarkLangMiddleware().process_request(request)) return request
def process_request(self, django_language=UNSET, accept=UNSET, preview_lang=UNSET, clear_lang=UNSET): """ Build a request and then process it using the ``DarkLangMiddleware``. Args: django_language (str): The language code to set in request.session['django_language'] accept (str): The accept header to set in request.META['HTTP_ACCEPT_LANGUAGE'] preview_lang (str): The value to set in request.GET['preview_lang'] clear_lang (str): The value to set in request.GET['clear_lang'] """ session = {} set_if_set(session, 'django_language', django_language) meta = {} set_if_set(meta, 'HTTP_ACCEPT_LANGUAGE', accept) get = {} set_if_set(get, 'preview-lang', preview_lang) set_if_set(get, 'clear-lang', clear_lang) request = Mock(spec=HttpRequest, session=session, META=meta, GET=get) self.assertIsNone(DarkLangMiddleware().process_request(request)) return request
def process_middleware_request(self, language_session_key=UNSET, accept=UNSET): """ Build a request and then process it using the ``DarkLangMiddleware``. Args: language_session_key (str): The language code to set in request.session[LANUGAGE_SESSION_KEY] accept (str): The accept header to set in request.META['HTTP_ACCEPT_LANGUAGE'] """ session = {} set_if_set(session, LANGUAGE_SESSION_KEY, language_session_key) meta = {} set_if_set(meta, 'HTTP_ACCEPT_LANGUAGE', accept) request = Mock( spec=HttpRequest, session=session, META=meta, GET={}, method='GET', user=self.user ) # Process it through the Middleware to ensure the language is available as expected. self.assertIsNone(DarkLangMiddleware().process_request(request)) return request