Skip to content

Commit d60f895

Browse files
author
Jonas Obrist
committed
more fixes to 995 (more tests fail now)
1 parent 01c067c commit d60f895

File tree

2 files changed

+13
-42
lines changed

2 files changed

+13
-42
lines changed

cms/test_utils/testcases.py

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22
from cms.models import Page
33
from cms.test_utils.util.context_managers import (UserLoginContext,
44
SettingsOverride, _AssertNumQueriesContext)
5+
from cms.test_utils.util.request_factory import RequestFactory
56
from django.conf import settings
6-
from django.db.utils import DEFAULT_DB_ALIAS
7-
from django.db import connections
8-
97
from django.contrib.auth.models import User, AnonymousUser
108
from django.core.exceptions import ObjectDoesNotExist
11-
from django.core.handlers.wsgi import WSGIRequest
129
from django.core.urlresolvers import reverse
10+
from django.db import connections
11+
from django.db.utils import DEFAULT_DB_ALIAS
1312
from django.template.context import Context
14-
from django.test.client import (encode_multipart, BOUNDARY, MULTIPART_CONTENT,
15-
FakePayload)
1613
from django.test import testcases
14+
from django.test.client import Client
1715
from menus.menu_pool import menu_pool
18-
from urlparse import urlparse
1916
import sys
2017
import urllib
2118
import warnings
2219

2320

21+
2422
URL_CMS_PAGE = "/admin/cms/page/"
2523
URL_CMS_PAGE_ADD = URL_CMS_PAGE + "add/"
2624
URL_CMS_PAGE_CHANGE = URL_CMS_PAGE + "%d/"
@@ -107,6 +105,7 @@ class CMSTestCase(TestCase):
107105
def _fixture_setup(self):
108106
super(CMSTestCase, self)._fixture_setup()
109107
self.create_fixtures()
108+
self.client = Client()
110109

111110
def create_fixtures(self):
112111
pass
@@ -237,51 +236,22 @@ def get_context(self, path=None):
237236

238237
return Context(context)
239238

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+
241242
if not path:
242243
path = self.get_pages_root()
243244

244245
if not language:
245246
language = settings.LANGUAGES[0][0]
246247

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-
}
271248
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)
280252
request.session = self.client.session
281253
request.user = getattr(self, 'user', AnonymousUser())
282254
request.LANGUAGE_CODE = language
283-
if not enforce_csrf_checks:
284-
request.csrf_processing_done = True
285255
return request
286256

287257
def check_published_page_attributes(self, page):

cms/tests/templatetags.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def _getsecond(self):
4747
def test_get_page_by_untyped_arg_none(self):
4848
control = self._getfirst()
4949
request = self.get_request('/')
50+
request.current_page = control
5051
page = _get_page_by_untyped_arg(None, request, 1)
5152
self.assertEqual(page, control)
5253

0 commit comments

Comments
 (0)