Package: django-functest
Helpers for creating high-level functional tests in Django, with a unified API
for WebTest and Selenium tests.Exploring django-functest makes me angry! Why? Because I’ve wasted so much
time writing low-level, boilerplate-filled tests for the past few years
instead of using it —jerivasWhat isWebTest?
Imagine a text-based, HTML-only browser that doesn’t load CSS, Javascript etc,
operates directly on a WSGI interface in a synchronous fashion for performance
and robustness, and is controlled programmatically.What isSelenium? A tool that opens full browsers
like Firefox and Chrome (with an isolated profile), and provides an API for
controlling them.For an idea of what writing tests with django-functest looks like in practice,
you might be interested in the video in ourwriting tests interactively
documentation.DocumentationThe full documentation is athttps://django-functest.readthedocs.org.InstallationPython 3.7 and later, Django 2.0 and later are required.pip install django-functestSee also thedependencies documentationfor important compatibility information.FeaturesA simplified API for writing functional tests in Django (tests that check the
behaviour of entire views, or sets of views, e.g. a checkout process).A unified API that abstracts over bothWebTestandSelenium- write two tests at once!Many of the gotchas and difficulties of using WebTest and Selenium ironed out
for you.Well tested - as well as its own test suite, which is run against Firefox
and Chrome, it is also used byWolf & Badgerfor tests covering many business critical
functionalities.Supports running with pytest (using pytest-django) as well as Django’smanage.py testTypical usageIn your tests.py:fromdjango.testimportLiveServerTestCase,TestCasefromdjango_functestimportFuncWebTestMixin,FuncSeleniumMixin,FuncBaseMixinclassContactTestBase(FuncBaseMixin):# Abstract class, doesn't inherit from TestCasedeftest_contact_form(self):self.get_url("contact_form")self.fill({"#id_name":"Joe","#id_message":"Hello",})self.submit("input[type=submit]")self.assertTextPresent("Thanks for your message")classContactWebTest(ContactTestBase,FuncWebTestMixin,TestCase):passclassContactSeleniumTest(ContactTestBase,FuncSeleniumMixin,LiveServerTestCase):passIn this way, you can write a single test with a high-level API, and run it in
two ways - using a fast, WSGI-based method which emulates typical HTTP usage of a
browser, and using a full browser that actually executes Javascript (if present)
etc.The approach taken by django-functest is ideal if your web app is mostly a
“classic” app with server-side rendered HTML combined with a careful sprinkling
of Javascript to enhance the UI, which you also need to be able to test. If such
an approach seems old-fashioned to you, have a look athtmx.orgorhotwireand get with the new
kids! (OK most of are actually quite old but we make fast web sites…)Under the hood, the WSGI-based method uses and builds uponWebTestanddjango-webtest.django-functest provides its functionality as mixins, so that you can have your
own base class for tests.Contributing and testsSeeCONTRIBUTING.rstfor information about running the test suite and
contributing to django-functest.Building on Mac OSWhile [this lxml bug](https://bugs.launchpad.net/lxml/+bug/1949271) is in
effectlxmlcannot handle certain unicode characters in HTML (or XML!)
documents on Mac OS, including the emoji used in one of the files in the test
suite.Therefore, if you are affected by this bug, you will find that certain tests
fail with the errorlxml.etree.ParserError: Document is empty.You will also find thatlxml’s own test suite fails on your machine.A workaround is to compilelibxml2yourself, whichlxmlwill take care of for you.
To do this, run the following:` STATICBUILD=true python-mpip install lxml--force-reinstall--no-binary=:all:`Paid supportSome of the maintainers are able to provide support on a paid basis for this
Open Source project. This includes the following kinds of things:Paying for bug fixes or new features (with the understanding that these
changes will become freely available as part of the project and are not
‘owned’ by the person who paid for them).Debugging or other support for integrating django-functest into your project.Writing a test suite for you from scratch using django-functest.If you are interested in these, you can contact the following developers:Luke Plant - long time Django expert and contributor -info and status.CreditsThis library was written originally byspookylukey,
further improved by developers atWolf & Badger, and released with the kind permission of that
company.Tools used in rendering this package:Cookiecuttercookiecutter-djangopackage