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 – Template context. If not set empty context is used.
  • request – Expects HttpRequest or string. String is used as a path for GET-request.
  • current_app
  • user – User instance to associate request with. Defaults to a new anonymous user. If string is passed, it is considered to be
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 – Template tags library name to load tag from.
  • tag_str – Tag string itself. As used in templates, but without {% %}.
  • 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 – HTML to strin tags from
  • joiner – String to join tags contents. Default: |