| OLD | NEW |
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 2 | 2 |
| 3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
| 4 # Copyright (C) 2006-2013 Eyeo GmbH | 4 # Copyright (C) 2006-2013 Eyeo GmbH |
| 5 # | 5 # |
| 6 # Adblock Plus is free software: you can redistribute it and/or modify | 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 | 7 # it under the terms of the GNU General Public License version 3 as |
| 8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
| 9 # | 9 # |
| 10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 def test_ipprocessing(self): | 60 def test_ipprocessing(self): |
| 61 country = None | 61 country = None |
| 62 class FakeGeo(object): | 62 class FakeGeo(object): |
| 63 ip_checked = None | 63 ip_checked = None |
| 64 def country_code_by_addr(self, ip): | 64 def country_code_by_addr(self, ip): |
| 65 self.ip_checked = ip | 65 self.ip_checked = ip |
| 66 return country | 66 return country |
| 67 | 67 |
| 68 tests = [ | 68 tests = [ |
| 69 ("1.2.3.4", "xy", "1.2.3.4", "xy"), | 69 ("1.2.3.4", "xy", "1.2.3.4", "v4", "xy"), |
| 70 ("::ffff:1.2.3.4", "xy", "1.2.3.4", "xy"), | 70 ("::ffff:1.2.3.4", "xy", "1.2.3.4", "v4", "xy"), |
| 71 ("1.2.3.4", "--", "1.2.3.4", "unknown"), | 71 ("1.2.3.4", "--", "1.2.3.4", "v4", "unknown"), |
| 72 ("1.2.3.4", "", "1.2.3.4", "unknown"), | 72 ("1.2.3.4", "", "1.2.3.4", "v4", "unknown"), |
| 73 ("::ffff:1.2.3.4", None, "1.2.3.4", "unknown"), | 73 ("::ffff:1.2.3.4", None, "1.2.3.4", "v4", "unknown"), |
| 74 ("::1", "xy", "::1", "v6", "xy"), |
| 75 ("FE80:0000:0000:0000:0202:B3FF:FE1E:8329", None, "FE80:0000:0000:0000:020
2:B3FF:FE1E:8329", "v6", "unknown"), |
| 74 ] | 76 ] |
| 75 for ip, country, expected_ip, expected_country in tests: | 77 for ip, country, expected_ip, expected_type, expected_country in tests: |
| 76 fake_geo = FakeGeo() | 78 fake_geo = FakeGeo() |
| 77 self.assertEqual(logprocessor.process_ip(ip, fake_geo), (expected_ip, expe
cted_country), "Processing IP '%s'" % ip) | 79 fake_geov6 = FakeGeo() |
| 78 self.assertEqual(fake_geo.ip_checked, expected_ip, "GeoIP check for IP '%s
'" % ip) | 80 self.assertEqual(logprocessor.process_ip(ip, fake_geo, fake_geov6), (expec
ted_ip, expected_country), "Processing IP '%s'" % ip) |
| 81 if expected_type == "v4": |
| 82 self.assertEqual(fake_geo.ip_checked, expected_ip, "GeoIP check for IP '
%s'" % ip) |
| 83 self.assertEqual(fake_geov6.ip_checked, None, "GeoIPv6 check for IP '%s'
" % ip) |
| 84 else: |
| 85 self.assertEqual(fake_geo.ip_checked, None, "GeoIP check for IP '%s'" %
ip) |
| 86 self.assertEqual(fake_geov6.ip_checked, expected_ip, "GeoIPv6 check for
IP '%s'" % ip) |
| 79 | 87 |
| 80 def test_timeparsing(self): | 88 def test_timeparsing(self): |
| 81 tests = [ | 89 tests = [ |
| 82 ("31/Jul/2013:12:03:37", 0, 0, datetime(2013, 07, 31, 12, 03, 37), "201307
"), | 90 ("31/Jul/2013:12:03:37", 0, 0, datetime(2013, 07, 31, 12, 03, 37), "201307
"), |
| 83 ("31/Jul/2013:12:03:37", 5, 0, datetime(2013, 07, 31, 7, 03, 37), "201307"
), | 91 ("31/Jul/2013:12:03:37", 5, 0, datetime(2013, 07, 31, 7, 03, 37), "201307"
), |
| 84 ("31/Jul/2013:12:03:37", -5, 0, datetime(2013, 07, 31, 17, 03, 37), "20130
7"), | 92 ("31/Jul/2013:12:03:37", -5, 0, datetime(2013, 07, 31, 17, 03, 37), "20130
7"), |
| 85 ("31/Jul/2013:12:03:37", 5, 30, datetime(2013, 07, 31, 6, 33, 37), "201307
"), | 93 ("31/Jul/2013:12:03:37", 5, 30, datetime(2013, 07, 31, 6, 33, 37), "201307
"), |
| 86 ("31/Jul/2013:12:03:37", -5, 30, datetime(2013, 07, 31, 17, 33, 37), "2013
07"), | 94 ("31/Jul/2013:12:03:37", -5, 30, datetime(2013, 07, 31, 17, 33, 37), "2013
07"), |
| 87 ] | 95 ] |
| 88 for timestr, tz_hours, tz_minutes, expected_time, expected_month in tests: | 96 for timestr, tz_hours, tz_minutes, expected_time, expected_month in tests: |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 "platform": "chromium", | 578 "platform": "chromium", |
| 571 "platformVersion": "28.0", | 579 "platformVersion": "28.0", |
| 572 "fullPlatform": "chromium 28.0", | 580 "fullPlatform": "chromium 28.0", |
| 573 "downloadInterval": "1 day(s)", | 581 "downloadInterval": "1 day(s)", |
| 574 "firstInDay": True, | 582 "firstInDay": True, |
| 575 } | 583 } |
| 576 ), | 584 ), |
| 577 ] | 585 ] |
| 578 for line, expected_record in tests: | 586 for line, expected_record in tests: |
| 579 logprocessor.mirror_name = "mirror123" | 587 logprocessor.mirror_name = "mirror123" |
| 580 self.assertEqual(logprocessor.parse_record(line, set(), FakeGeo()), expect
ed_record, "Parsing log line '%s'" % line) | 588 self.assertEqual(logprocessor.parse_record(line, set(), FakeGeo(), FakeGeo
()), expected_record, "Parsing log line '%s'" % line) |
| 581 | 589 |
| 582 def test_record_adding(self): | 590 def test_record_adding(self): |
| 583 tests = [ | 591 tests = [ |
| 584 ( | 592 ( |
| 585 {"size": 200}, | 593 {"size": 200}, |
| 586 {}, | 594 {}, |
| 587 (), | 595 (), |
| 588 {"hits": 1, "bandwidth": 200}, | 596 {"hits": 1, "bandwidth": 200}, |
| 589 ), | 597 ), |
| 590 ( | 598 ( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 "addonName": {"bar": {"hits": 1, "bandwidth": 200}} | 639 "addonName": {"bar": {"hits": 1, "bandwidth": 200}} |
| 632 }, | 640 }, |
| 633 ), | 641 ), |
| 634 ] | 642 ] |
| 635 for info, section, ignored_fields, expected_result in tests: | 643 for info, section, ignored_fields, expected_result in tests: |
| 636 logprocessor.add_record(info, section, ignored_fields) | 644 logprocessor.add_record(info, section, ignored_fields) |
| 637 self.assertEqual(section, expected_result) | 645 self.assertEqual(section, expected_result) |
| 638 | 646 |
| 639 if __name__ == '__main__': | 647 if __name__ == '__main__': |
| 640 unittest.main() | 648 unittest.main() |
| OLD | NEW |