Mercurial > getan
comparison test_data/getan_test_data.py @ 442:7125e67d5acb
dd getan testdata, add multi-selection Bug report.
* add /test_data/getan_test_data.py to create a new getan database
with test data.
* update report 20170317 BER. Add a guide to recreating the bug.
* TDOD: Fix the bug.
author | Magnus Schieder <mschieder@intevation.de> |
---|---|
date | Thu, 18 Jan 2018 11:14:24 +0100 |
parents | |
children | 45b7b83efaed |
comparison
equal
deleted
inserted
replaced
440:f441913a5cdc | 442:7125e67d5acb |
---|---|
1 #!/usr/bin/env python3 | |
2 # | |
3 # Author: Magnus Schieder <magnus.schieder@intevation.de> | |
4 # (c) 2018 Intevation GmbH | |
5 # | |
6 # Program to create test data for getan (getan_test_data.db). | |
7 # Please delete existing getan_test_data.db. | |
8 # Open getan with getan_test_data.db: getan /path/getan_test_data.db | |
9 # | |
10 # This is Free Software licensed under the terms of GPLv3 or later. | |
11 # For details see LICENSE coming with the source of 'getan'. | |
12 # | |
13 | |
14 | |
15 import sqlite3 | |
16 | |
17 | |
18 def main(): | |
19 | |
20 conn = sqlite3.connect("getan_test_data.db") | |
21 | |
22 db = conn.cursor() | |
23 | |
24 # create getan schema. | |
25 db.execute('''CREATE TABLE projects ( | |
26 id INTEGER PRIMARY KEY AUTOINCREMENT, | |
27 key VARCHAR(16) NOT NULL CONSTRAINT unique_key UNIQUE, | |
28 description VARCHAR(256), | |
29 active BOOLEAN DEFAULT 1) | |
30 ''') | |
31 | |
32 db.execute('''CREATE TABLE entries ( | |
33 id INTEGER PRIMARY KEY AUTOINCREMENT, | |
34 project_id INTEGER REFERENCES projects(id), | |
35 start_time TIMESTAMP NOT NULL, | |
36 stop_time TIMESTAMP NOT NULL, | |
37 description VARCHAR(256), | |
38 | |
39 CHECK (strftime('%s', start_time) <= strftime('%s', stop_time))) | |
40 ''') | |
41 | |
42 # List of projects. | |
43 # (key, 'description') | |
44 pro = [ | |
45 (1, 'pro1'), | |
46 (2, 'pro2'), | |
47 (3, 'pro3'), | |
48 ] | |
49 | |
50 # List of entries with test data. | |
51 # (project_id, 'start_time', 'stop_time', 'description') | |
52 ent = [ | |
53 (2, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent9'), | |
54 (2, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent8'), | |
55 (2, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent7'), | |
56 (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent6'), | |
57 (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent5'), | |
58 (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent4'), | |
59 (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent3'), | |
60 (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent2'), | |
61 (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent1'), | |
62 ] | |
63 | |
64 db.executemany("INSERT INTO projects(key, description) VALUES (?,?)", pro) | |
65 | |
66 db.executemany('''INSERT INTO entries(project_id, start_time, stop_time, | |
67 description) VALUES (?,?,?,?)''', ent) | |
68 | |
69 conn.commit() | |
70 conn.close() | |
71 | |
72 if __name__ == '__main__': | |
73 main() |