OLD | NEW |
(Empty) | |
| 1 # coding: utf-8 |
| 2 |
| 3 # This file is part of the Adblock Plus web scripts, |
| 4 # Copyright (C) 2006-2015 Eyeo GmbH |
| 5 # |
| 6 # Adblock Plus is free software: you can redistribute it and/or modify |
| 7 # it under the terms of the GNU General Public License version 3 as |
| 8 # published by the Free Software Foundation. |
| 9 # |
| 10 # Adblock Plus is distributed in the hope that it will be useful, |
| 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 # GNU General Public License for more details. |
| 14 # |
| 15 # You should have received a copy of the GNU General Public License |
| 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
| 18 import json, os, shutil, time, unittest |
| 19 from sitescripts.filterhits import common |
| 20 |
| 21 class CommonTestCase(unittest.TestCase): |
| 22 longMessage = True |
| 23 maxDiff = None |
| 24 |
| 25 def setUp(self): |
| 26 self.test_dir = os.path.join(os.path.dirname(__file__), "temp") |
| 27 shutil.rmtree(self.test_dir, ignore_errors=True) |
| 28 |
| 29 def tearDown(self): |
| 30 shutil.rmtree(self.test_dir, ignore_errors=True) |
| 31 |
| 32 def test_log_filterhits(self): |
| 33 def list_files(d): |
| 34 return filter(os.path.isfile, [os.path.join(d, f) for f in os.listdir(d)]) |
| 35 |
| 36 todays_date = time.strftime('%Y-%m-%d', time.gmtime()) |
| 37 todays_folder = os.path.join(self.test_dir, todays_date) |
| 38 |
| 39 self.assertEqual(os.path.exists(self.test_dir), False) |
| 40 |
| 41 log_file = common.log_filterhits({"some": "thing"}, self.test_dir, "a=1") |
| 42 now = time.strftime('%d/%b/%Y:%H:%M:%S', time.gmtime()) |
| 43 self.assertEqual(os.path.exists(self.test_dir), True) |
| 44 self.assertEqual(os.path.exists(todays_folder), True) |
| 45 self.assertEqual(len(list_files(todays_folder)), 1) |
| 46 self.assertEqual(os.path.exists(log_file), True) |
| 47 with open(list_files(todays_folder)[0], 'r') as f: |
| 48 self.assertEqual(f.read(), '[%s] "a=1" {"some": "thing"}\n' % now) |
| 49 |
| 50 common.log_filterhits({"some": "thing"}, self.test_dir, "") |
| 51 self.assertEqual(os.path.exists(self.test_dir), True) |
| 52 self.assertEqual(os.path.exists(todays_folder), True) |
| 53 self.assertEqual(len(list_files(todays_folder)), 2) |
| 54 |
| 55 if __name__ == '__main__': |
| 56 unittest.main() |
OLD | NEW |