Templates

These fixtures are related to Django templates system.

pytest_djangoapp.fixtures.templates.template_context(request_get, user_create)

Creates template context object.

To be used with template_render_tag fixture.

Example:

def test_this(template_context):
    context = template_context({'somevar': 'someval'})
Parameters
  • context_dict (dict) – Template context. If not set empty context is used.

  • request (str|unicode|HttpRequest) – Expects HttpRequest or string. String is used as a path for GET-request.

  • current_app (str|unicode) –

  • user (AbstractBaseUser|str|unicode) – User to associate request with. Defaults to anonymous user.

pytest_djangoapp.fixtures.templates.template_render_tag()

Renders a template tag from a given library by its name.

Example:

def test_this(template_render_tag):
    rendered = template_render_tag('library_name', 'mytag arg1 arg2')
Parameters
  • library (str|unicode) – Template tags library name to load tag from.

  • tag_str (str|unicode) – Tag string itself. As used in templates, but without {% %}.

  • context (Context) – Template context object. If not set, empty context object is used.

pytest_djangoapp.fixtures.templates.template_strip_tags()

Allows HTML tags strip from string.

To be used with template_render_tag fixture to easy result assertions.

Example:

def test_this(template_strip_tags):
    stripped = template_strip_tags('<b>some</b>')
Parameters
  • html (str|unicode) – HTML to strin tags from

  • joiner (str|unicode) – String to join tags contents. Default: |