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

Unified Diff: sitescripts/filterhits/test/log_tests.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/geometrical_mean_tests.py ('k') | sitescripts/filterhits/test/test_helpers.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/filterhits/test/log_tests.py
diff --git a/sitescripts/filterhits/test/log_tests.py b/sitescripts/filterhits/test/log_tests.py
new file mode 100644
index 0000000000000000000000000000000000000000..f49b6045c8fa5251f98cda3234b97c72d1a549e6
--- /dev/null
+++ b/sitescripts/filterhits/test/log_tests.py
@@ -0,0 +1,55 @@
+# 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 os
+import shutil
+import time
+import unittest
+
+from sitescripts.filterhits.test import test_helpers
+from sitescripts.filterhits.web import submit
+
+class LogTestCase(test_helpers.FilterhitsTestCase):
+ 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)
+
+ # The temporary logging directory is created at the start of all tests but
+ # we want to test that the directory is created if it doesn't already exist.
+ # So we'll delete the directory here and make sure it's re-created later on.
+ shutil.rmtree(self.test_dir)
+ self.assertEqual(os.path.exists(self.test_dir), False)
+
+ log_file = submit.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\n{"some": "thing"}' % now)
+
+ submit.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()
« no previous file with comments | « sitescripts/filterhits/test/geometrical_mean_tests.py ('k') | sitescripts/filterhits/test/test_helpers.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld