Mercurial > getan
annotate test_data/getan_test_data.py @ 453:ceb5909b106e
Backed out changeset ab3c63877862
Because Magnus accidently committed some experimental code pieces.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Fri, 26 Jan 2018 17:23:01 +0100 |
parents | ab3c63877862 |
children | a4f04440f045 |
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 |
453
ceb5909b106e
Backed out changeset ab3c63877862
Bernhard Reiter <bernhard@intevation.de>
parents:
452
diff
changeset
|
2 |
ceb5909b106e
Backed out changeset ab3c63877862
Bernhard Reiter <bernhard@intevation.de>
parents:
452
diff
changeset
|
3 # Program to 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
|
4 |
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
5 """ |
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
6 Author: Magnus Schieder <magnus.schieder@intevation.de> |
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
7 (c) 2018 Intevation GmbH |
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
8 |
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
9 Please delete existing getan_test_data.db. |
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
10 Execute getan_test_data.py to get the test database getan_test_data.db. |
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
11 Open getan with getan_test_data.db: getan /path/getan_test_data.db |
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
12 |
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
13 This is Free Software licensed under the terms of GPLv3 or later. |
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
14 For details see LICENSE coming with the source of 'getan'. |
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
15 """ |
442
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 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
18 import sqlite3 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
19 |
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 def main(): |
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 conn = sqlite3.connect("getan_test_data.db") |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
24 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
25 db = conn.cursor() |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
26 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
27 # create getan schema. |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
28 db.execute('''CREATE TABLE projects ( |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
29 id INTEGER PRIMARY KEY AUTOINCREMENT, |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
30 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
|
31 description VARCHAR(256), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
32 active BOOLEAN DEFAULT 1) |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
33 ''') |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
34 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
35 db.execute('''CREATE TABLE entries ( |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
36 id INTEGER PRIMARY KEY AUTOINCREMENT, |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
37 project_id INTEGER REFERENCES projects(id), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
38 start_time TIMESTAMP NOT NULL, |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
39 stop_time TIMESTAMP NOT NULL, |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
40 description VARCHAR(256), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
41 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
42 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
|
43 ''') |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
44 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
45 # List of projects. |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
46 # (key, 'description') |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
47 pro = [ |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
48 (1, 'pro1'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
49 (2, 'pro2'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
50 (3, 'pro3'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
51 ] |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
52 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
53 # List of entries with test data. |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
54 # (project_id, 'start_time', 'stop_time', 'description') |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
55 ent = [ |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
56 (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
|
57 (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
|
58 (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
|
59 (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
|
60 (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
|
61 (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
|
62 (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
|
63 (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
|
64 (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
|
65 ] |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
66 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
67 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
|
68 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
69 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
|
70 description) VALUES (?,?,?,?)''', ent) |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
71 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
72 conn.commit() |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
73 conn.close() |
450
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
74 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
|
75 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
76 if __name__ == '__main__': |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
77 main() |