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: Create temporary log directory with tempfile module for tests. Created March 30, 2015, 7 p.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..49a2304e23280f09200f2518c8e5b16e14ac55d7
--- /dev/null
+++ b/sitescripts/filterhits/test/test_helpers.py
@@ -0,0 +1,41 @@
+# 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
+
+from sitescripts.utils import get_config
+
+config = get_config()
+live_config = {
+ "database": config.get("filterhitstats", "database"),
+ "log_dir": config.get("filterhitstats", "log_dir")
+}
+test_config = {
+ "database": config.get("filterhitstats", "test_database"),
+ "log_dir": tempfile.mkdtemp()
Wladimir Palant 2015/03/30 19:07:04 This will create the directory exactly once rather
kzar 2015/03/30 19:29:03 Ugh sorry, good point. (I didn't notice this as I'
+}
+
+def setup_config():
+ config.set("filterhitstats", "database", test_config["database"])
+ config.set("filterhitstats", "log_dir", test_config["log_dir"])
+ return config
+
+def restore_config():
+ config.set("filterhitstats", "database", live_config["database"])
+ config.set("filterhitstats", "log_dir", live_config["log_dir"])
+ shutil.rmtree(test_config["log_dir"], ignore_errors=True)
« 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