lino.utils.djangotest

Two TestCase classes for writing tests be run using Django's test runner (i.e. manage.py test).

(This module's source code is available here.)

Classes

DjangoManageTestCase([methodName])

Adds some extensions to the Django TestCase.

NoAuthTestCase([methodName])

RemoteAuthTestCase([methodName])

Base class for tests that use remote http authentication.

RestoreTestCase([methodName])

Used for testing migrations from previous versions.

TestCase

alias of lino.utils.djangotest.RemoteAuthTestCase

WebIndexTestCase([methodName])

Designed to be just imported.

class lino.utils.djangotest.DjangoManageTestCase(methodName='runTest')

Bases: django.test.testcases.TestCase, lino.utils.test.CommonTestCase

Adds some extensions to the Django TestCase.

override_djangosite_settings = {}

If specified, this is a dict of Site attributes to override before running the test.

defining_module = None

When you decorate your subclass of TestCase, you must also specify:

defining_module = __name__

Because a decorator will change your class's __module__ attribute and test_them_all() would search for test methods in the wrong module.

check_sql_queries(*expected)

Checks whether the specified expected SQL queries match to those who actually have been emitted.

client_json_dict(meth, username, url, *data, **extra)

Send a POST or PUT to client with given username, url and data. The client is expected to respond with a JSON encoded response. Parse the response's content (which is expected to contain a dict), convert this dict to an AttrDict before returning it.

check_callback_dialog(meth, username, url, dialog, *data, **extra)

Check wether the given dialog runs as expected and return the final response as an AttrDict.

  • meth : should be self.client.get or self.client.post

  • username : the username

  • url : the url

  • dialog : a list of (expected, reply) tuples where expected it the expected response message and reply must be one of 'yes' or 'no' for all items expect for the last item where it must be None.

  • data : optional positional arguments to the meth

  • extra : optional keywords arguments to the meth

class lino.utils.djangotest.RemoteAuthTestCase(methodName='runTest')

Bases: lino.utils.djangotest.DjangoManageTestCase

Base class for tests that use remote http authentication. We override the __call__() method in order to simulate remote_user_header <lino.core.site.Site.remote_user_header> being set to 'REMOTE_USER'.

lino.utils.djangotest.TestCase

alias of lino.utils.djangotest.RemoteAuthTestCase

class lino.utils.djangotest.WebIndexTestCase(methodName='runTest')

Bases: lino.utils.djangotest.RemoteAuthTestCase

Designed to be just imported. No subclassing needed.

class lino.utils.djangotest.RestoreTestCase(methodName='runTest')

Bases: django.test.testcases.TransactionTestCase

Used for testing migrations from previous versions.

See Migration tests.

tested_versions = []

A list of strings, each string is a version for which there must be a migration dump created by makemigdump.