Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/filterhits/test/db_tests.py

Issue 4615801646612480: Issue 395 - Filter hits statistics backend (Closed)
Patch Set: Improvements regarding comments Created Feb. 17, 2015, 10:50 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sitescripts/filterhits/test/db_tests.py
diff --git a/sitescripts/filterhits/test/db_tests.py b/sitescripts/filterhits/test/db_tests.py
index 31e3dcfd6e681a420a3df62bcaf71548bf5fb401..96aa0590d846da3b8a685f10af899c3873c1f341 100644
--- a/sitescripts/filterhits/test/db_tests.py
+++ b/sitescripts/filterhits/test/db_tests.py
@@ -1,7 +1,7 @@
# coding: utf-8
# This file is part of the Adblock Plus web scripts,
-# Copyright (C) 2006-2014 Eyeo GmbH
+# Copyright (C) 2006-2015 Eyeo GmbH
#
# Adblock Plus is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
@@ -28,10 +28,9 @@ class DbTestCase(unittest.TestCase):
def clear_rows(self):
if self.db:
- db.write("DELETE FROM filters;")
+ db.write(self.db, "DELETE FROM filters")
def setUp(self):
- db.disconnect()
try:
self.config = get_config()
self.db = db.connect(
@@ -43,34 +42,32 @@ class DbTestCase(unittest.TestCase):
self.clear_rows()
def tearDown(self):
- self.clear_rows()
- db.disconnect()
+ if self.db:
+ self.clear_rows()
+ self.db.close()
+ self.db = None
def test_query_and_write(self):
if not self.db:
raise unittest.SkipTest("Not connected to test DB.")
- insert_sql = """INSERT INTO `filters` (filter, md5)
- VALUES ('%s', UNHEX(MD5(filter)));"""
- select_sql = "SELECT filter FROM filters ORDER BY filter ASC;"
+ insert_sql = """INSERT INTO `filters` (filter, sha1)
+ VALUES (%s, UNHEX(SHA1(filter)))"""
+ select_sql = "SELECT filter FROM filters ORDER BY filter ASC"
# Table should be empty to start with
- self.assertEqual(db.query(select_sql), ())
+ self.assertEqual(db.query(self.db, select_sql), ())
# Write some data and query it back
- db.write(insert_sql % "something")
- self.assertEqual(db.query(select_sql), ((u"something",),))
+ db.write(self.db, ((insert_sql, "something"),))
+ self.assertEqual(db.query(self.db, select_sql), ((u"something",),))
# Write an array of SQL strings
- db.write([insert_sql % "a", insert_sql % "b", insert_sql % "c"])
- self.assertEqual(db.query(select_sql), ((u"a",), (u"b",), (u"c",), (u"something",)))
- # Write an array of concatinated SQL strings
- db.write([insert_sql % "d" + insert_sql % "e"])
- self.assertEqual(db.query(select_sql), ((u"a",), (u"b",), (u"c",), (u"d",), (u"e",),
- (u"something",)))
+ db.write(self.db, ((insert_sql, "a"), (insert_sql, "b"), (insert_sql, "c")))
+ self.assertEqual(db.query(self.db, select_sql), ((u"a",), (u"b",), (u"c",), (u"something",)))
# Write a sequence of SQL but roll back when a problem arrises
with self.assertRaises(MySQLdb.ProgrammingError):
- db.write([insert_sql % "f" + insert_sql % "g", insert_sql % "h", "GFDGks"])
- self.assertEqual(db.query(select_sql), ((u"a",), (u"b",), (u"c",), (u"d",), (u"e",),
- (u"something",)))
+ db.write(self.db, ((insert_sql, "f"), (insert_sql, "g"), (insert_sql, "h"),
+ ("GFDGks",)))
+ self.assertEqual(db.query(self.db, select_sql), ((u"a",), (u"b",), (u"c",), (u"something",)))
if __name__ == '__main__':
unittest.main()

Powered by Google App Engine
This is Rietveld