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) |