django-selectable has its own test suite for testing the rendering, validation
and server-side logic it provides. However, depending on the additional customizations
you add to your forms and lookups you most likely will want to include tests of your
own. This section contains some tips or techniques for testing your lookups.

This guide assumes that you are reasonable familiar with the concepts of unit testing
including Python’s unittest module and
Django’s testing guide.

For the most part testing forms which use django-selectable’s custom fields
and widgets is the same as testing any Django form. One point that is slightly
different is that the select and multi-select widgets are
MultiWidgets.
The effect of this is that there are two names in the post rather than one. Take the below
form for example.

# forms.pyfromdjangoimportformsfromselectable.formsimportAutoCompleteSelectFieldfrom.lookupsimportThingLookupclassSimpleForm(forms.Form):"Basic form for testing."thing=AutoCompleteSelectField(lookup_class=ThingLookup)

This form has a single field to select a Thing. It does not allow
new items. Let’s write some simple tests for this form.

Here you will note that while there is only one field thing it requires
two items in the POST the first is for the text input and the second is for
the hidden input. This is again due to the use of MultiWidget for the selection.

There is compatibility code in the widgets to lookup the original name
from the POST. This makes it easier to transition to the the selectable widgets without
breaking existing tests.

Testing the lookups used by django-selectable is similar to testing your Django views.
While it might be tempting to use the Django
test client,
it is slightly easier to use the
request factory.
A simple example is given below.

As shown in the test_label example it is not required to test the full
request/response. You can test each of the methods in the lookup API individually.
When testing your lookups you should focus on testing the portions which have been
customized by your application.