Mercurial > getan
annotate test_data/getan_test_data.py @ 461:f1ec2d1357e2
TODO: (minor) removes leading tabs and one typo
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Wed, 21 Mar 2018 09:55:12 +0100 |
parents | a4f04440f045 |
children | 199b3e3657aa |
rev | line source |
---|---|
442
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
454
a4f04440f045
Improves coding style and phrasing.
Bernhard Reiter <bernhard@intevation.de>
parents:
453
diff
changeset
|
2 """ Create test data for getan (getan_test_data.db). |
450
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
3 |
454
a4f04440f045
Improves coding style and phrasing.
Bernhard Reiter <bernhard@intevation.de>
parents:
453
diff
changeset
|
4 Please delete existing getan_test_data.db. |
a4f04440f045
Improves coding style and phrasing.
Bernhard Reiter <bernhard@intevation.de>
parents:
453
diff
changeset
|
5 Execute getan_test_data.py to get the test database getan_test_data.db. |
a4f04440f045
Improves coding style and phrasing.
Bernhard Reiter <bernhard@intevation.de>
parents:
453
diff
changeset
|
6 Open getan with getan_test_data.db: getan /path/getan_test_data.db |
450
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
7 |
454
a4f04440f045
Improves coding style and phrasing.
Bernhard Reiter <bernhard@intevation.de>
parents:
453
diff
changeset
|
8 (c) 2018 Intevation GmbH |
a4f04440f045
Improves coding style and phrasing.
Bernhard Reiter <bernhard@intevation.de>
parents:
453
diff
changeset
|
9 Author: Magnus Schieder <magnus.schieder@intevation.de> |
a4f04440f045
Improves coding style and phrasing.
Bernhard Reiter <bernhard@intevation.de>
parents:
453
diff
changeset
|
10 |
a4f04440f045
Improves coding style and phrasing.
Bernhard Reiter <bernhard@intevation.de>
parents:
453
diff
changeset
|
11 This is Free Software licensed under the terms of GPLv3 or later. |
a4f04440f045
Improves coding style and phrasing.
Bernhard Reiter <bernhard@intevation.de>
parents:
453
diff
changeset
|
12 For details see LICENSE coming with the source of 'getan'. |
450
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
13 """ |
442
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
14 import sqlite3 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
15 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
16 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
17 def main(): |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
18 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
19 conn = sqlite3.connect("getan_test_data.db") |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
20 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
21 db = conn.cursor() |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
22 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
23 # create getan schema. |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
24 db.execute('''CREATE TABLE projects ( |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
25 id INTEGER PRIMARY KEY AUTOINCREMENT, |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
26 key VARCHAR(16) NOT NULL CONSTRAINT unique_key UNIQUE, |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
27 description VARCHAR(256), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
28 active BOOLEAN DEFAULT 1) |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
29 ''') |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
30 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
31 db.execute('''CREATE TABLE entries ( |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
32 id INTEGER PRIMARY KEY AUTOINCREMENT, |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
33 project_id INTEGER REFERENCES projects(id), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
34 start_time TIMESTAMP NOT NULL, |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
35 stop_time TIMESTAMP NOT NULL, |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
36 description VARCHAR(256), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
37 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
38 CHECK (strftime('%s', start_time) <= strftime('%s', stop_time))) |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
39 ''') |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
40 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
41 # List of projects. |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
42 # (key, 'description') |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
43 pro = [ |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
44 (1, 'pro1'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
45 (2, 'pro2'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
46 (3, 'pro3'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
47 ] |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
48 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
49 # List of entries with test data. |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
50 # (project_id, 'start_time', 'stop_time', 'description') |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
51 ent = [ |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
52 (2, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent9'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
53 (2, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent8'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
54 (2, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent7'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
55 (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent6'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
56 (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent5'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
57 (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent4'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
58 (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent3'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
59 (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent2'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
60 (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent1'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
61 ] |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
62 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
63 db.executemany("INSERT INTO projects(key, description) VALUES (?,?)", pro) |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
64 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
65 db.executemany('''INSERT INTO entries(project_id, start_time, stop_time, |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
66 description) VALUES (?,?,?,?)''', ent) |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
67 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
68 conn.commit() |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
69 conn.close() |
450
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
70 print("getan_test_data.db was created.") |
442
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
71 |
454
a4f04440f045
Improves coding style and phrasing.
Bernhard Reiter <bernhard@intevation.de>
parents:
453
diff
changeset
|
72 |
442
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
73 if __name__ == '__main__': |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
74 main() |