=============================
Django assert element
=============================
.. image:: https://badge.fury.io/py/assert_element.svg
:target: https://badge.fury.io/py/assert_element
.. image:: https://codecov.io/gh/PetrDlouhy/assert_element/branch/master/graph/badge.svg
:target: https://codecov.io/gh/PetrDlouhy/assert_element
.. image:: https://github.com/PetrDlouhy/django-assert-element/actions/workflows/main.yml/badge.svg?event=registry_package
:target: https://github.com/PetrDlouhy/django-assert-element/actions/workflows/main.yml
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:
* https://pypi.org/project/django_html_assertions/
* https://django-with-asserts.readthedocs.io/en/latest/
* https://github.com/robjohncox/python-html-assert
Documentation
-------------
The full documentation is at https://assert_element.readthedocs.io.
Quickstart
----------
Install by:
.. code-block:: bash
pip install assert-element
Usage in tests:
.. code-block:: python
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:
* Cookiecutter_
* `cookiecutter-djangopackage`_
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/PetrDlouhy/django-assert-element",
"name": "assert-element",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "assert_element",
"author": "Petr Dlouh\u00fd",
"author_email": "petr.dlouhy@email.cz",
"download_url": "https://files.pythonhosted.org/packages/d0/86/d747ef0a29c1451a3c650ef9c89ed3e31390c7cc9d1ee14b72f0072a477d/assert_element-0.4.0.tar.gz",
"platform": null,
"description": "=============================\nDjango assert element\n=============================\n\n.. image:: https://badge.fury.io/py/assert_element.svg\n :target: https://badge.fury.io/py/assert_element\n\n.. image:: https://codecov.io/gh/PetrDlouhy/assert_element/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/PetrDlouhy/assert_element\n\n.. image:: https://github.com/PetrDlouhy/django-assert-element/actions/workflows/main.yml/badge.svg?event=registry_package\n :target: https://github.com/PetrDlouhy/django-assert-element/actions/workflows/main.yml\n\nSimple TestCase assertion that finds element based on it's path and check if it equals with given content.\n\nThis is more useful than the default Django AssertContains\nbecause it will find the element and show differences if something changed.\nThe test also tries to ignore differences in whitespaces as much as possible.\n\nOther similar projects\n----------------------\n\nI released this package just to realize after few days, that there are some other very similar projects:\n\n* https://pypi.org/project/django_html_assertions/\n* https://django-with-asserts.readthedocs.io/en/latest/\n* https://github.com/robjohncox/python-html-assert\n\nDocumentation\n-------------\n\nThe full documentation is at https://assert_element.readthedocs.io.\n\nQuickstart\n----------\n\nInstall by:\n\n.. code-block:: bash\n \n pip install assert-element\n\nUsage in tests:\n\n.. code-block:: python\n\n from assert_element import AssertElementMixin\n\n class MyTestCase(AssertElementMixin, TestCase):\n def test_something(self):\n response = self.client.get(address)\n self.assertElementContains(\n response,\n 'div[id=\"my-div\"]',\n '<div id=\"my-div\">My div</div>',\n )\n\nThe first attribute can be response or content itself.\nSecond attribute is the path to the element.\nThird attribute is the expected content.\n\nRunning Tests\n-------------\n\nDoes the code actually work?\n\n::\n\n source <YOURVIRTUALENV>/bin/activate\n (myenv) $ pip install tox\n (myenv) $ tox\n\n\nDevelopment commands\n---------------------\n\n::\n\n pip install -r requirements_dev.txt\n invoke -l\n\n\nCredits\n-------\n\nTools used in rendering this package:\n\n* Cookiecutter_\n* `cookiecutter-djangopackage`_\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage\n\n\n\n\nHistory\n-------\n\n0.4.0 (2023-07-21)\n++++++++++++++++++\n\n* more readable output when assertion fails\n\n0.3.0 (2022-09-16)\n++++++++++++++++++\n\n* more tolerance in whitespace differences\n\n0.2.0 (2022-09-01)\n++++++++++++++++++\n\n* first attribute can be response or content itself\n\n0.1.0 (2022-08-21)\n++++++++++++++++++\n\n* First release on PyPI.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simple TestCase assertion that finds element based on it's path and check if it equals with given content.",
"version": "0.4.0",
"project_urls": {
"Homepage": "https://github.com/PetrDlouhy/django-assert-element"
},
"split_keywords": [
"assert_element"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ce9de4581a35fe93391f2fde0d28e1368546794b57cf6fb8f396a95ee24eb089",
"md5": "09615fac8dfb06e9ebeb34e9a5f465e9",
"sha256": "c6ecc1c2fc3cd99038cec3c824425faed297ad41a9fa561fd71b170555e83785"
},
"downloads": -1,
"filename": "assert_element-0.4.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "09615fac8dfb06e9ebeb34e9a5f465e9",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 4571,
"upload_time": "2023-07-21T16:34:59",
"upload_time_iso_8601": "2023-07-21T16:34:59.448076Z",
"url": "https://files.pythonhosted.org/packages/ce/9d/e4581a35fe93391f2fde0d28e1368546794b57cf6fb8f396a95ee24eb089/assert_element-0.4.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d086d747ef0a29c1451a3c650ef9c89ed3e31390c7cc9d1ee14b72f0072a477d",
"md5": "c53dfd0880baa9dac522545c265bf88a",
"sha256": "bd63b0d4d267d48a8dae62cc8d6f97dc889de55185d3a006921352a073254239"
},
"downloads": -1,
"filename": "assert_element-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "c53dfd0880baa9dac522545c265bf88a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 18575,
"upload_time": "2023-07-21T16:35:01",
"upload_time_iso_8601": "2023-07-21T16:35:01.379299Z",
"url": "https://files.pythonhosted.org/packages/d0/86/d747ef0a29c1451a3c650ef9c89ed3e31390c7cc9d1ee14b72f0072a477d/assert_element-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-21 16:35:01",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "PetrDlouhy",
"github_project": "django-assert-element",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"tox": true,
"lcname": "assert-element"
}