From 087ecc02794e60a980400a3be863aceb39961405 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Tue, 16 Aug 2011 19:16:14 +0300 Subject: [PATCH] Move main() in access.py to tests/test_acces.py. --- ppf/db/access.py | 60 ++----------------------------------- ppf/db/tests/test_access.py | 56 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 ppf/db/tests/test_access.py diff --git a/ppf/db/access.py b/ppf/db/access.py index e32a4e1..4a3827a 100644 --- a/ppf/db/access.py +++ b/ppf/db/access.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import sys import sqlite3 import os.path @@ -107,11 +105,6 @@ class DatabaseAccess: pass -class MySQLDatabaseAccess(DatabaseAccess): - """ - SQLite interface for databae access. - """ - class SQLiteDatabaseAccess(DatabaseAccess): """ SQLite interface for databae access. @@ -334,7 +327,6 @@ class SQLiteDatabaseAccess(DatabaseAccess): values += (value, ) query = query.strip('and ') - #print query, values self.cursor.execute(query, values) if show == True: @@ -356,55 +348,7 @@ class SQLiteDatabaseAccess(DatabaseAccess): print("[status_messages]An error ocurred: ", e.args[0]) -def main(): - +class MySQLDatabaseAccess(DatabaseAccess): """ - Test case + MySQL interface for databae access. """ - - if len(sys.argv) != 2: - print "Usage: python DatabaseAccess dbfile" - sys.exit(2) - - dba = DatabaseAccess(sys.argv[1]) - - dba.connect() - - for t in [('DarkKnight', '123000', 'experiment', 'TVTorrents'), - ('Fedora', '1024', 'experiment', 'local'), - ('Pulp Fiction', '102400', 'streaming', 'isohunt'), - ('Karaoke', 'anaaremere', 'streaming', 'local'), - ]: - dba.insert_swarms_row(t) - - for t in [('Tribler', 'Python', '1', '1'), - ('libtorrent', 'C++', '1', '0'), - ('Vuze', 'Java', '1', '0'), - ('Transmission', 'C', 'asa', '0'), - ]: - dba.insert_btclients_row(t) - - for t in [('1', '2', 'Linux', '2.6.26', '512', '1500', '141.85.224.205', '50500', '512', '64', '2455125.02409722'), - ('3', '4', 'Linux', '2.6.26', '512', '1500', '141.85.224.209', '40400', '512', '64', '2455125.03174769'), - ]: - dba.insert_client_sessions_row(t) - - for t in [('1', '2455128.10', '222', '0', '213', '56', '200', '300', '121.324'), - ('6', '2455128.10', '222', '0', '213', '56', '200', '300', '121.324'), - ]: - dba.insert_status_messages_row(t) - - for t in [('1', '2455128.121295811', '0', '127.0.0.1', '1345', '0', '3', '4', '13', '777'), - ('4', '2455128.121295811', '1', '127.0.0.1', '1345', '0', '3', '4', '13', '777'), - ]: - dba.insert_verbose_messages_row(t) - - dba.get_status() - - dba.select_btclient_by_name("Tribler") - - dba.disconnect() - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/ppf/db/tests/test_access.py b/ppf/db/tests/test_access.py new file mode 100644 index 0000000..3e41fd2 --- /dev/null +++ b/ppf/db/tests/test_access.py @@ -0,0 +1,56 @@ +import unittest +import os + +class AccessTest(unittest.TestCase): + def main(): + + """ + Test case + """ + + if len(sys.argv) != 2: + print "Usage: python DatabaseAccess dbfile" + sys.exit(2) + + dba = DatabaseAccess(sys.argv[1]) + + dba.connect() + + for t in [('DarkKnight', '123000', 'experiment', 'TVTorrents'), + ('Fedora', '1024', 'experiment', 'local'), + ('Pulp Fiction', '102400', 'streaming', 'isohunt'), + ('Karaoke', 'anaaremere', 'streaming', 'local'), + ]: + dba.insert_swarms_row(t) + + for t in [('Tribler', 'Python', '1', '1'), + ('libtorrent', 'C++', '1', '0'), + ('Vuze', 'Java', '1', '0'), + ('Transmission', 'C', 'asa', '0'), + ]: + dba.insert_btclients_row(t) + + for t in [('1', '2', 'Linux', '2.6.26', '512', '1500', '141.85.224.205', '50500', '512', '64', '2455125.02409722'), + ('3', '4', 'Linux', '2.6.26', '512', '1500', '141.85.224.209', '40400', '512', '64', '2455125.03174769'), + ]: + dba.insert_client_sessions_row(t) + + for t in [('1', '2455128.10', '222', '0', '213', '56', '200', '300', '121.324'), + ('6', '2455128.10', '222', '0', '213', '56', '200', '300', '121.324'), + ]: + dba.insert_status_messages_row(t) + + for t in [('1', '2455128.121295811', '0', '127.0.0.1', '1345', '0', '3', '4', '13', '777'), + ('4', '2455128.121295811', '1', '127.0.0.1', '1345', '0', '3', '4', '13', '777'), + ]: + dba.insert_verbose_messages_row(t) + + dba.get_status() + + dba.select_btclient_by_name("Tribler") + + dba.disconnect() + + +if __name__ == "__main__": + unittest.main() -- 2.20.1