Index: sitescripts/filterhits/test/common_tests.py |
diff --git a/sitescripts/filterhits/test/common_tests.py b/sitescripts/filterhits/test/common_tests.py |
index fe408d5c01bb4a19845138b1d79bd69821033680..3b9410b16d74d0f769b54f5cad95938d6c686144 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,33 +15,9 @@ |
# 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 json, os, shutil, time, unittest |
import sitescripts.filterhits.common as 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": 1413368627000}, |
- "example.org": {"hits": 4, "latest": 1413368627000} |
- }, |
- "thirdParty": { |
- "example.com": {"hits": 5, "latest": 123455489000} |
- }, |
- "subscriptions": ["EasyList", "EasyList Germany+EasyList"] |
- } |
- } |
-}""" |
- |
class CommonTestCase(unittest.TestCase): |
longMessage = True |
maxDiff = None |
@@ -53,31 +29,17 @@ class CommonTestCase(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) |
log_file = common.log_filterhits({"some": "thing"}, self.test_dir, "a=1") |
- now = datetime.now().strftime('%d/%b/%Y:%H:%M:%S %z') |
+ 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) |