Index: sitescripts/filterhits/test/common_tests.py |
diff --git a/sitescripts/filterhits/test/common_tests.py b/sitescripts/filterhits/test/common_tests.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8b42354932d100c8b4916484b2ce013bf427d7bd |
--- /dev/null |
+++ b/sitescripts/filterhits/test/common_tests.py |
@@ -0,0 +1,56 @@ |
+# 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 json, os, shutil, time, unittest |
+from sitescripts.filterhits import common |
+ |
+class CommonTestCase(unittest.TestCase): |
+ longMessage = True |
+ maxDiff = None |
+ |
+ def setUp(self): |
+ self.test_dir = os.path.join(os.path.dirname(__file__), "temp") |
+ shutil.rmtree(self.test_dir, ignore_errors=True) |
+ |
+ def tearDown(self): |
+ shutil.rmtree(self.test_dir, ignore_errors=True) |
+ |
+ def test_log_filterhits(self): |
+ def list_files(d): |
+ return filter(os.path.isfile, [os.path.join(d, f) for f in os.listdir(d)]) |
+ |
+ todays_date = time.strftime('%Y-%m-%d', time.gmtime()) |
+ todays_folder = os.path.join(self.test_dir, todays_date) |
+ |
+ self.assertEqual(os.path.exists(self.test_dir), False) |
+ |
+ log_file = common.log_filterhits({"some": "thing"}, self.test_dir, "a=1") |
+ now = time.strftime('%d/%b/%Y:%H:%M:%S', time.gmtime()) |
+ self.assertEqual(os.path.exists(self.test_dir), True) |
+ self.assertEqual(os.path.exists(todays_folder), True) |
+ self.assertEqual(len(list_files(todays_folder)), 1) |
+ self.assertEqual(os.path.exists(log_file), True) |
+ with open(list_files(todays_folder)[0], 'r') as f: |
+ self.assertEqual(f.read(), '[%s] "a=1" {"some": "thing"}\n' % now) |
+ |
+ common.log_filterhits({"some": "thing"}, self.test_dir, "") |
+ self.assertEqual(os.path.exists(self.test_dir), True) |
+ self.assertEqual(os.path.exists(todays_folder), True) |
+ self.assertEqual(len(list_files(todays_folder)), 2) |
+ |
+if __name__ == '__main__': |
+ unittest.main() |