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

Side by Side Diff: sitescripts/filterhits/test/db_tests.py

Issue 29344572: Noissue - Removed obsolete sitescripts.filterhits package (Closed)
Patch Set: Created May 26, 2016, 12:05 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # coding: utf-8
2
3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2016 Eyeo GmbH
5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation.
9 #
10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17
18 import unittest
19
20 import MySQLdb
21
22 from sitescripts.filterhits.test import test_helpers
23 from sitescripts.filterhits import db
24
25
26 class DbTestCase(test_helpers.FilterhitsTestCase):
27 longMessage = True
28 maxDiff = None
29
30 def test_query_and_write(self):
31 insert_sql = """INSERT INTO `filters` (filter, sha1)
32 VALUES (%s, UNHEX(SHA1(filter)))"""
33 select_sql = "SELECT filter FROM filters ORDER BY filter ASC"
34
35 # Table should be empty to start with
36 self.assertEqual(db.query(self.db, select_sql), ())
37 # Write some data and query it back
38 db.write(self.db, ((insert_sql, "something"),))
39 self.assertEqual(db.query(self.db, select_sql), ((u"something",),))
40 # Write an array of SQL strings
41 db.write(self.db, ((insert_sql, "a"), (insert_sql, "b"), (insert_sql, "c ")))
42 self.assertEqual(db.query(self.db, select_sql), ((u"a",), (u"b",), (u"c" ,), (u"something",)))
43 # Write a sequence of SQL but roll back when a problem arrises
44 with self.assertRaises(MySQLdb.ProgrammingError):
45 db.write(self.db, ((insert_sql, "f"), (insert_sql, "g"), (insert_sql , "h"),
46 ("GFDGks",)))
47 self.assertEqual(db.query(self.db, select_sql), ((u"a",), (u"b",), (u"c" ,), (u"something",)))
48
49 if __name__ == "__main__":
50 unittest.main()
OLDNEW
« no previous file with comments | « sitescripts/filterhits/test/api_tests.py ('k') | sitescripts/filterhits/test/geometrical_mean_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld