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

Side by Side Diff: sitescripts/filterhits/test/log_tests.py

Issue 4615801646612480: Issue 395 - Filter hits statistics backend (Closed)
Patch Set: Addressed Sebastian's and Wladimir's comments. Created March 27, 2015, 3:08 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(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
19 import os
20 import shutil
21 import time
22 import unittest
23
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.test_dir = os.path.join(os.path.dirname(__file__), "temp")
32 shutil.rmtree(self.test_dir, ignore_errors=True)
33
34 def tearDown(self):
35 shutil.rmtree(self.test_dir, ignore_errors=True)
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 self.assertEqual(os.path.exists(self.test_dir), False)
45
46 log_file = submit.log_filterhits({"some": "thing"}, self.test_dir, "a=1")
47 now = time.strftime('%d/%b/%Y:%H:%M:%S', time.gmtime())
48 self.assertEqual(os.path.exists(self.test_dir), True)
49 self.assertEqual(os.path.exists(todays_folder), True)
50 self.assertEqual(len(list_files(todays_folder)), 1)
51 self.assertEqual(os.path.exists(log_file), True)
52 with open(list_files(todays_folder)[0], 'r') as f:
53 self.assertEqual(f.read(), '[%s] "a=1"\n{"some": "thing"}\n' % now)
54
55 submit.log_filterhits({"some": "thing"}, self.test_dir, "")
56 self.assertEqual(os.path.exists(self.test_dir), True)
57 self.assertEqual(os.path.exists(todays_folder), True)
58 self.assertEqual(len(list_files(todays_folder)), 2)
59
60 if __name__ == '__main__':
61 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld