Base test class

class djangocms_helper.base_test.BaseTestCase(methodName='runTest')[source]

Utils class that provides some helper methods to setup and interact with Django testing framework.

captured_output(*args, **kwds)[source]

Context manager that patches stdout / stderr with StringIO and return the instances. Use it to test output

Returns:stdout, stderr wrappers
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 name
  • self.filename: the complete image path
Returns:django file object

It requires Pillow 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 name
  • self.filename: the complete image path
  • self.filer_image: the filer image object
Returns:filer image object

It requires Pillow and django-filer installed in the environment to work

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_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 attribute

Returns: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

render_plugin(page, lang, plugin, edit=False)[source]

Renders a single plugin using CMSPlugin.render_plugin

Parameters:
  • page – Page object
  • lang – Current language
  • plugin – Plugin instance
  • edit – Enable edit mode for rendering
Returns:

Rendered plugin

temp_dir(*args, **kwds)[source]

Context manager to operate on a temporary directory