Permalink
Browse files

Merge branch 'develop' into fix-1080

  • Loading branch information...
2 parents a23ebe7 + 7fecd87 commit 9d364739696e431845b4416d097288a99eb05b73 @digi604 committed Aug 9, 2012
Showing with 4 additions and 179 deletions.
  1. +2 −3 cms/test_utils/testcases.py
  2. +0 −173 cms/test_utils/util/request_factory.py
  3. +1 −2 cms/tests/admin.py
  4. +1 −1 cms/tests/toolbar.py
@@ -1,15 +1,14 @@
# -*- coding: utf-8 -*-
from cms.models import Page
-from cms.test_utils.util.context_managers import (UserLoginContext,
+from cms.test_utils.util.context_managers import (UserLoginContext,
SettingsOverride)
-from cms.test_utils.util.request_factory import RequestFactory
from django.conf import settings
from django.contrib.auth.models import User, AnonymousUser
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.template.context import Context
from django.test import testcases
-from django.test.client import Client
+from django.test.client import Client, RequestFactory
from menus.menu_pool import menu_pool
from urlparse import urljoin
import sys
@@ -1,173 +0,0 @@
-from StringIO import StringIO
-from django.conf import settings
-from django.core.handlers.wsgi import WSGIRequest
-from django.http import SimpleCookie
-from django.test.client import (FakePayload, MULTIPART_CONTENT, encode_multipart,
- BOUNDARY, CONTENT_TYPE_RE)
-from django.utils.encoding import smart_str
-from urllib import urlencode
-from urlparse import urlparse
-import urllib
-
-
-class RequestFactory(object):
- """
- Class that lets you create mock Request objects for use in testing.
-
- Usage:
-
- rf = RequestFactory()
- get_request = rf.get('/hello/')
- post_request = rf.post('/submit/', {'foo': 'bar'})
-
- Once you have a request object you can pass it to any view function,
- just as if that view had been hooked up using a URLconf.
- """
- def __init__(self, **defaults):
- self.defaults = defaults
- self.cookies = SimpleCookie()
- self.errors = StringIO()
-
- def _base_environ(self, **request):
- """
- The base environment for a request.
- """
- environ = {
- 'HTTP_COOKIE': self.cookies.output(header='', sep='; '),
- 'PATH_INFO': '/',
- '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.errors,
- 'wsgi.multiprocess': True,
- 'wsgi.multithread': False,
- 'wsgi.run_once': False,
- }
- environ.update(self.defaults)
- environ.update(request)
- return environ
-
- def request(self, **request):
- "Construct a generic request object."
- return WSGIRequest(self._base_environ(**request))
-
- def _get_path(self, parsed):
- # If there are parameters, add them
- if parsed[3]:
- return urllib.unquote(parsed[2] + ";" + parsed[3])
- else:
- return urllib.unquote(parsed[2])
-
- def get(self, path, data={}, **extra):
- "Construct a GET request"
-
- parsed = urlparse(path)
- r = {
- 'CONTENT_TYPE': 'text/html; charset=utf-8',
- 'PATH_INFO': self._get_path(parsed),
- 'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
- 'REQUEST_METHOD': 'GET',
- 'wsgi.input': FakePayload('')
- }
- r.update(extra)
- return self.request(**r)
-
- def post(self, path, data={}, content_type=MULTIPART_CONTENT,
- **extra):
- "Construct a POST request."
-
- if content_type is MULTIPART_CONTENT:
- post_data = encode_multipart(BOUNDARY, data)
- else:
- # Encode the content so that the byte representation is correct.
- match = CONTENT_TYPE_RE.match(content_type)
- if match:
- charset = match.group(1)
- else:
- charset = settings.DEFAULT_CHARSET
- post_data = smart_str(data, encoding=charset)
-
- parsed = urlparse(path)
- r = {
- 'CONTENT_LENGTH': len(post_data),
- 'CONTENT_TYPE': content_type,
- 'PATH_INFO': self._get_path(parsed),
- 'QUERY_STRING': parsed[4],
- 'REQUEST_METHOD': 'POST',
- 'wsgi.input': FakePayload(post_data),
- }
- r.update(extra)
- return self.request(**r)
-
- def head(self, path, data={}, **extra):
- "Construct a HEAD request."
-
- parsed = urlparse(path)
- r = {
- 'CONTENT_TYPE': 'text/html; charset=utf-8',
- 'PATH_INFO': self._get_path(parsed),
- 'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
- 'REQUEST_METHOD': 'HEAD',
- 'wsgi.input': FakePayload('')
- }
- r.update(extra)
- return self.request(**r)
-
- def options(self, path, data={}, **extra):
- "Constrict an OPTIONS request"
-
- parsed = urlparse(path)
- r = {
- 'PATH_INFO': self._get_path(parsed),
- 'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
- 'REQUEST_METHOD': 'OPTIONS',
- 'wsgi.input': FakePayload('')
- }
- r.update(extra)
- return self.request(**r)
-
- def put(self, path, data={}, content_type=MULTIPART_CONTENT,
- **extra):
- "Construct a PUT request."
-
- if content_type is MULTIPART_CONTENT:
- post_data = encode_multipart(BOUNDARY, data)
- else:
- post_data = data
-
- # Make `data` into a querystring only if it's not already a string. If
- # it is a string, we'll assume that the caller has already encoded it.
- query_string = None
- if not isinstance(data, basestring):
- query_string = urlencode(data, doseq=True)
-
- parsed = urlparse(path)
- r = {
- 'CONTENT_LENGTH': len(post_data),
- 'CONTENT_TYPE': content_type,
- 'PATH_INFO': self._get_path(parsed),
- 'QUERY_STRING': query_string or parsed[4],
- 'REQUEST_METHOD': 'PUT',
- 'wsgi.input': FakePayload(post_data),
- }
- r.update(extra)
- return self.request(**r)
-
- def delete(self, path, data={}, **extra):
- "Construct a DELETE request."
-
- parsed = urlparse(path)
- r = {
- 'PATH_INFO': self._get_path(parsed),
- 'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
- 'REQUEST_METHOD': 'DELETE',
- 'wsgi.input': FakePayload('')
- }
- r.update(extra)
- return self.request(**r)
View
@@ -19,7 +19,6 @@
URL_CMS_PAGE, URL_CMS_TRANSLATION_DELETE)
from cms.test_utils.util.context_managers import SettingsOverride
from cms.test_utils.util.mock import AttributeObject
-from cms.test_utils.util.request_factory import RequestFactory
from django.conf import settings
from django.contrib import admin
from django.contrib.admin.sites import site
@@ -29,7 +28,7 @@
from django.core.urlresolvers import reverse
from django.http import (Http404, HttpResponseBadRequest, HttpResponseForbidden,
HttpResponse)
-from django.test.client import Client
+from django.test.client import Client, RequestFactory
from django.utils.encoding import smart_str
from menus.menu_pool import menu_pool
from types import MethodType
@@ -2,13 +2,13 @@
from cms.api import create_page
from cms.cms_toolbar import CMSToolbar
from cms.test_utils.testcases import SettingsOverrideTestCase
-from cms.test_utils.util.request_factory import RequestFactory
from cms.toolbar.items import (Anchor, TemplateHTML, Switcher, List, ListItem,
GetButton)
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User
from django.contrib.sessions.middleware import SessionMiddleware
from django.core.urlresolvers import reverse
+from django.test.client import RequestFactory
class ToolbarUserMixin(object):
def get_anon(self):

0 comments on commit 9d36473

Please sign in to comment.