Index: sitescripts/filterhits/test/geometrical_mean_tests.py |
diff --git a/sitescripts/filterhits/test/geometrical_mean_tests.py b/sitescripts/filterhits/test/geometrical_mean_tests.py |
index 33f64f115fcf447c946dbac7f50e19622ae18377..5c4227ba34abf7c2e5dc46ca2cb358baf7c219a8 100644 |
--- a/sitescripts/filterhits/test/geometrical_mean_tests.py |
+++ b/sitescripts/filterhits/test/geometrical_mean_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 |
@@ -79,10 +79,10 @@ class GeometricalMeanTestCase(unittest.TestCase): |
def clear_rows(self): |
if self.db: |
- db.write("DELETE FROM geometrical_mean; DELETE FROM filters;") |
+ db.write(self.db, (("DELETE FROM geometrical_mean",), |
+ ("DELETE FROM filters",))) |
def setUp(self): |
- db.disconnect() |
try: |
self.config = get_config() |
self.db = db.connect( |
@@ -94,8 +94,10 @@ class GeometricalMeanTestCase(unittest.TestCase): |
self.clear_rows() |
def tearDown(self): |
- self.clear_rows() |
- db.disconnect() |
+ if self.db: |
+ self.clear_rows() |
+ self.db.close() |
+ self.db = None |
def test_calculations(self): |
if not self.db: |
@@ -104,83 +106,83 @@ class GeometricalMeanTestCase(unittest.TestCase): |
interval = 86400 |
# Tables should be empty to start with |
- self.assertEqual(db.query("SELECT * FROM filters;"), ()) |
- self.assertEqual(db.query("SELECT * FROM geometrical_mean;"), ()) |
+ self.assertEqual(db.query(self.db, "SELECT * FROM filters"), ()) |
+ self.assertEqual(db.query(self.db, "SELECT * FROM geometrical_mean"), ()) |
# First batch |
- db.write(geometrical_mean.update(interval, test_data[0])) |
- self.assertEqual(db.query("SELECT * FROM filters;"), |
- (("cb4a637e0176010f51f86bb085c7b955".decode("hex"), |
+ db.write(self.db, geometrical_mean.update(interval, test_data[0])) |
+ self.assertEqual(db.query(self.db, "SELECT * FROM filters"), |
+ (("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), |
u"##.top-box-right-ad"),)) |
self.assertEqual( |
- db.query("SELECT * FROM geometrical_mean;"), |
- (("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"acxiom-online.com", |
+ db.query(self.db, "SELECT * FROM geometrical_mean"), |
+ (("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"acxiom-online.com", |
6L, datetime.utcfromtimestamp(1414817340948 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"demdex.net", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"demdex.net", |
36L, datetime.utcfromtimestamp(1414838712373 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"doubleclick.net", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"doubleclick.net", |
26L, datetime.utcfromtimestamp(1414823430333 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"google.com", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"google.com", |
50L, datetime.utcfromtimestamp(1414849084678 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"yahoo.com", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"yahoo.com", |
14L, datetime.utcfromtimestamp(1414859271125 / 1000)))) |
# Second batch |
- db.write(geometrical_mean.update(interval, test_data[1])) |
- self.assertEqual(db.query("SELECT * FROM filters;"), |
- (("cb4a637e0176010f51f86bb085c7b955".decode("hex"), |
+ db.write(self.db, geometrical_mean.update(interval, test_data[1])) |
+ self.assertEqual(db.query(self.db, "SELECT * FROM filters"), |
+ (("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), |
u"##.top-box-right-ad"),)) |
self.assertEqual( |
- db.query("SELECT * FROM geometrical_mean;"), |
- (("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"acxiom-online.com", |
+ db.query(self.db, "SELECT * FROM geometrical_mean"), |
+ (("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"acxiom-online.com", |
6L, datetime.utcfromtimestamp(1414817340948 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"adsymptotic.com", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"adsymptotic.com", |
49L, datetime.utcfromtimestamp(1414953943015 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"amazon.com", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"amazon.com", |
2L, datetime.utcfromtimestamp(1414913563746 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"demdex.net", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"demdex.net", |
36L, datetime.utcfromtimestamp(1414838712373 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"doubleclick.net", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"doubleclick.net", |
26L, datetime.utcfromtimestamp(1414823430333 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"google.com", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"google.com", |
self.geometrical(interval, 21, 1414953920364, 50, 1414849084678), |
datetime.utcfromtimestamp(1414953920364 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"live.com", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"live.com", |
34L, datetime.utcfromtimestamp(1414916268769 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"yahoo.com", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"yahoo.com", |
self.geometrical(interval, 27, 1414917270343, 14, 1414859271125), |
datetime.utcfromtimestamp(1414917270343 / 1000)))) |
# Third batch |
- db.write(geometrical_mean.update(interval, test_data[2])) |
- self.assertEqual(db.query("SELECT * FROM filters;"), |
- (("23b2670782157a39ee4454a32155f299".decode("hex"), |
+ db.write(self.db, geometrical_mean.update(interval, test_data[2])) |
+ self.assertEqual(db.query(self.db, "SELECT * FROM filters"), |
+ (("22de8d2ba8429eb170a0ece6ea7a426f7b22e574".decode("hex"), |
u"stevedeace.com##.topAddHolder"), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), |
u"##.top-box-right-ad"))) |
self.assertEqual( |
- db.query("SELECT * FROM geometrical_mean;"), |
- (("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"acxiom-online.com", |
+ db.query(self.db, "SELECT * FROM geometrical_mean"), |
+ (("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"acxiom-online.com", |
6L, datetime.utcfromtimestamp(1414817340948 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"adsymptotic.com", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"adsymptotic.com", |
self.geometrical(interval, 15, 1414994112862, 49, 1414953943015), |
datetime.utcfromtimestamp(1414994112862 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"amazon.com", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"amazon.com", |
2L, datetime.utcfromtimestamp(1414913563746 / 1000)), |
- ("23b2670782157a39ee4454a32155f299".decode("hex"), u'amazonaws.com', |
+ ("22de8d2ba8429eb170a0ece6ea7a426f7b22e574".decode("hex"), u'amazonaws.com', |
18L, datetime.utcfromtimestamp(1414977342966 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"demdex.net", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"demdex.net", |
36L, datetime.utcfromtimestamp(1414838712373 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"doubleclick.net", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"doubleclick.net", |
26L, datetime.utcfromtimestamp(1414823430333 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"google.com", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"google.com", |
self.geometrical(interval, 14, 1415008533089, |
self.geometrical(interval, 21, 1414953920364, |
50, 1414849084678), |
1414953920364), |
datetime.utcfromtimestamp(1415008533089 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"live.com", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"live.com", |
34L, datetime.utcfromtimestamp(1414916268769 / 1000)), |
- ("23b2670782157a39ee4454a32155f299".decode("hex"), u'mathtag.com', |
+ ("22de8d2ba8429eb170a0ece6ea7a426f7b22e574".decode("hex"), u'mathtag.com', |
14L, datetime.utcfromtimestamp(1415032601175 / 1000)), |
- ("cb4a637e0176010f51f86bb085c7b955".decode("hex"), u"yahoo.com", |
+ ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"yahoo.com", |
self.geometrical(interval, 43, 1415045194098, |
self.geometrical(interval, 27, 1414917270343, |
14, 1414859271125), |