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

Unified Diff: sitescripts/stats/test/logprocessor.py

Issue 11577044: Switch to pygeoip for log processing to allow running it via PyPy (Closed)
Patch Set: Created Aug. 29, 2013, 7:38 p.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/stats/bin/logprocessor.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/stats/test/logprocessor.py
===================================================================
--- a/sitescripts/stats/test/logprocessor.py
+++ b/sitescripts/stats/test/logprocessor.py
@@ -61,26 +61,34 @@ class Test(unittest.TestCase):
country = None
class FakeGeo(object):
ip_checked = None
def country_code_by_addr(self, ip):
self.ip_checked = ip
return country
tests = [
- ("1.2.3.4", "xy", "1.2.3.4", "xy"),
- ("::ffff:1.2.3.4", "xy", "1.2.3.4", "xy"),
- ("1.2.3.4", "--", "1.2.3.4", "unknown"),
- ("1.2.3.4", "", "1.2.3.4", "unknown"),
- ("::ffff:1.2.3.4", None, "1.2.3.4", "unknown"),
+ ("1.2.3.4", "xy", "1.2.3.4", "v4", "xy"),
+ ("::ffff:1.2.3.4", "xy", "1.2.3.4", "v4", "xy"),
+ ("1.2.3.4", "--", "1.2.3.4", "v4", "unknown"),
+ ("1.2.3.4", "", "1.2.3.4", "v4", "unknown"),
+ ("::ffff:1.2.3.4", None, "1.2.3.4", "v4", "unknown"),
+ ("::1", "xy", "::1", "v6", "xy"),
+ ("FE80:0000:0000:0000:0202:B3FF:FE1E:8329", None, "FE80:0000:0000:0000:0202:B3FF:FE1E:8329", "v6", "unknown"),
]
- for ip, country, expected_ip, expected_country in tests:
+ for ip, country, expected_ip, expected_type, expected_country in tests:
fake_geo = FakeGeo()
- self.assertEqual(logprocessor.process_ip(ip, fake_geo), (expected_ip, expected_country), "Processing IP '%s'" % ip)
- self.assertEqual(fake_geo.ip_checked, expected_ip, "GeoIP check for IP '%s'" % ip)
+ fake_geov6 = FakeGeo()
+ self.assertEqual(logprocessor.process_ip(ip, fake_geo, fake_geov6), (expected_ip, expected_country), "Processing IP '%s'" % ip)
+ if expected_type == "v4":
+ self.assertEqual(fake_geo.ip_checked, expected_ip, "GeoIP check for IP '%s'" % ip)
+ self.assertEqual(fake_geov6.ip_checked, None, "GeoIPv6 check for IP '%s'" % ip)
+ else:
+ self.assertEqual(fake_geo.ip_checked, None, "GeoIP check for IP '%s'" % ip)
+ self.assertEqual(fake_geov6.ip_checked, expected_ip, "GeoIPv6 check for IP '%s'" % ip)
def test_timeparsing(self):
tests = [
("31/Jul/2013:12:03:37", 0, 0, datetime(2013, 07, 31, 12, 03, 37), "201307"),
("31/Jul/2013:12:03:37", 5, 0, datetime(2013, 07, 31, 7, 03, 37), "201307"),
("31/Jul/2013:12:03:37", -5, 0, datetime(2013, 07, 31, 17, 03, 37), "201307"),
("31/Jul/2013:12:03:37", 5, 30, datetime(2013, 07, 31, 6, 33, 37), "201307"),
("31/Jul/2013:12:03:37", -5, 30, datetime(2013, 07, 31, 17, 33, 37), "201307"),
@@ -572,17 +580,17 @@ class Test(unittest.TestCase):
"fullPlatform": "chromium 28.0",
"downloadInterval": "1 day(s)",
"firstInDay": True,
}
),
]
for line, expected_record in tests:
logprocessor.mirror_name = "mirror123"
- self.assertEqual(logprocessor.parse_record(line, set(), FakeGeo()), expected_record, "Parsing log line '%s'" % line)
+ self.assertEqual(logprocessor.parse_record(line, set(), FakeGeo(), FakeGeo()), expected_record, "Parsing log line '%s'" % line)
def test_record_adding(self):
tests = [
(
{"size": 200},
{},
(),
{"hits": 1, "bandwidth": 200},
« no previous file with comments | « sitescripts/stats/bin/logprocessor.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld