ppf: Read test initialization/population script.
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Mon, 22 Aug 2011 07:50:29 +0000 (10:50 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Mon, 22 Aug 2011 08:28:02 +0000 (11:28 +0300)
ppf/new/tests/test_storage.py

index 45f6cc4..ef4b097 100644 (file)
@@ -302,14 +302,15 @@ class SQLiteDatabaseAccessTest(unittest.TestCase):
     # Class specific variables. Initialized in setUp, used throughout tests.
     database = "test.db"
     sql_create_script = "p2p-log-sqlite.sql"
+    sql_init_script = "p2p-init-test.sql"
     expected_swarms_count = 0
-    expected_btclients_count = 0
     expected_sessions_count = 0
     expected_statmsg_count = 0
     expected_verbmsg_count = 0
 
     def setUp(self):
         """ Create database file and instantiate objects. """
+        # Create database file. Create tables and indices.
         # TODO: Check exceptions.
         sql_create_script_path = os.path.join(os.path.dirname(__file__),
                 self.sql_create_script)
@@ -318,20 +319,21 @@ class SQLiteDatabaseAccessTest(unittest.TestCase):
         ret = os.waitpid(p.pid, 0)[1]
         f.close()
 
-        conn = sqlite3.connect(self.database)
-        cursor = conn.cursor()
+        # Populate database.
+        # TODO: Check exceptions.
+        sql_init_script_path = os.path.join(os.path.dirname(__file__),
+                self.sql_init_script)
+        f = open(sql_init_script_path, 'r')
+        p = subprocess.Popen(["sqlite3", self.database], stdin=f)
+        ret = os.waitpid(p.pid, 0)[1]
+        f.close()
 
-        #cursor.executescript(sql_init_script)
         # Initialize to number of table entries inserted in the init script.
         self.expected_swarms_count = 2
-        self.expected_btclients_count = 6
         self.expected_sessions_count = 2
         self.expected_statmsg_count = 2
         self.expected_verbmsg_count = 2
 
-        cursor.close()
-        conn.close()
-
     def tearDown(self):
         """ Close connection and remove database file. """
         os.remove(self.database)