Пример #1
0
class SQLWorkerTest(unittest.TestCase):
    def setUp(self):
        self.queue = Queue.Queue()
        self.sql = SQLWorker(dbfile='/tmp/test.db',
                             in_queue=self.queue)
        self.conn = self.sql.get_sql_connection()

    def tearDown(self):
        self.conn.close()
        os.remove('/tmp/test.db')

    def test_get_sql_connection(self):
        conn = self.sql.get_sql_connection('/tmp/test2.db')
        self.assertNotEqual(conn, None)
        conn.close()
        os.remove('/tmp/test2.db')

    def test_dump_page(self):
        page = {'url': '1', 'content': '2', 'lastmodified': '3',
                'etag': '4', 'redirect': '5'}
        self.sql.get_sql_connection('/tmp/test.db')
        self.sql.dump_page(page)
        conn = sqlite3.connect('/tmp/test.db')
        curs = conn.cursor()
        curs.execute("select etag from pages where url='1';")
        a = curs.fetchone()
        curs.close()
        conn.close()
        self.assertEqual(a, (u'4',))
Пример #2
0
 def setUp(self):
     self.queue = Queue.Queue()
     self.sql = SQLWorker(dbfile='/tmp/test.db',
                          in_queue=self.queue)
     self.conn = self.sql.get_sql_connection()