Mercurial > getan
annotate test_data/getan_test_data.py @ 568:e7b36e596751 tip
Last week's year is not necessarily today's year
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 03 Jan 2022 11:37:31 +0100 |
parents | 199b3e3657aa |
children |
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 |
499
199b3e3657aa
Every minute the time of the current entry is saved.
Magnus Schieder <mschieder@intevation.de>
parents:
454
diff
changeset
|
41 db.execute('''CREATE TABLE recover ( |
199b3e3657aa
Every minute the time of the current entry is saved.
Magnus Schieder <mschieder@intevation.de>
parents:
454
diff
changeset
|
42 id INTEGER PRIMARY KEY, |
199b3e3657aa
Every minute the time of the current entry is saved.
Magnus Schieder <mschieder@intevation.de>
parents:
454
diff
changeset
|
43 project_id INTEGER REFERENCES projects(id), |
199b3e3657aa
Every minute the time of the current entry is saved.
Magnus Schieder <mschieder@intevation.de>
parents:
454
diff
changeset
|
44 start_time TIMESTAMP NOT NULL, |
199b3e3657aa
Every minute the time of the current entry is saved.
Magnus Schieder <mschieder@intevation.de>
parents:
454
diff
changeset
|
45 stop_time TIMESTAMP NOT NULL, |
199b3e3657aa
Every minute the time of the current entry is saved.
Magnus Schieder <mschieder@intevation.de>
parents:
454
diff
changeset
|
46 description VARCHAR(256), |
199b3e3657aa
Every minute the time of the current entry is saved.
Magnus Schieder <mschieder@intevation.de>
parents:
454
diff
changeset
|
47 |
199b3e3657aa
Every minute the time of the current entry is saved.
Magnus Schieder <mschieder@intevation.de>
parents:
454
diff
changeset
|
48 CHECK (strftime('%s', start_time) <= strftime('%s', stop_time))) |
199b3e3657aa
Every minute the time of the current entry is saved.
Magnus Schieder <mschieder@intevation.de>
parents:
454
diff
changeset
|
49 ''') |
199b3e3657aa
Every minute the time of the current entry is saved.
Magnus Schieder <mschieder@intevation.de>
parents:
454
diff
changeset
|
50 |
442
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
51 # List of projects. |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
52 # (key, 'description') |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
53 pro = [ |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
54 (1, 'pro1'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
55 (2, 'pro2'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
56 (3, 'pro3'), |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
57 ] |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
58 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
59 # List of entries with test data. |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
60 # (project_id, 'start_time', 'stop_time', 'description') |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
61 ent = [ |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
62 (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
|
63 (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
|
64 (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
|
65 (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
|
66 (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
|
67 (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
|
68 (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
|
69 (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
|
70 (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
|
71 ] |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
72 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
73 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
|
74 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
75 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
|
76 description) VALUES (?,?,?,?)''', ent) |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
77 |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
78 conn.commit() |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
79 conn.close() |
450
45b7b83efaed
Prepares for release 2.2.
Magnus Schieder <mschieder@intevation.de>
parents:
442
diff
changeset
|
80 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
|
81 |
454
a4f04440f045
Improves coding style and phrasing.
Bernhard Reiter <bernhard@intevation.de>
parents:
453
diff
changeset
|
82 |
442
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
83 if __name__ == '__main__': |
7125e67d5acb
dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
84 main() |