#! /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()

@@ -1762,72 +1762,275 @@
     
-x = %22%22%0A        for event in events:%0A            x += %22 - %25s%5Cn%22 %25
+self.assertEquals(len(events), 3)%0A%0A        # Introduced in Zeitgeist 0.8.0:%0A        #  - event.origin%0A        #  - subject.current_uri%0A        #  - subject.storage%0A        for event in events:%0A            self.assertEquals(event.origin, %22%22)%0A            for subject in
  eve
@@ -2044,15 +2044,9 @@
 ects
-%5B0%5D.uri
+:
 %0A   
@@ -2054,28 +2054,8 @@
     
-raise ValueError, x%0A
     
@@ -2072,39 +2072,127 @@
 ssertEquals(
-len(events), 3)
+subject.current_uri, subject.uri)%0A%0A        # Introduced in Bluebird Alpha 2:%0A        #  - WebDataObject
 %0A%0A    def te

Add some assert...