summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSiegfried-Angel Gevatter Pujals <siegfried@gevatter.com>2012-09-14 22:21:23 +0200
committerSiegfried-Angel Gevatter Pujals <siegfried@gevatter.com>2012-09-14 22:21:23 +0200
commitad1f6d382f5f813dfe364fe8d3de6ae901ccf5d8 (patch)
tree3147f9434317aed57a982b6e1298096d8ee0fe99 /test
parentfb930841790b008e9d9d932d50822eda6125d71b (diff)
downloadzeitgeist-ad1f6d382f5f813dfe364fe8d3de6ae901ccf5d8.tar.gz
Start working on upgrade tests...
Diffstat (limited to 'test')
-rw-r--r--test/data/databases/071.sql213
-rw-r--r--test/data/databases/README14
-rw-r--r--test/data/upgrade_test.js53
-rw-r--r--test/dbus/Makefile.am1
-rw-r--r--test/dbus/testutils.py4
-rw-r--r--test/dbus/upgrade-test.py65
6 files changed, 348 insertions, 2 deletions
diff --git a/test/data/databases/071.sql b/test/data/databases/071.sql
new file mode 100644
index 00000000..200b5a95
--- /dev/null
+++ b/test/data/databases/071.sql
@@ -0,0 +1,213 @@
+PRAGMA foreign_keys=OFF;
+BEGIN TRANSACTION;
+CREATE TABLE uri
+ (id INTEGER PRIMARY KEY, value VARCHAR UNIQUE);
+INSERT INTO "uri" VALUES(1,'file:///tmp');
+INSERT INTO "uri" VALUES(2,'http://www.google.de');
+INSERT INTO "uri" VALUES(4,'file:///tmp/foo.txt');
+CREATE TABLE interpretation
+ (id INTEGER PRIMARY KEY, value VARCHAR UNIQUE);
+INSERT INTO "interpretation" VALUES(1,'stfu:OpenEvent');
+INSERT INTO "interpretation" VALUES(2,'stfu:Document');
+INSERT INTO "interpretation" VALUES(3,'stfu:ShalalalalaEvent');
+INSERT INTO "interpretation" VALUES(4,'stfu:Image');
+INSERT INTO "interpretation" VALUES(5,'stfu:FoobarEvent');
+INSERT INTO "interpretation" VALUES(6,'stfu:Test');
+CREATE TABLE manifestation
+ (id INTEGER PRIMARY KEY, value VARCHAR UNIQUE);
+INSERT INTO "manifestation" VALUES(1,'stfu:YourActivity');
+INSERT INTO "manifestation" VALUES(2,'stfu:File');
+INSERT INTO "manifestation" VALUES(3,'stfu:BooActivity');
+INSERT INTO "manifestation" VALUES(4,'stfu:Ethereal');
+INSERT INTO "manifestation" VALUES(5,'stfu:SomeActivity');
+CREATE TABLE mimetype
+ (id INTEGER PRIMARY KEY, value VARCHAR UNIQUE);
+INSERT INTO "mimetype" VALUES(1,'meat/raw');
+INSERT INTO "mimetype" VALUES(2,'text/plain');
+CREATE TABLE actor
+ (id INTEGER PRIMARY KEY, value VARCHAR UNIQUE);
+INSERT INTO "actor" VALUES(1,'firefox');
+INSERT INTO "actor" VALUES(2,'geany');
+INSERT INTO "actor" VALUES(3,'gedit');
+CREATE TABLE text
+ (id INTEGER PRIMARY KEY, value VARCHAR UNIQUE);
+INSERT INTO "text" VALUES(1,'this item has not text... rly!');
+CREATE TABLE payload
+ (id INTEGER PRIMARY KEY, value BLOB);
+CREATE TABLE storage
+ (id INTEGER PRIMARY KEY,
+ value VARCHAR UNIQUE,
+ state INTEGER);
+INSERT INTO "storage" VALUES(1,'368c991f-8b59-4018-8130-3ce0ec944157',NULL);
+CREATE TABLE event (
+ id INTEGER,
+ timestamp INTEGER,
+ interpretation INTEGER,
+ manifestation INTEGER,
+ actor INTEGER,
+ payload INTEGER,
+ subj_id INTEGER,
+ subj_interpretation INTEGER,
+ subj_manifestation INTEGER,
+ subj_origin INTEGER,
+ subj_mimetype INTEGER,
+ subj_text INTEGER,
+ subj_storage INTEGER,
+ CONSTRAINT interpretation_fk FOREIGN KEY(interpretation)
+ REFERENCES interpretation(id) ON DELETE CASCADE,
+ CONSTRAINT manifestation_fk FOREIGN KEY(manifestation)
+ REFERENCES manifestation(id) ON DELETE CASCADE,
+ CONSTRAINT actor_fk FOREIGN KEY(actor)
+ REFERENCES actor(id) ON DELETE CASCADE,
+ CONSTRAINT payload_fk FOREIGN KEY(payload)
+ REFERENCES payload(id) ON DELETE CASCADE,
+ CONSTRAINT subj_id_fk FOREIGN KEY(subj_id)
+ REFERENCES uri(id) ON DELETE CASCADE,
+ CONSTRAINT subj_interpretation_fk FOREIGN KEY(subj_interpretation)
+ REFERENCES interpretation(id) ON DELETE CASCADE,
+ CONSTRAINT subj_manifestation_fk FOREIGN KEY(subj_manifestation)
+ REFERENCES manifestation(id) ON DELETE CASCADE,
+ CONSTRAINT subj_origin_fk FOREIGN KEY(subj_origin)
+ REFERENCES uri(id) ON DELETE CASCADE,
+ CONSTRAINT subj_mimetype_fk FOREIGN KEY(subj_mimetype)
+ REFERENCES mimetype(id) ON DELETE CASCADE,
+ CONSTRAINT subj_text_fk FOREIGN KEY(subj_text)
+ REFERENCES text(id) ON DELETE CASCADE,
+ CONSTRAINT subj_storage_fk FOREIGN KEY(subj_storage)
+ REFERENCES storage(id) ON DELETE CASCADE,
+ CONSTRAINT unique_event UNIQUE (timestamp, interpretation, manifestation, actor, subj_id)
+ );
+INSERT INTO "event" VALUES(1,1347652042579,1,1,1,'',2,2,2,1,1,1,1);
+INSERT INTO "event" VALUES(2,143,3,3,2,'',4,4,4,1,2,1,1);
+INSERT INTO "event" VALUES(3,133,5,5,3,'',2,6,2,1,2,1,1);
+CREATE TABLE schema_version
+ (schema VARCHAR PRIMARY KEY ON CONFLICT REPLACE, version INT);
+INSERT INTO "schema_version" VALUES('core',3);
+CREATE UNIQUE INDEX uri_value ON uri(value);
+CREATE UNIQUE INDEX interpretation_value
+ ON interpretation(value);
+CREATE UNIQUE INDEX manifestation_value
+ ON manifestation(value);
+CREATE UNIQUE INDEX mimetype_value
+ ON mimetype(value);
+CREATE UNIQUE INDEX actor_value
+ ON actor(value);
+CREATE UNIQUE INDEX text_value
+ ON text(value);
+CREATE UNIQUE INDEX storage_value
+ ON storage(value);
+CREATE INDEX event_id
+ ON event(id);
+CREATE INDEX event_timestamp
+ ON event(timestamp);
+CREATE INDEX event_interpretation
+ ON event(interpretation);
+CREATE INDEX event_manifestation
+ ON event(manifestation);
+CREATE INDEX event_actor
+ ON event(actor);
+CREATE INDEX event_subj_id
+ ON event(subj_id);
+CREATE INDEX event_subj_interpretation
+ ON event(subj_interpretation);
+CREATE INDEX event_subj_manifestation
+ ON event(subj_manifestation);
+CREATE INDEX event_subj_origin
+ ON event(subj_origin);
+CREATE INDEX event_subj_mimetype
+ ON event(subj_mimetype);
+CREATE INDEX event_subj_text
+ ON event(subj_text);
+CREATE INDEX event_subj_storage
+ ON event(subj_storage);
+CREATE TRIGGER fkdc_event_interpretation
+ BEFORE DELETE ON event
+ WHEN ((SELECT COUNT(*) FROM event WHERE interpretation=OLD.interpretation) < 2)
+ BEGIN
+ DELETE FROM interpretation WHERE id=OLD.interpretation;
+ END;
+CREATE TRIGGER fkdc_event_subj_interpretation
+ BEFORE DELETE ON event
+ WHEN ((SELECT COUNT(*) FROM event WHERE subj_interpretation=OLD.subj_interpretation) < 2)
+ BEGIN
+ DELETE FROM interpretation WHERE id=OLD.subj_interpretation;
+ END;
+CREATE TRIGGER fkdc_event_manifestation
+ BEFORE DELETE ON event
+ WHEN ((SELECT COUNT(*) FROM event WHERE manifestation=OLD.manifestation) < 2)
+ BEGIN
+ DELETE FROM manifestation WHERE id=OLD.manifestation;
+ END;
+CREATE TRIGGER fkdc_event_subj_manifestation
+ BEFORE DELETE ON event
+ WHEN ((SELECT COUNT(*) FROM event WHERE subj_manifestation=OLD.subj_manifestation) < 2)
+ BEGIN
+ DELETE FROM manifestation WHERE id=OLD.subj_manifestation;
+ END;
+CREATE TRIGGER fkdc_event_actor
+ BEFORE DELETE ON event
+ WHEN ((SELECT COUNT(*) FROM event WHERE actor=OLD.actor) < 2)
+ BEGIN
+ DELETE FROM actor WHERE id=OLD.actor;
+ END;
+CREATE TRIGGER fkdc_event_payload
+ BEFORE DELETE ON event
+ WHEN ((SELECT COUNT(*) FROM event WHERE payload=OLD.payload) < 2)
+ BEGIN
+ DELETE FROM payload WHERE id=OLD.payload;
+ END;
+CREATE TRIGGER fkdc_event_subj_mimetype
+ BEFORE DELETE ON event
+ WHEN ((SELECT COUNT(*) FROM event WHERE subj_mimetype=OLD.subj_mimetype) < 2)
+ BEGIN
+ DELETE FROM mimetype WHERE id=OLD.subj_mimetype;
+ END;
+CREATE TRIGGER fkdc_event_subj_text
+ BEFORE DELETE ON event
+ WHEN ((SELECT COUNT(*) FROM event WHERE subj_text=OLD.subj_text) < 2)
+ BEGIN
+ DELETE FROM text WHERE id=OLD.subj_text;
+ END;
+CREATE TRIGGER fkdc_event_subj_storage
+ BEFORE DELETE ON event
+ WHEN ((SELECT COUNT(*) FROM event WHERE subj_storage=OLD.subj_storage) < 2)
+ BEGIN
+ DELETE FROM storage WHERE id=OLD.subj_storage;
+ END;
+CREATE TRIGGER fkdc_event_uri_1
+ BEFORE DELETE ON event
+ WHEN ((SELECT COUNT(*) FROM event WHERE subj_id=OLD.subj_id OR subj_origin=OLD.subj_id) < 2)
+ BEGIN
+ DELETE FROM uri WHERE id=OLD.subj_id;
+ END;
+CREATE TRIGGER fkdc_event_uri_2
+ BEFORE DELETE ON event
+ WHEN ((SELECT COUNT(*) FROM event WHERE subj_id=OLD.subj_origin OR subj_origin=OLD.subj_origin) < 2)
+ BEGIN
+ DELETE FROM uri WHERE id=OLD.subj_origin;
+ END;
+CREATE VIEW event_view AS
+ SELECT event.id,
+ event.timestamp,
+ event.interpretation,
+ event.manifestation,
+ event.actor,
+ (SELECT value FROM payload WHERE payload.id=event.payload)
+ AS payload,
+ (SELECT value FROM uri WHERE uri.id=event.subj_id)
+ AS subj_uri,
+ event.subj_id, -- #this directly points to an id in the uri table
+ event.subj_interpretation,
+ event.subj_manifestation,
+ event.subj_origin,
+ (SELECT value FROM uri WHERE uri.id=event.subj_origin)
+ AS subj_origin_uri,
+ event.subj_mimetype,
+ (SELECT value FROM text WHERE text.id = event.subj_text)
+ AS subj_text,
+ (SELECT value FROM storage
+ WHERE storage.id=event.subj_storage) AS subj_storage,
+ (SELECT state FROM storage
+ WHERE storage.id=event.subj_storage) AS subj_storage_state
+ FROM event;
+COMMIT;
diff --git a/test/data/databases/README b/test/data/databases/README
new file mode 100644
index 00000000..f2e859f2
--- /dev/null
+++ b/test/data/databases/README
@@ -0,0 +1,14 @@
+These SQL files can be used to reconstruct databases corresponding to
+old Zeitgeist databases, containing the events from upgrade_test.js.
+
+The procedure for creating or updating a SQL file is:
+ - Download the old Zeitgeist version from Launchpad
+ - Run ./configure and make
+ - Copy run_fake_zeitgeist.sh into the directory and adapt it to
+ work with that Zeitgeist version (eg., for Python versions,
+ change "./src/zeitgeist-daemon" to "./zeitgeist-daemon").
+ - Run the modified copy of run_fake_zeitgeist.sh
+ - In the subshell, move into an up-to-date Zeitgeist checkout and run:
+ $ ./tools/development/insert_events_from_json.py test/data/upgrade_test.js
+ - Now move back into the temporary directory, and run:
+ $ sqlite3 activity.sqlite .dump
diff --git a/test/data/upgrade_test.js b/test/data/upgrade_test.js
new file mode 100644
index 00000000..b4091dcc
--- /dev/null
+++ b/test/data/upgrade_test.js
@@ -0,0 +1,53 @@
+[
+ {
+ "timestamp" : 1347652042579,
+ "interpretation" : "stfu:OpenEvent",
+ "manifestation" : "stfu:YourActivity",
+ "actor" : "firefox",
+ "subjects" : [
+ {
+ "uri" : "http://www.google.de",
+ "interpretation" : "stfu:Document",
+ "manifestation" : "stfu:File",
+ "origin" : "file:///tmp",
+ "mimetype" : "meat/raw",
+ "text" : "this item has not text... rly!",
+ "storage" : "368c991f-8b59-4018-8130-3ce0ec944157"
+ }
+ ]
+ },{
+ "timestamp" : 143,
+ "interpretation" : "stfu:ShalalalalaEvent",
+ "manifestation" : "stfu:BooActivity",
+ "actor" : "geany",
+ "origin" : "belly",
+ "subjects" : [
+ {
+ "uri" : "file:///tmp/foo.txt",
+ "interpretation" : "stfu:Image",
+ "manifestation" : "stfu:Ethereal",
+ "origin" : "file:///tmp",
+ "mimetype" : "text/plain",
+ "text" : "this item has not text... rly!",
+ "storage" : "368c991f-8b59-4018-8130-3ce0ec944157"
+ }
+ ]
+ },{
+ "timestamp" : 133,
+ "interpretation" : "stfu:FoobarEvent",
+ "manifestation" : "stfu:SomeActivity",
+ "actor" : "gedit",
+ "origin" : "big bang",
+ "subjects" : [
+ {
+ "uri" : "http://www.google.de",
+ "interpretation" : "stfu:Test",
+ "manifestation" : "stfu:File",
+ "origin" : "file:///tmp",
+ "mimetype" : "text/plain",
+ "text" : "this item has not text... rly!",
+ "storage" : "368c991f-8b59-4018-8130-3ce0ec944157"
+ }
+ ]
+ }
+]
diff --git a/test/dbus/Makefile.am b/test/dbus/Makefile.am
index 81cb1746..0a2a6748 100644
--- a/test/dbus/Makefile.am
+++ b/test/dbus/Makefile.am
@@ -8,6 +8,7 @@ EXTRA_DIST = \
monitor-test.py \
remote-test.py \
testutils.py \
+ upgrade-test.py \
run-all-tests.py \
$(NULL)
diff --git a/test/dbus/testutils.py b/test/dbus/testutils.py
index e964b574..b8f0dd89 100644
--- a/test/dbus/testutils.py
+++ b/test/dbus/testutils.py
@@ -164,13 +164,13 @@ class RemoteTestCase (unittest.TestCase):
os.kill(self.daemon.pid, kill_signal)
return self.daemon.wait()
- def setUp(self):
+ def setUp(self, database_path=None):
assert self.daemon is None
assert self.client is None
self.env = os.environ.copy()
self.datapath = tempfile.mkdtemp(prefix="zeitgeist.datapath.")
self.env.update({
- "ZEITGEIST_DATABASE_PATH": ":memory:",
+ "ZEITGEIST_DATABASE_PATH": database_path or ":memory:",
"ZEITGEIST_DATA_PATH": self.datapath,
"XDG_CACHE_HOME": os.path.join(self.datapath, "cache"),
})
diff --git a/test/dbus/upgrade-test.py b/test/dbus/upgrade-test.py
new file mode 100644
index 00000000..6d75ada6
--- /dev/null
+++ b/test/dbus/upgrade-test.py
@@ -0,0 +1,65 @@
+#! /usr/bin/python
+# -.- coding: utf-8 -.-
+
+# upgrade-test.py
+#
+# Copyright © 2012 Collabora Ltd.
+# By Seif Lotfy <seif@lotfy.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import sqlite3
+import tempfile
+import unittest
+
+from zeitgeist.datamodel import *
+
+import testutils
+from testutils import parse_events, import_events
+
+class ZeitgeistUpgradeTest(testutils.RemoteTestCase):
+
+ def setUp(self):
+ self._db_file = tempfile.mktemp(".sqlite", prefix="zeitgeist.upgrade.")
+ # Do nothing, functions should call prepare() instead
+
+ def tearDown(self):
+ super(ZeitgeistUpgradeTest, self).tearDown()
+ os.remove(self._db_file)
+
+ def prepare(self, from_version):
+ # Create initial database
+ con = sqlite3.connect(self._db_file)
+ initial_sql = open("test/data/databases/%s.sql" % from_version).read()
+ con.cursor().executescript(initial_sql)
+ del con
+
+ # Launch Zeitgeist, using the created database
+ super(ZeitgeistUpgradeTest, self).setUp(self._db_file)
+
+ def sanity_check(self):
+ events = self.findEventsForTemplatesAndWait([])
+ x = ""
+ for event in events:
+ x += " - %s\n" % event.subjects[0].uri
+ raise ValueError, x
+ self.assertEquals(len(events), 3)
+
+ def testUpgradeFrom071(self):
+ self.prepare("071")
+ self.sanity_check()
+
+if __name__ == "__main__":
+ unittest.main()