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

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

Issue 4615801646612480: Issue 395 - Filter hits statistics backend (Closed)
Patch Set: Addressed further comments from Sebastian. Created April 2, 2015, 10:13 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
« no previous file with comments | « sitescripts/filterhits/test/log_tests.py ('k') | sitescripts/filterhits/web/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/filterhits/test/test_helpers.py
diff --git a/sitescripts/filterhits/test/test_helpers.py b/sitescripts/filterhits/test/test_helpers.py
new file mode 100644
index 0000000000000000000000000000000000000000..ec617bea5fdf52e2bbd5ea36025409350ce5ad59
--- /dev/null
+++ b/sitescripts/filterhits/test/test_helpers.py
@@ -0,0 +1,70 @@
+# coding: utf-8
+
+# This file is part of the Adblock Plus web scripts,
+# 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
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+import tempfile
+import shutil
+import unittest
+
+import MySQLdb
+
+from sitescripts.filterhits import db
+from sitescripts.utils import get_config
+
+class FilterhitsTestCase(unittest.TestCase):
+ config = get_config()
+ _db = None
+ _live_config = {
+ "dbuser": config.get("filterhitstats", "dbuser"),
+ "dbpassword": config.get("filterhitstats", "dbpassword"),
+ "database": config.get("filterhitstats", "database"),
+ "log_dir": config.get("filterhitstats", "log_dir")
+ }
+ _test_config = {
+ "dbuser": config.get("filterhitstats", "test_dbuser"),
+ "dbpassword": config.get("filterhitstats", "test_dbpassword"),
+ "database": config.get("filterhitstats", "test_database")
+ }
+
+ def _clear_database(self):
+ db.write(self._db, (("DELETE FROM frequencies",), ("DELETE FROM filters",)))
+
+ @property
+ def db(self):
+ if (not self._db):
+ self._db = db.connect()
+ self._clear_database()
+ return self._db
+
+ def setUp(self):
+ # Set up a temporary log directory for testing
+ self.test_dir = tempfile.mkdtemp()
+ # Set up test config
+ for k, v in self._test_config.items():
+ self.config.set("filterhitstats", k, v)
+ self.config.set("filterhitstats", "log_dir", self.test_dir)
+
+ def tearDown(self):
+ # Clean the database and close our connection
+ if self._db:
+ self._clear_database()
+ self._db.close()
+ self._db = None
+ # Clean any generated logs
+ shutil.rmtree(self.test_dir, ignore_errors=True)
+ # Restore the configuration
+ for k, v in self._live_config.items():
+ self.config.set("filterhitstats", k, v)
« no previous file with comments | « sitescripts/filterhits/test/log_tests.py ('k') | sitescripts/filterhits/web/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld