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

Unified Diff: sitescripts/filterhits/test/common_tests.py

Issue 4615801646612480: Issue 395 - Filter hits statistics backend (Closed)
Patch Set: Addressed more comments. Created March 2, 2015, 10:37 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/api_tests.py ('k') | sitescripts/filterhits/test/db_tests.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/filterhits/test/common_tests.py
diff --git a/sitescripts/filterhits/test/common_tests.py b/sitescripts/filterhits/test/common_tests.py
index 4487d56bb6c83ed27caa3fbe48f53cc69ae6d504..8b42354932d100c8b4916484b2ce013bf427d7bd 100644
--- a/sitescripts/filterhits/test/common_tests.py
+++ b/sitescripts/filterhits/test/common_tests.py
@@ -1,7 +1,7 @@
# coding: utf-8
# This file is part of the Adblock Plus web scripts,
-# Copyright (C) 2006-2014 Eyeo GmbH
+# 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
@@ -15,34 +15,10 @@
# 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 json, os, shutil, unittest
-from datetime import datetime
-import sitescripts.filterhits.common as common
+import json, os, shutil, time, unittest
+from sitescripts.filterhits import common
-valid_log_data = """{
- "version": 1,
- "timeSincePush": 12345,
- "addonName": "adblockplus",
- "addonVersion": "2.3.4",
- "application": "firefox",
- "applicationVersion": "31",
- "platform": "gecko",
- "platformVersion": "31",
- "filters": {
- "||example.com^": {
- "firstParty": {
- "example.com": {"hits": 12, "latest": 1413368627},
- "example.org": {"hits": 4, "latest": 1413368627}
- },
- "thirdParty": {
- "example.com": {"hits": 5, "latest": 123455489}
- },
- "subscriptions": ["EasyList", "EasyList Germany+EasyList"]
- }
- }
-}"""
-
-class Test(unittest.TestCase):
+class CommonTestCase(unittest.TestCase):
longMessage = True
maxDiff = None
@@ -53,37 +29,25 @@ class Test(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.test_dir, ignore_errors=True)
- def test_datetime_to_timestamp(self):
- examples = [
- [datetime(2014, 11, 27, 13, 58, 27), 1417096707],
- [datetime(2001, 1, 10, 13, 35, 21), 979133721]
- ]
- for dt, ts in examples:
- self.assertEqual(common.datetime_to_timestamp(dt), ts)
-
- def test_valid_log_data(self):
- data = json.loads(valid_log_data)
- self.assertEqual(common.valid_log_data(data), True)
- data.pop("version")
- self.assertEqual(common.valid_log_data(data), False)
-
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 = datetime.now().strftime("%Y-%m-%d")
+ todays_date = time.strftime('%Y-%m-%d', time.gmtime())
todays_folder = os.path.join(self.test_dir, todays_date)
self.assertEqual(os.path.exists(self.test_dir), False)
- common.log_filterhits({"some": "thing"}, self.test_dir)
+ log_file = common.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(), '{"some": "thing"}\n')
+ self.assertEqual(f.read(), '[%s] "a=1" {"some": "thing"}\n' % now)
- common.log_filterhits({"some": "thing"}, self.test_dir)
+ common.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)
« no previous file with comments | « sitescripts/filterhits/test/api_tests.py ('k') | sitescripts/filterhits/test/db_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld