changeset 443:dc79952b36b0

Merge
author Magnus Schieder <mschieder@intevation.de>
date Thu, 18 Jan 2018 11:29:29 +0100
parents 7125e67d5acb (diff) 7175ee3dbb0d (current diff)
children 08b61b78285d
files TODO
diffstat 1 files changed, 73 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_data/getan_test_data.py	Thu Jan 18 11:29:29 2018 +0100
@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+#
+# Author: Magnus Schieder <magnus.schieder@intevation.de>
+# (c) 2018 Intevation GmbH
+#
+# Program to create test data for getan (getan_test_data.db).
+# Please delete existing getan_test_data.db.
+# Open getan with getan_test_data.db: getan /path/getan_test_data.db
+#
+# This is Free Software licensed under the terms of GPLv3 or later.
+# For details see LICENSE coming with the source of 'getan'.
+#
+
+
+import sqlite3
+
+
+def main():
+
+    conn = sqlite3.connect("getan_test_data.db")
+
+    db = conn.cursor()
+
+    # create getan schema.
+    db.execute('''CREATE TABLE projects (
+            id          INTEGER PRIMARY KEY AUTOINCREMENT,
+            key         VARCHAR(16) NOT NULL CONSTRAINT unique_key UNIQUE,
+            description VARCHAR(256),
+            active      BOOLEAN DEFAULT 1)
+            ''')
+
+    db.execute('''CREATE TABLE entries (
+            id          INTEGER PRIMARY KEY AUTOINCREMENT,
+            project_id  INTEGER REFERENCES projects(id),
+            start_time  TIMESTAMP NOT NULL,
+            stop_time   TIMESTAMP NOT NULL,
+            description VARCHAR(256),
+
+            CHECK (strftime('%s', start_time) <= strftime('%s', stop_time)))
+            ''')
+
+    # List of projects.
+    # (key, 'description')
+    pro = [
+        (1, 'pro1'),
+        (2, 'pro2'),
+        (3, 'pro3'),
+        ]
+
+    # List of entries with test data.
+    # (project_id, 'start_time', 'stop_time', 'description')
+    ent = [
+        (2, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent9'),
+        (2, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent8'),
+        (2, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent7'),
+        (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent6'),
+        (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent5'),
+        (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent4'),
+        (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent3'),
+        (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent2'),
+        (1, '2018-01-01 01:01:01.0', '2018-01-01 02:01:01.0', 'ent1'),
+        ]
+
+    db.executemany("INSERT INTO projects(key, description) VALUES (?,?)", pro)
+
+    db.executemany('''INSERT INTO entries(project_id, start_time, stop_time,
+                    description) VALUES (?,?,?,?)''', ent)
+
+    conn.commit()
+    conn.close()
+
+if __name__ == '__main__':
+    main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)