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

Delta Between Two Patch Sets: sitescripts/filterhits/test/log_tests.py

Issue 4615801646612480: Issue 395 - Filter hits statistics backend (Closed)
Left Patch Set: Addressed comments. Created Feb. 24, 2015, 5:59 p.m.
Right Patch Set: Addressed further comments from Sebastian. Created April 2, 2015, 10:13 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/filterhits/test/geometrical_mean_tests.py ('k') | sitescripts/filterhits/test/test_helpers.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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(test_helpers.FilterhitsTestCase):
27 def test_log_filterhits(self):
28 def list_files(d):
29 return filter(os.path.isfile, [os.path.join(d, f) for f in os.listdir(d)])
30
31 todays_date = time.strftime("%Y-%m-%d", time.gmtime())
32 todays_folder = os.path.join(self.test_dir, todays_date)
33
34 # The temporary logging directory is created at the start of all tests but
35 # we want to test that the directory is created if it doesn't already exist.
36 # So we'll delete the directory here and make sure it's re-created later on.
37 shutil.rmtree(self.test_dir)
38 self.assertEqual(os.path.exists(self.test_dir), False)
39
40 log_file = submit.log_filterhits({"some": "thing"}, self.test_dir, "a=1")
41 now = time.strftime("%d/%b/%Y:%H:%M:%S", time.gmtime())
42 self.assertEqual(os.path.exists(self.test_dir), True)
43 self.assertEqual(os.path.exists(todays_folder), True)
44 self.assertEqual(len(list_files(todays_folder)), 1)
45 self.assertEqual(os.path.exists(log_file), True)
46 with open(list_files(todays_folder)[0], "r") as f:
47 self.assertEqual(f.read(), '[%s] a=1\n{"some": "thing"}' % now)
48
49 submit.log_filterhits({"some": "thing"}, self.test_dir, "")
50 self.assertEqual(os.path.exists(self.test_dir), True)
51 self.assertEqual(os.path.exists(todays_folder), True)
52 self.assertEqual(len(list_files(todays_folder)), 2)
53
54 if __name__ == "__main__":
55 unittest.main()
LEFTRIGHT

Powered by Google App Engine
This is Rietveld