From dd5d3252fa53af0777df245b2e36a3cce41ee52f Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Wed, 17 Aug 2011 18:00:30 +0300 Subject: [PATCH] ppf: Add partial tests for accees.py. --- ppf/db/tests/test_access_sqlite.py | 93 +++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 22 deletions(-) diff --git a/ppf/db/tests/test_access_sqlite.py b/ppf/db/tests/test_access_sqlite.py index be558a8..bc0d59c 100644 --- a/ppf/db/tests/test_access_sqlite.py +++ b/ppf/db/tests/test_access_sqlite.py @@ -1,6 +1,7 @@ import unittest import os import sqlite3 +import access sql_script = """ drop table if exists status_messages; @@ -99,7 +100,6 @@ class AccessTest(unittest.TestCase): def tearDown(self): os.remove(self.database) - pass def test_run(self): conn = sqlite3.connect(self.database) @@ -112,34 +112,77 @@ class AccessTest(unittest.TestCase): conn.close() def test_connect(self): - self.assertEqual(True, True) + dba = access.SQLiteDatabaseAccess() + conn = dba.connect(self.database) + + self.assertNotEqual(conn, None) + + dba.disconnect() def test_disconnect(self): - self.assertEqual(True, True) + dba = access.DatabaseAccess() + conn = dba.connect(self.database) + dba.disconnect() + + self.assertEqual(conn, None) def test_get_cursor(self): - self.assertEqual(True, True) + dba = access.SQLiteDatabaseAccess() + conn = dba.connect(self.database) + cursor = dba.get_cursor() - def test_get_connection(self): - self.assertEqual(True, True) + self.assertNotEqual(cursor, None) + + dba.disconnect() + + def test_select_swarms(self): + # Needs fixing. An entry should be added in the startup script. + dba = access.SQLiteDatabaseAccess() + dba.connect(self.database) + cursor = dba.select_swarms(False) + + num_rows = 0 + for row in cursor: + num_rows = num_rows+1 + + self.assertEqual(num_rows, 0) def test_insert_swarms_row(self): - self.assertEqual(True, True) + dba = access.SQLiteDatabaseAccess() + dba.connect(self.database) + dba.insert_swarms_row(["fedora.torrent", 10000, "btex", "isohunt"]) + cursor = dba.select_swarms(False) + + num_rows = 0 + for row in cursor: + num_rows = num_rows+1 + + self.assertEqual(num_rows, 1) def test_insert_swarms(self): - self.assertEqual(True, True) + dba = access.SQLiteDatabaseAccess() + dba.connect(self.database) + dba.insert_swarms("fedora.torrent", 10000, "btex", "isohunt") + cursor = dba.select_swarms(False) - def test_select_swarms(self): - self.assertEqual(True, True) + num_rows = 0 + for row in cursor: + num_rows = num_rows+1 + + self.assertEqual(num_rows, 1) def test_delete_swarms(self): - self.assertEqual(True, True) + dba = access.SQLiteDatabaseAccess() + dba.connect(self.database) + dba.insert_swarms("fedora.torrent", 10000, "btex", "isohunt") + dba.delete_swarms() + cursor = dba.select_swarms(False) - def test_insert_btclients_row(self): - self.assertEqual(True, True) + num_rows = 0 + for row in cursor: + num_rows = num_rows+1 - def test_insert_btclients(self): - self.assertEqual(True, True) + self.assertEqual(num_rows, 0) def test_select_btclients(self): self.assertEqual(True, True) @@ -150,10 +193,10 @@ class AccessTest(unittest.TestCase): def test_select_btclients_id_by_name(self): self.assertEqual(True, True) - def test_insert_client_sessions_row(self): + def test_insert_btclients_row(self): self.assertEqual(True, True) - def test_insert_client_sessions(self): + def test_insert_btclients(self): self.assertEqual(True, True) def test_select_client_sessions_by_id(self): @@ -162,22 +205,31 @@ class AccessTest(unittest.TestCase): def test_select_client_sessions_by_swarm(self): self.assertEqual(True, True) + def test_insert_client_sessions_row(self): + self.assertEqual(True, True) + + def test_insert_client_sessions(self): + self.assertEqual(True, True) + def test_delete_client_sessions_by_id(self): self.assertEqual(True, True) def test_delete_client_sessions_by_swarm(self): self.assertEqual(True, True) + def test_select_status_messages(self): + self.assertEqual(True, True) + def test_insert_status_messages_row(self): self.assertEqual(True, True) def test_insert_status_messages(self): self.assertEqual(True, True) - def test_select_status_messages(self): + def test_delete_status_messages(self): self.assertEqual(True, True) - def test_delete_status_messages(self): + def test_select_verbose_messages(self): self.assertEqual(True, True) def test_insert_verbose_messages_row(self): @@ -186,9 +238,6 @@ class AccessTest(unittest.TestCase): def test_insert_verbose_messages(self): self.assertEqual(True, True) - def test_select_verbose_messages(self): - self.assertEqual(True, True) - def test_delete_verbose_messages(self): self.assertEqual(True, True) -- 2.20.1