|
2 | 2 | from cms.models import Page
|
3 | 3 | from cms.test_utils.util.context_managers import (UserLoginContext,
|
4 | 4 | SettingsOverride, _AssertNumQueriesContext)
|
| 5 | +from cms.test_utils.util.request_factory import RequestFactory |
5 | 6 | from django.conf import settings
|
6 |
| -from django.db.utils import DEFAULT_DB_ALIAS |
7 |
| -from django.db import connections |
8 |
| - |
9 | 7 | from django.contrib.auth.models import User, AnonymousUser
|
10 | 8 | from django.core.exceptions import ObjectDoesNotExist
|
11 |
| -from django.core.handlers.wsgi import WSGIRequest |
12 | 9 | from django.core.urlresolvers import reverse
|
| 10 | +from django.db import connections |
| 11 | +from django.db.utils import DEFAULT_DB_ALIAS |
13 | 12 | from django.template.context import Context
|
14 |
| -from django.test.client import (encode_multipart, BOUNDARY, MULTIPART_CONTENT, |
15 |
| - FakePayload) |
16 | 13 | from django.test import testcases
|
| 14 | +from django.test.client import Client |
17 | 15 | from menus.menu_pool import menu_pool
|
18 |
| -from urlparse import urlparse |
19 | 16 | import sys
|
20 | 17 | import urllib
|
21 | 18 | import warnings
|
22 | 19 |
|
23 | 20 |
|
| 21 | + |
24 | 22 | URL_CMS_PAGE = "/admin/cms/page/"
|
25 | 23 | URL_CMS_PAGE_ADD = URL_CMS_PAGE + "add/"
|
26 | 24 | URL_CMS_PAGE_CHANGE = URL_CMS_PAGE + "%d/"
|
@@ -107,6 +105,7 @@ class CMSTestCase(TestCase):
|
107 | 105 | def _fixture_setup(self):
|
108 | 106 | super(CMSTestCase, self)._fixture_setup()
|
109 | 107 | self.create_fixtures()
|
| 108 | + self.client = Client() |
110 | 109 |
|
111 | 110 | def create_fixtures(self):
|
112 | 111 | pass
|
@@ -237,51 +236,22 @@ def get_context(self, path=None):
|
237 | 236 |
|
238 | 237 | return Context(context)
|
239 | 238 |
|
240 |
| - def get_request(self, path=None, language=None, post_data=None, enforce_csrf_checks=False): |
| 239 | + def get_request(self, path=None, language=None, post_data=None): |
| 240 | + factory = RequestFactory() |
| 241 | + |
241 | 242 | if not path:
|
242 | 243 | path = self.get_pages_root()
|
243 | 244 |
|
244 | 245 | if not language:
|
245 | 246 | language = settings.LANGUAGES[0][0]
|
246 | 247 |
|
247 |
| - parsed_path = urlparse(path) |
248 |
| - host = parsed_path.netloc or 'testserver' |
249 |
| - port = 80 |
250 |
| - if ':' in host: |
251 |
| - host, port = host.split(':', 1) |
252 |
| - |
253 |
| - environ = { |
254 |
| - 'HTTP_COOKIE': self.client.cookies, |
255 |
| - 'PATH_INFO': parsed_path.path, |
256 |
| - 'QUERY_STRING': parsed_path.query, |
257 |
| - 'REMOTE_ADDR': '127.0.0.1', |
258 |
| - 'REQUEST_METHOD': 'GET', |
259 |
| - 'SCRIPT_NAME': '', |
260 |
| - 'SERVER_NAME': host, |
261 |
| - 'SERVER_PORT': port, |
262 |
| - 'SERVER_PROTOCOL': 'HTTP/1.1', |
263 |
| - 'wsgi.version': (1,0), |
264 |
| - 'wsgi.url_scheme': 'http', |
265 |
| - 'wsgi.errors': self.client.errors, |
266 |
| - 'wsgi.multiprocess': True, |
267 |
| - 'wsgi.multithread': False, |
268 |
| - 'wsgi.run_once': False, |
269 |
| - 'wsgi.input': '' |
270 |
| - } |
271 | 248 | if post_data:
|
272 |
| - post_data = encode_multipart(BOUNDARY, post_data) |
273 |
| - environ.update({ |
274 |
| - 'CONTENT_LENGTH': len(post_data), |
275 |
| - 'CONTENT_TYPE': MULTIPART_CONTENT, |
276 |
| - 'REQUEST_METHOD': 'POST', |
277 |
| - 'wsgi.input': FakePayload(post_data), |
278 |
| - }) |
279 |
| - request = WSGIRequest(environ) |
| 249 | + request = factory.post(path, post_data) |
| 250 | + else: |
| 251 | + request = factory.get(path) |
280 | 252 | request.session = self.client.session
|
281 | 253 | request.user = getattr(self, 'user', AnonymousUser())
|
282 | 254 | request.LANGUAGE_CODE = language
|
283 |
| - if not enforce_csrf_checks: |
284 |
| - request.csrf_processing_done = True |
285 | 255 | return request
|
286 | 256 |
|
287 | 257 | def check_published_page_attributes(self, page):
|
|
0 commit comments