Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

lino.utils.test

Defines some TestCase classes that are meant for writing general Python test cases (not Django test cases, which are defined in lino.utils.djangotest).

Classes

CommonTestCase([methodName])

A unittest.TestCase (not a django.test.TestCase) that starts a Django test client on a demo database populated using pm prep.

DemoTestCase([methodName])

Base class for unit tests that are meant to run directly in a demo project that has been initialized with pm prep.

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, ...)

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

Bases: tuple

expected_rows

Alias for field number 3

json_fields

Alias for field number 2

kwargs

Alias for field number 4

url_base

Alias for field number 1

username

Alias for field number 0

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

Bases: TestCase

A unittest.TestCase (not a django.test.TestCase) that starts a Django test client on a demo database populated using pm prep.

create_obj(model, **values)

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

This is here for backwards compatibility. New code should 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: 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: TestCase, CommonTestCase

Base class for unit tests that are meant to run directly in a demo project that has been initialized with pm prep.

It expects the demo database to be initialized, and it should be read-only, i.e. not modify any data.

This is used by the demotest command.

login(username, pwd)

Invoke the lino.modlib.users.SignIn action for the given username and password. Unlike django.test.Client.force_login(), this simulates a real login, which later causes Lino to build the JS cache for this user.