lino.utils.test

Defines the DocTest and DemoTestCase classes.

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

Classes

CommonTestCase([methodName])

An extended django.test.TestCase.

DemoTestCase([methodName])

Used to define tests that are to be run directly in the demo database, without using the Django test runner (i.e.

DocTest([methodName])

Looks for a file "index.rst" in your project_dir and (if it exists) runs doctest on it.

HttpQuery(username, url_base, json_fields, ...)

WebIndexTestCase([methodName])

Test whether a runserver on this database would respond with 200 to an anonymous request.

class lino.utils.test.HttpQuery(username, url_base, json_fields, expected_rows, kwargs)

Bases: tuple

property expected_rows

Alias for field number 3

property json_fields

Alias for field number 2

property kwargs

Alias for field number 4

property url_base

Alias for field number 1

property username

Alias for field number 0

class lino.utils.test.CommonTestCase(methodName='runTest')

Bases: unittest.case.TestCase

An extended django.test.TestCase.

create_obj(model, **values)

Create the given database object, run full_clean() and save(), return the object.

Deprecated. Use lino.utils.instantiator.create_row() instead.

check_json_result(response, expected_keys=None, msg='')

Checks the result of response which is expected to return a JSON-encoded dictionary with the expected_keys.

assertEquivalent(a, b, report_plain=False)

Compares two strings a (expected) and b (got), ignoring whitespace repetitions and writing a logger message in case they are different. For long strings it's then more easy to find the difference.

request_PUT(url, data, **kw)

Sends a PUT request using Django's test client, overriding the content_type keyword. This is how ExtJS grids behave by default.

class lino.utils.test.DocTest(methodName='runTest')

Bases: unittest.case.TestCase

Looks for a file "index.rst" in your project_dir and (if it exists) runs doctest on it.

This is for tests to be run by the Django test runner on a temporary test database.

doctest_files = ['index.rst']

The files to be tested.

class lino.utils.test.DemoTestCase(methodName='runTest')

Bases: lino.utils.pythontest.TestCase, lino.utils.test.CommonTestCase

Used to define tests that are to be run directly in the demo database, without using the Django test runner (i.e. without creating a temporary test database).

It expects the demo database to be initialized, and it works only in an environment with lino.core.site.Site.remote_user_header set to 'REMOTE_USER'.

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

Bases: lino.utils.test.DemoTestCase

Test whether a runserver on this database would respond with 200 to an anonymous request.

You add this to your test suite by just importing it. No subclassing needed.

By convention this is done in a file test_webindex.py, i.e. when such a file is present in the tests directory of a demo project, this test is being run as part of test.