Skip to main content

Simple TestCase assertion that finds element based on it's path and check if it equals with given content.

Project description

https://badge.fury.io/py/assert_element.svg https://codecov.io/gh/PetrDlouhy/assert_element/branch/master/graph/badge.svg https://github.com/PetrDlouhy/django-assert-element/actions/workflows/main.yml/badge.svg?event=registry_package

Simple TestCase assertion that finds element based on it’s path and check if it equals with given content.

This is more useful than the default Django AssertContains because it will find the element and show differences if something changed. The test also tries to ignore differences in whitespaces as much as possible.

Other similar projects

I released this package just to realize after few days, that there are some other very similar projects:

Documentation

The full documentation is at https://assert_element.readthedocs.io.

Quickstart

Install by:

pip install assert-element

Usage in tests:

from assert_element import AssertElementMixin

class MyTestCase(AssertElementMixin, TestCase):
    def test_something(self):
        response = self.client.get(address)
        self.assertElementContains(
            response,
            'div[id="my-div"]',
            '<div id="my-div">My div</div>',
        )

The first attribute can be response or content itself. Second attribute is the path to the element. Third attribute is the expected content.

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Development commands

pip install -r requirements_dev.txt
invoke -l

Credits

Tools used in rendering this package:

History

0.4.0 (2023-07-21)

  • more readable output when assertion fails

0.3.0 (2022-09-16)

  • more tolerance in whitespace differences

0.2.0 (2022-09-01)

  • first attribute can be response or content itself

0.1.0 (2022-08-21)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

assert_element-0.4.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

assert_element-0.4.0-py2.py3-none-any.whl (4.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file assert_element-0.4.0.tar.gz.

File metadata

  • Download URL: assert_element-0.4.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for assert_element-0.4.0.tar.gz
Algorithm Hash digest
SHA256 bd63b0d4d267d48a8dae62cc8d6f97dc889de55185d3a006921352a073254239
MD5 c53dfd0880baa9dac522545c265bf88a
BLAKE2b-256 d086d747ef0a29c1451a3c650ef9c89ed3e31390c7cc9d1ee14b72f0072a477d

See more details on using hashes here.

File details

Details for the file assert_element-0.4.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for assert_element-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c6ecc1c2fc3cd99038cec3c824425faed297ad41a9fa561fd71b170555e83785
MD5 09615fac8dfb06e9ebeb34e9a5f465e9
BLAKE2b-256 ce9de4581a35fe93391f2fde0d28e1368546794b57cf6fb8f396a95ee24eb089

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page