| Left: | ||
| Right: |
| 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 os | |
| 19 import shutil | |
| 20 import time | |
| 21 import unittest | |
| 22 | |
| 23 from sitescripts.filterhits.test import test_helpers | |
| 24 from sitescripts.filterhits.web import submit | |
| 25 | |
| 26 class LogTestCase(unittest.TestCase): | |
| 27 longMessage = True | |
| 28 maxDiff = None | |
| 29 | |
| 30 def setUp(self): | |
| 31 self.config = test_helpers.setup_config() | |
|
Sebastian Noack
2015/03/31 07:55:21
Why do you assign this attribute? It doesn't seem
kzar
2015/03/31 09:48:56
Well the reason I've done it this way is that I'm
Sebastian Noack
2015/03/31 10:19:04
I see, but this is the wrong way doing it then. In
kzar
2015/03/31 10:27:47
I agree, I thought of doing it that way originally
Sebastian Noack
2015/03/31 10:32:23
Well, this documentation refers to setupClass/tear
kzar
2015/04/01 19:09:39
You were right, I've done it that way now and it w
| |
| 32 self.test_dir = self.config.get("filterhitstats", "log_dir") | |
| 33 | |
| 34 def tearDown(self): | |
| 35 test_helpers.restore_config() | |
| 36 | |
| 37 def test_log_filterhits(self): | |
| 38 def list_files(d): | |
| 39 return filter(os.path.isfile, [os.path.join(d, f) for f in os.listdir(d)]) | |
| 40 | |
| 41 todays_date = time.strftime('%Y-%m-%d', time.gmtime()) | |
| 42 todays_folder = os.path.join(self.test_dir, todays_date) | |
| 43 | |
| 44 # The temporary logging directory is created at the start of all tests but | |
| 45 # we want to test that the directory is created if it doesn't already exist. | |
| 46 # So we'll delete the directory here and make sure it's re-created later on. | |
| 47 shutil.rmtree(self.test_dir) | |
| 48 self.assertEqual(os.path.exists(self.test_dir), False) | |
| 49 | |
| 50 log_file = submit.log_filterhits({"some": "thing"}, self.test_dir, "a=1") | |
| 51 now = time.strftime('%d/%b/%Y:%H:%M:%S', time.gmtime()) | |
| 52 self.assertEqual(os.path.exists(self.test_dir), True) | |
| 53 self.assertEqual(os.path.exists(todays_folder), True) | |
| 54 self.assertEqual(len(list_files(todays_folder)), 1) | |
| 55 self.assertEqual(os.path.exists(log_file), True) | |
| 56 with open(list_files(todays_folder)[0], 'r') as f: | |
| 57 self.assertEqual(f.read(), '[%s] a=1\n{"some": "thing"}' % now) | |
| 58 | |
| 59 submit.log_filterhits({"some": "thing"}, self.test_dir, "") | |
| 60 self.assertEqual(os.path.exists(self.test_dir), True) | |
| 61 self.assertEqual(os.path.exists(todays_folder), True) | |
| 62 self.assertEqual(len(list_files(todays_folder)), 2) | |
| 63 | |
| 64 if __name__ == '__main__': | |
|
Sebastian Noack
2015/03/31 07:55:21
Nit: Consistent whitespaces please.
Sebastian Noack
2015/03/31 09:20:18
I meant quotes of course.
kzar
2015/03/31 09:48:56
Done.
| |
| 65 unittest.main() | |
| OLD | NEW |