Base test class¶
BaseTestCaseMixin
is available to provide helpers and methods that implements
repetitive tasks during development.
BaseTestCase
, BaseTransactionTestCase
are concrete classes extending
django.tests.TestCase
and django.tests.TransactionTestCase
-
class
djangocms_helper.base_test.
BaseTestCaseMixin
[source]¶ Utils mixin that provides some helper methods to setup and interact with Django testing framework.
-
BaseTestCase.
_admin_user_username
= u'admin'¶
-
BaseTestCase.
_admin_user_password
= u'admin'¶
-
BaseTestCase.
_admin_user_email
= u'admin@admin.com'¶
-
BaseTestCase.
_staff_user_username
= u'staff'¶
-
BaseTestCase.
_staff_user_password
= u'staff'¶
-
BaseTestCase.
_staff_user_email
= u'staff@admin.com'¶
-
BaseTestCase.
_user_user_username
= u'normal'¶
-
BaseTestCase.
_user_user_password
= u'normal'¶
-
BaseTestCase.
_user_user_email
= u'user@admin.com'¶
-
BaseTestCase.
_pages_data
= ()¶
-
_admin_user_email
= u'admin@admin.com'¶ Email for auto-generated superuser
-
_admin_user_password
= u'admin'¶ Password for auto-generated superuser
-
_admin_user_username
= u'admin'¶ Username for auto-generated superuser
-
_pages_data
= ()¶ List of pages data for the different languages.
Each item of the list is a dictionary containing the attributes (as accepted by
cms.api.create_page
) of the page to be created.The first language will be created with
cms.api.create_page
the following languages usingcms.api.create_title
- Example:
Single page created in en, fr, it languages:
_pages_data = ( { 'en': {'title': 'Page title', 'template': 'page.html', 'publish': True}, 'fr': {'title': 'Titre', 'publish': True}, 'it': {'title': 'Titolo pagina', 'publish': False} }, )
-
_staff_user_email
= u'staff@admin.com'¶ Email for auto-generated staff user
-
_staff_user_password
= u'staff'¶ Password for auto-generated staff user
-
_staff_user_username
= u'staff'¶ Username for auto-generated staff user
-
_user_user_email
= u'user@admin.com'¶ Email for auto-generated non-staff user
-
_user_user_password
= u'normal'¶ Password for auto-generated non-staff user
-
_user_user_username
= u'normal'¶ Username for auto-generated non-staff user
-
captured_output
(**kwds)[source]¶ Context manager that patches stdout / stderr with StringIO and return the instances. Use it to test output
Returns: stdout, stderr wrappers
-
static
create_django_image
()[source]¶ Create a django image file object suitable for FileField It also sets the following attributes:
self.image_name
: the image base nameself.filename
: the complete image path
Returns: (django file object, path to file image) It requires Pillow installed in the environment to work
-
create_django_image_object
()[source]¶ Create a django image file object suitable for FileField It also sets the following attributes:
self.image_name
: the image base nameself.filename
: the complete image path
Returns: django file object It requires Pillow installed in the environment to work
-
static
create_filer_image
(user, image_name)[source]¶ Create a filer image object suitable for FilerImageField It also sets the following attributes:
self.image_name
: the image base nameself.filename
: the complete image pathself.filer_image
: the filer image object
Parameters: - user – image owner
- image_name – image name
Returns: filer image object
It requires Pillow and django-filer installed in the environment to work
-
create_filer_image_object
()[source]¶ Create a filer image object suitable for FilerImageField It also sets the following attributes:
self.image_name
: the image base nameself.filename
: the complete image pathself.filer_image
: the filer image object
Returns: filer image object It requires Pillow and django-filer installed in the environment to work
-
static
create_image
(mode=u'RGB', size=(800, 600))[source]¶ Create a random image suitable for saving as DjangoFile :param mode: color mode :param size: tuple of width, height :return: image object
It requires Pillow installed in the environment to work
-
static
create_pages
(source, languages)[source]¶ Build pages according to the pages data provided by
get_pages_data()
and returns the list of the draft version of each
-
create_user
(username, email, password, is_staff=False, is_superuser=False, base_cms_permissions=False, permissions=None)[source]¶ Creates a user with the given properties
Parameters: - username – Username
- email – Email
- password – password
- is_staff – Staff status
- is_superuser – Superuser status
- base_cms_permissions – Base django CMS permissions
- permissions – Other permissions
Returns: User instance
-
get_content_renderer
(request)[source]¶ Returns a the plugin renderer. Only for django CMS 3.4+
Parameters: request – request instance Returns: ContentRenderer instance
-
get_page_request
(page, user, path=None, edit=False, lang=u'en', use_middlewares=False, secure=False)[source]¶ Create a GET request for the given page suitable for use the django CMS toolbar
This method requires django CMS installed to work. It will raise an ImportError otherwise; not a big deal as this method makes sense only in a django CMS environment
Parameters: - page – current page object
- user – current user
- path – path (if different from the current page path)
- edit – whether enabling editing mode
- lang – request language
- use_middlewares – pass the request through configured middlewares.
- secure – create HTTPS request
Returns: request
-
get_pages
()[source]¶ Create pages using self._pages_data and self.languages :return: list of created pages
-
get_pages_data
()[source]¶ Construct a list of pages in the different languages available for the project. Default implementation is to return the
_pages_data
attributeReturns: list of pages data
-
get_plugin_context
(page, lang, plugin, edit=False)[source]¶ Returns a context suitable for CMSPlugin.render_plugin / render_placeholder
Parameters: - page – Page object
- lang – Current language
- plugin – Plugin instance
- edit – Enable edit mode for rendering
Returns: PluginContext instance
-
get_request
(page, lang, user=None, path=None, use_middlewares=False, secure=False)[source]¶ Create a GET request for the given page and language
Parameters: - page – current page object
- lang – request language
- user – current user
- path – path (if different from the current page path)
- use_middlewares – pass the request through configured middlewares.
- secure – create HTTPS request
Returns: request
-
login_user_context
(user, password=None)[source]¶ Context manager to make logged in requests :param user: user username :param password: user password (if omitted, username is used)
-
post_request
(page, lang, data, user=None, path=None, use_middlewares=False, secure=False)[source]¶ Create a POST request for the given page and language with CSRF disabled
Parameters: - page – current page object
- lang – request language
- data – POST payload
- user – current user
- path – path (if different from the current page path)
- use_middlewares – pass the request through configured middlewares.
- secure – create HTTPS request
Returns: request
-
reload_model
(obj)[source]¶ Reload a models instance from database :param obj: model instance to reload :return: the reloaded model instance
-
-
class
djangocms_helper.base_test.
BaseTestCase
(methodName='runTest')[source]¶ Base class that implements
BaseTestCaseMixin
anddjango.tests.TestCase
-
class
djangocms_helper.base_test.
BaseTransactionTestCase
(methodName='runTest')[source]¶ Base class that implements
BaseTestCaseMixin
anddjango.tests.TransactionTestCase