annotate test_data/getan_test_data.py @ 448:ce70c76754e4

TODO: Adds a minor usability issue.
author Bernhard Reiter <bernhard@intevation.de>
date Thu, 18 Jan 2018 21:41:25 +0100
parents 7125e67d5acb
children 45b7b83efaed
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
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
2 #
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
3 # Author: Magnus Schieder <magnus.schieder@intevation.de>
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
4 # (c) 2018 Intevation GmbH
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
5 #
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
6 # Program to create test data for getan (getan_test_data.db).
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
7 # Please delete existing getan_test_data.db.
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
8 # Open getan with getan_test_data.db: getan /path/getan_test_data.db
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
9 #
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
10 # This is Free Software licensed under the terms of GPLv3 or later.
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
11 # For details see LICENSE coming with the source of 'getan'.
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
12 #
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
13
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
14
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
15 import sqlite3
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 def main():
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 conn = sqlite3.connect("getan_test_data.db")
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
21
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
22 db = conn.cursor()
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
23
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
24 # create getan schema.
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
25 db.execute('''CREATE TABLE projects (
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
26 id INTEGER PRIMARY KEY AUTOINCREMENT,
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
27 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
28 description VARCHAR(256),
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
29 active BOOLEAN DEFAULT 1)
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
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
32 db.execute('''CREATE TABLE entries (
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
33 id INTEGER PRIMARY KEY AUTOINCREMENT,
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
34 project_id INTEGER REFERENCES projects(id),
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
35 start_time TIMESTAMP NOT NULL,
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
36 stop_time TIMESTAMP NOT NULL,
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
37 description VARCHAR(256),
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
38
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
39 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
40 ''')
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 # List of projects.
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
43 # (key, 'description')
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
44 pro = [
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
45 (1, 'pro1'),
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
46 (2, 'pro2'),
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
47 (3, 'pro3'),
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
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
50 # List of entries with test data.
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
51 # (project_id, 'start_time', 'stop_time', 'description')
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
52 ent = [
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', 'ent9'),
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', 'ent8'),
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
55 (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
56 (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
57 (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
58 (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
59 (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
60 (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
61 (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
62 ]
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
63
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
64 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
65
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
66 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
67 description) VALUES (?,?,?,?)''', ent)
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 conn.commit()
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
70 conn.close()
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 if __name__ == '__main__':
7125e67d5acb dd getan testdata, add multi-selection Bug report.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
73 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)