]> git.openstreetmap.org Git - nominatim.git/blob - tests/README.md
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / tests / README.md
1 This directory contains functional tests for the Nominatim API,
2 for the import/update from osm files and for indexing.
3
4 The tests use the lettuce framework (http://lettuce.it/) and
5 nose (https://nose.readthedocs.org). API tests are meant to be run
6 against a Nominatim installation with a complete planet-wide
7 setup based on a fairly recent planet. If you only have an
8 excerpt, some of the API tests may fail. Database tests can be
9 run without having a database installed.
10
11 Prerequisites
12 =============
13
14  * lettuce framework (http://lettuce.it/)
15  * nose (https://nose.readthedocs.org)
16  * pytidylib (http://countergram.com/open-source/pytidylib)
17  * haversine (https://github.com/mapado/haversine)
18
19 Usage
20 =====
21
22  * get prerequisites
23
24      [sudo] pip install lettuce nose pytidylib haversine
25
26  * run the tests
27
28      NOMINATIM_SERVER=http://your.nominatim.instance/ lettuce features
29
30 The tests can be configured with a set of environment variables:
31
32  * `NOMINATIM_SERVER` - URL of the nominatim instance (API tests)
33  * `NOMINATIM_DIR` - source directory of Nominatim (import tests)
34  * `TEMPLATE_DB` - name of template database used as a skeleton for
35                    the test databases (db tests)
36  * `TEST_DB` - name of test database (db tests)
37  * `NOMINATIM_SETTINGS` - file to write temporary Nominatim settings to (db tests)
38  * `NOMINATIM_REUSE_TEMPLATE` - if defined, the template database will not be
39                                 deleted after the test runs and reused during
40                                 the next run. This speeds up tests considerably
41                                 but might lead to outdated errors for some
42                                 changes in the database layout.
43  * `NOMINATIM_KEEP_SCENARIO_DB` - if defined, the test database will not be
44                                   dropped after a test is finished. Should
45                                   only be used if one single scenario is run,
46                                   otherwise the result is undefined.
47  * `LOGLEVEL` - set to 'debug' to get more verbose output (only works properly
48                 when output to a logfile is configured)
49  * `LOGFILE` - sends debug output to the given file
50
51 Writing Tests
52 =============
53
54 The following explanation assume that the reader is familiar with the lettuce
55 notations of features, scenarios and steps.
56
57 All possible steps can be found in the `steps` directory and should ideally
58 be documented.
59
60
61 API Tests (`features/api`)
62 --------------------------
63
64 These tests are meant to test the different API calls and their parameters.
65
66 There are two kind of steps defined for these tests: 
67 request setup steps (see `steps/api_setup.py`) 
68 and steps for checking results (see `steps/api_result.py`).
69
70 Each scenario follows this simple sequence of steps:
71
72   1. One or more steps to define parameters and HTTP headers of the request.
73      These are cumulative, so you can use multiple steps.
74   2. A single step to call the API. This sends a HTTP request to the configured
75      server and collects the answer. The cached parameters will be deleted,
76      to ensure that the setup works properly with scenario outlines.
77   3. As many result checks as necessary. The result remains cached, so that
78      multiple tests can be added here.
79
80 Indexing Tests (`features/db`)
81 ---------------------------------------------------
82
83 These tests check the import and update of the Nominatim database. They do not
84 test the correctness of osm2pgsql. Each test will write some data into the `place`
85 table (and optionally `the planet_osm_*` tables if required) and then run
86 Nominatim's processing functions on that.
87
88 These tests need to create their own test databases. By default they will be
89 called `test_template_nominatim` and `test_nominatim`. Names can be changed with
90 the environment variables `TEMPLATE_DB` and `TEST_DB`. The user running the tests
91 needs superuser rights for postgres.
92
93
94 Import Tests (`features/osm2pgsql`)
95 -----------------------------------
96
97 These tests check that data is imported correctly into the place table. They
98 use the same template database as the Indexing tests, so the same remarks apply.