def get_request(self, path=None, language=settings.LANGUAGES[0][0]): if not path: path = self.get_pages_root() parsed_path = urlparse(path) host = parsed_path.netloc or 'testserver' port = 80 if ':' in host: host, port = host.split(':', 1) environ = { 'HTTP_COOKIE': self.client.cookies, 'PATH_INFO': parsed_path.path, 'QUERY_STRING': parsed_path.query, 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_METHOD': 'GET', 'SCRIPT_NAME': '', 'SERVER_NAME': host, 'SERVER_PORT': port, 'SERVER_PROTOCOL': 'HTTP/1.1', 'wsgi.version': (1, 0), 'wsgi.url_scheme': 'http', 'wsgi.errors': self.client.errors, 'wsgi.multiprocess': True, 'wsgi.multithread': False, 'wsgi.run_once': False, 'wsgi.input': '' } request = WSGIRequest(environ) request.session = self.client.session request.user = getattr(self, 'user', AnonymousUser()) request.LANGUAGE_CODE = language return request
def get_request(self, path=None, language=settings.LANGUAGES[0][0]): if not path: path = self.get_pages_root() parsed_path = urlparse(path) host = parsed_path.netloc or 'testserver' port = 80 if ':' in host: host, port = host.split(':', 1) environ = { 'HTTP_COOKIE': self.client.cookies, 'PATH_INFO': parsed_path.path, 'QUERY_STRING': parsed_path.query, 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_METHOD': 'GET', 'SCRIPT_NAME': '', 'SERVER_NAME': host, 'SERVER_PORT': port, 'SERVER_PROTOCOL': 'HTTP/1.1', 'wsgi.version': (1, 0), 'wsgi.url_scheme': 'http', 'wsgi.errors': self.client.errors, 'wsgi.multiprocess': True, 'wsgi.multithread': False, 'wsgi.run_once': False, } request = WSGIRequest(environ) request.session = self.client.session request.user = getattr(self, 'user', AnonymousUser()) request.LANGUAGE_CODE = language return request
def get_request(self, path=None): if not path: path = '/' environ = { 'HTTP_COOKIE': self.client.cookies, 'PATH_INFO': path, 'QUERY_STRING': '', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_METHOD': 'GET', 'SCRIPT_NAME': '', 'SERVER_NAME': 'testserver', 'SERVER_PORT': '80', 'SERVER_PROTOCOL': 'HTTP/1.1', 'wsgi.version': (1,0), 'wsgi.url_scheme': 'http', 'wsgi.errors': self.client.errors, 'wsgi.multiprocess': True, 'wsgi.multithread': False, 'wsgi.run_once': False, } request = WSGIRequest(environ) request.session = self.client.session request.LANGUAGE_CODE = settings.LANGUAGE_CODE return request
def get_request(self, path=None, language=None, post_data=None, enforce_csrf_checks=False): if not path: path = self.get_pages_root() if not language: language = settings.LANGUAGES[0][0] parsed_path = urlparse(path) host = parsed_path.netloc or "testserver" port = 80 if ":" in host: host, port = host.split(":", 1) environ = { "HTTP_COOKIE": self.client.cookies, "PATH_INFO": parsed_path.path, "QUERY_STRING": parsed_path.query, "REMOTE_ADDR": "127.0.0.1", "REQUEST_METHOD": "GET", "SCRIPT_NAME": "", "SERVER_NAME": host, "SERVER_PORT": port, "SERVER_PROTOCOL": "HTTP/1.1", "wsgi.version": (1, 0), "wsgi.url_scheme": "http", "wsgi.errors": self.client.errors, "wsgi.multiprocess": True, "wsgi.multithread": False, "wsgi.run_once": False, "wsgi.input": "", } if post_data: post_data = encode_multipart(BOUNDARY, post_data) environ.update( { "CONTENT_LENGTH": len(post_data), "CONTENT_TYPE": MULTIPART_CONTENT, "REQUEST_METHOD": "POST", "wsgi.input": FakePayload(post_data), } ) request = WSGIRequest(environ) request.session = self.client.session request.user = getattr(self, "user", AnonymousUser()) request.LANGUAGE_CODE = language if not enforce_csrf_checks: request.csrf_processing_done = True return request
def get_request(self, path=None, language=None, post_data=None): if not path: path = self.get_pages_root() if not language: language = settings.LANGUAGES[0][0] parsed_path = urlparse(path) host = parsed_path.netloc or 'testserver' port = 80 if ':' in host: host, port = host.split(':', 1) environ = { 'HTTP_COOKIE': self.client.cookies, 'PATH_INFO': parsed_path.path, 'QUERY_STRING': parsed_path.query, 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_METHOD': 'GET', 'SCRIPT_NAME': '', 'SERVER_NAME': host, 'SERVER_PORT': port, 'SERVER_PROTOCOL': 'HTTP/1.1', 'wsgi.version': (1,0), 'wsgi.url_scheme': 'http', 'wsgi.errors': self.client.errors, 'wsgi.multiprocess': True, 'wsgi.multithread': False, 'wsgi.run_once': False, 'wsgi.input': '' } if post_data: post_data = encode_multipart(BOUNDARY, post_data) environ.update({ 'CONTENT_LENGTH': len(post_data), 'CONTENT_TYPE': MULTIPART_CONTENT, 'REQUEST_METHOD': 'POST', 'wsgi.input': FakePayload(post_data), }) request = WSGIRequest(environ) request.session = self.client.session request.user = getattr(self, 'user', AnonymousUser()) request.LANGUAGE_CODE = language return request
def expire_view_cache(path, meta, key_prefix=None): """ This function allows you to invalidate any item from the per-view cache. It probably won't work with things cached using the per-site cache middleware (because that takes account of the Vary: Cookie header). This assumes you're using the Sites framework. Arguments: * path: The URL of the view to invalidate, like `/blog/posts/1234/`. * meta: Meta details of the request * key_prefix: The same as that used for the cache_page() function/decorator (if any). """ from django.conf import settings from django.core.cache import cache from django.utils.cache import get_cache_key from django.core.handlers.wsgi import WSGIRequest # Create a fake request object request = WSGIRequest(meta) request.method = 'GET' request.path = path if 'admin' in path: request.META['QUERY_STRING'] = '' if settings.USE_I18N: request.LANGUAGE_CODE = settings.LANGUAGE_CODE # If this key is in the cache, delete it: try: cache_key = get_cache_key(request, key_prefix=key_prefix) if cache_key: if cache_key in cache: cache.delete(cache_key) return (True, 'Successfully invalidated') else: return (False, 'Cache_key does not exist in cache') else: raise ValueError('Failed to create cache_key') except (ValueError, Exception) as e: return (False, e)
def get_request(self, path="/"): environ = { 'HTTP_COOKIE': self.client.cookies, 'PATH_INFO': path, 'QUERY_STRING': '', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_METHOD': 'GET', 'SCRIPT_NAME': '', 'SERVER_NAME': 'testserver', 'SERVER_PORT': '80', 'SERVER_PROTOCOL': 'HTTP/1.1', 'wsgi.version': (1,0), 'wsgi.url_scheme': 'http', 'wsgi.errors': self.client.errors, 'wsgi.multiprocess': True, 'wsgi.multithread': False, 'wsgi.run_once': False, } request = WSGIRequest(environ) request.session = self.client.session request.user = self.user request.LANGUAGE_CODE = settings.LANGUAGES[0][0] return request