Skip to main content

django-testhook

A Django template tag to enable testhook attributes on HTML elements.

https://travis-ci.org/jjanssen/django-testhook.svg?branch=master https://img.shields.io/pypi/v/django-testhook.svg https://img.shields.io/pypi/dm/django-testhook.svg https://img.shields.io/badge/wheel-yes-green.svg https://img.shields.io/pypi/l/django-testhook.svg https://img.shields.io/pypi/pyversions/Django.svg https://coveralls.io/repos/jjanssen/django-testhook/badge.svg?branch=master

About django-testhook

The django-testhook provides a template tag to generate data-testhook-id for HTML templates.

This can be useful for automated testing (for eg: Webdriver.IO) to maintain a fixed entry point, rather than having a automated test that breaks by just renaming a CSS class or an element which can require you to re-evaluate an XPath-selector.

Requirements

Django 1.8.x or greater, Python 2.7 or greater.

Installation

Install django-testhook with pip:

$ pip install django-testhook

Configuration

Configuring django-testhook

Add the following to your settings file:

INSTALLED_APPS += (
    'testhook',
)

Available settings

By default the rendering of testhook data attributes is enabled. If you are in the scenario you want to disable it for a certain environment just configure it to False.

TESTHOOK_ENABLED = False

Usage

Basic usage

Within your HTML template you must load the testhook tag in order to use it. The testhook tag only requires a single argument in order to return a result.

{% load testhook %}

<div class="my-elem" {% testhook "test-elem" %}>
    I want to test this
</div>

This will output to the following:

<div class="my-elem" data-testhook-id="test-elem">
    I want to test this
</div>

Object Usage

For dynamic elements there is also the option to pass arguments. For eg: given I have a product in a shopping basket with a primary key and a slug I could use it like this:

<div class="item" {% testhook "basket" product.id product.slug %}>
    {{ product.title }}
</div>

It will output to:

<div class="item" data-testhook-id="basket-1-product-slug">
    A product title
</div>

Metadata

Release files for django-testhook 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-testhook 1.0.2
File Size Uploaded Provenance Actions
django-testhook-1.0.2.tar.gz 7.9 kB Without provenance Details for django-testhook-1.0.2.tar.gz

Release files / django-testhook-1.0.2.tar.gz

Download URL django-testhook-1.0.2.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
946c01590431961ca6d65b2dc005c1df34f23d73cdb4e25c0bc57287859750f6
BLAKE2b-256 checksum
How to use checksums
bf67050dad0b5cdb0034de7e2aba27d12ed68209137d37961e6075aea1baecf5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-testhook 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.2 This release

1 release file No provenance

1.0.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page