Skip to content

Commit

Permalink
Split BaseTestCase as mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed Jan 14, 2018
1 parent f06e881 commit 597228e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
24 changes: 19 additions & 5 deletions djangocms_helper/base_test.py
Expand Up @@ -12,7 +12,7 @@
from django.http import SimpleCookie
from django.template import RequestContext
from django.template.loader import get_template
from django.test import RequestFactory, TestCase
from django.test import RequestFactory, TestCase, TransactionTestCase
from django.utils.functional import SimpleLazyObject
from django.utils.six import StringIO

Expand All @@ -26,9 +26,9 @@
from mock import patch


class BaseTestCase(TestCase):
class BaseTestCaseMixin(object):
"""
Utils class that provides some helper methods to setup and interact with
Utils mixin that provides some helper methods to setup and interact with
Django testing framework.
"""
request_factory = None
Expand Down Expand Up @@ -87,7 +87,7 @@ class BaseTestCase(TestCase):
@classmethod
def setUpClass(cls):
from django.contrib.sites.models import Site
super(BaseTestCase, cls).setUpClass()
super(BaseTestCaseMixin, cls).setUpClass()
cls.request_factory = RequestFactory()
cls.user = create_user(
cls._admin_user_username, cls._admin_user_email, cls._admin_user_password,
Expand All @@ -111,7 +111,7 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
super(BaseTestCase, cls).tearDownClass()
super(BaseTestCaseMixin, cls).tearDownClass()
User = get_user_model()
User.objects.all().delete()

Expand Down Expand Up @@ -523,3 +523,17 @@ def captured_output(self):
with patch('sys.stdout', new_callable=StringIO) as out:
with patch('sys.stderr', new_callable=StringIO) as err:
yield out, err


class BaseTestCase(BaseTestCaseMixin, TestCase):
"""
Base class that implements :py:class:`BaseTestCaseMixin` and
:py:class:`django.tests.TestCase`
"""


class BaseTransactionTestCase(BaseTestCaseMixin, TransactionTestCase):
"""
Base class that implements :py:class:`BaseTestCaseMixin` and
:py:class:`django.tests.TransactionTestCase`
"""
13 changes: 12 additions & 1 deletion docs/basetest.rst
@@ -1,7 +1,13 @@
Base test class
===============

.. autoclass:: djangocms_helper.base_test.BaseTestCase
:py:class:`BaseTestCaseMixin` is available to provide helpers and methods that implements
repetitive tasks during development.
:py:class:`BaseTestCase`, :py:class:`BaseTransactionTestCase` are concrete classes extending
:py:class:`django.tests.TestCase` and :py:class:`django.tests.TransactionTestCase`


.. autoclass:: djangocms_helper.base_test.BaseTestCaseMixin
:members:
:private-members:

Expand All @@ -15,3 +21,8 @@ Base test class
.. autoattribute:: djangocms_helper.base_test.BaseTestCase._user_user_password
.. autoattribute:: djangocms_helper.base_test.BaseTestCase._user_user_email
.. autoattribute:: djangocms_helper.base_test.BaseTestCase._pages_data


.. autoclass:: djangocms_helper.base_test.BaseTestCase

.. autoclass:: djangocms_helper.base_test.BaseTransactionTestCase
7 changes: 5 additions & 2 deletions docs/settings.rst
Expand Up @@ -62,13 +62,13 @@ All ``TEMPLATES_`` settings from Django 1.6/1.7 are automatically translated to
will take care of converting.

Django 1.10 support
==================
===================

``MIDDLEWARE_CLASSES`` setting is automatically copied into ``MIDDLEWARE`` on Django 1.10 and above
to support new style middleware. *This assumes all the middlewares are compatible with the new style.*
If you define a ``MIDDLEWARE`` setting, ``MIDDLEWARE_CLASSES`` is **not** copied over it or merged with
it, including the django CMS middlewares. To support both styles, thus, just use the old setting and
and the `compatibility mixin<https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-middleware>`_.
and the `compatibility mixin`_.


================
Expand Down Expand Up @@ -151,3 +151,6 @@ Middlewares::
``djangocms-helper`` discovers automtically the South / Django migrations layout and configure
the settings accordingly. As of the current version ``filer``, ``djangocms_text_ckeditor``,
``cmplugin_filer`` are supported.


.. _compatibility mixin: https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-middleware

0 comments on commit 597228e

Please sign in to comment.