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

Side by Side Diff: sitescripts/stats/test/logprocessor.py

Issue 11576063: Stats processing: Add previousDownload field in addition to downloadInterval (Closed)
Patch Set: Created Sept. 5, 2013, 10:54 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sitescripts/stats/template/fileStats.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 tests = [ 117 tests = [
118 ( 118 (
119 datetime(2013, 07, 31, 12, 03, 00), 119 datetime(2013, 07, 31, 12, 03, 00),
120 "easylist.txt", 120 "easylist.txt",
121 "", 121 "",
122 "", 122 "",
123 "unknown/unknown", 123 "unknown/unknown",
124 "unknown/unknown", 124 "unknown/unknown",
125 "unknown/unknown", 125 "unknown/unknown",
126 "unknown", 126 "unknown",
127 "unknown",
127 "", 128 "",
128 ), 129 ),
129 ( 130 (
130 datetime(2013, 07, 31, 12, 03, 00), 131 datetime(2013, 07, 31, 12, 03, 00),
131 "easylist.txt", 132 "easylist.txt",
132 "addonName=adblockplus&addonVersion=2.3.1&application=firefox&applicatio nVersion=22.0a1&platform=gecko&platformVersion=23.0&lastVersion=0", 133 "addonName=adblockplus&addonVersion=2.3.1&application=firefox&applicatio nVersion=22.0a1&platform=gecko&platformVersion=23.0&lastVersion=0",
133 "-", 134 "-",
134 "adblockplus/2.3.1", 135 "adblockplus/2.3.1",
135 "firefox/22.0", 136 "firefox/22.0",
136 "gecko/23.0", 137 "gecko/23.0",
137 "unknown", 138 "unknown",
139 "unknown",
138 "firstDownload", 140 "firstDownload",
139 ), 141 ),
140 ( 142 (
141 datetime(2013, 07, 31, 12, 03, 00), 143 datetime(2013, 07, 31, 12, 03, 00),
142 "easylist.txt", 144 "easylist.txt",
143 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0&lastVersion=201307311200", 145 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0&lastVersion=201307311200",
144 "-", 146 "-",
145 "adblockplus/2.3.1", 147 "adblockplus/2.3.1",
146 "unknown/unknown", 148 "unknown/unknown",
147 "gecko/23.0", 149 "gecko/23.0",
148 "0 hour(s)", 150 "0 hour(s)",
151 "same day",
149 "", 152 "",
150 ), 153 ),
151 ( 154 (
152 datetime(2013, 07, 31, 12, 03, 00), 155 datetime(2013, 07, 31, 12, 03, 00),
153 "easylist.txt", 156 "easylist.txt",
154 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0&lastVersion=201307302200", 157 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0&lastVersion=201307302200",
155 "-", 158 "-",
156 "adblockplus/2.3.1", 159 "adblockplus/2.3.1",
157 "unknown/unknown", 160 "unknown/unknown",
158 "gecko/23.0", 161 "gecko/23.0",
159 "14 hour(s)", 162 "14 hour(s)",
163 "1 day(s)",
160 "firstInDay", 164 "firstInDay",
161 ), 165 ),
162 ( 166 (
163 datetime(2013, 07, 31, 12, 03, 00), 167 datetime(2013, 07, 31, 12, 03, 00),
164 "easylist.txt", 168 "easylist.txt",
165 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0&lastVersion=201307282200", 169 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0&lastVersion=201307282200",
166 "-", 170 "-",
167 "adblockplus/2.3.1", 171 "adblockplus/2.3.1",
168 "unknown/unknown", 172 "unknown/unknown",
169 "gecko/23.0", 173 "gecko/23.0",
170 "2 day(s)", 174 "2 day(s)",
175 "3 day(s)",
171 "firstInWeek firstInDay", 176 "firstInWeek firstInDay",
172 ), 177 ),
173 ( 178 (
174 datetime(2013, 8, 2, 12, 03, 00), 179 datetime(2013, 8, 2, 12, 03, 00),
175 "easylist.txt", 180 "easylist.txt",
176 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0&lastVersion=201307311200", 181 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0&lastVersion=201307311200",
177 "-", 182 "-",
178 "adblockplus/2.3.1", 183 "adblockplus/2.3.1",
179 "unknown/unknown", 184 "unknown/unknown",
180 "gecko/23.0", 185 "gecko/23.0",
181 "2 day(s)", 186 "2 day(s)",
187 "2 day(s)",
182 "firstInMonth firstInDay", 188 "firstInMonth firstInDay",
183 ), 189 ),
184 ( 190 (
185 datetime(2013, 07, 31, 12, 03, 00), 191 datetime(2013, 07, 31, 12, 03, 00),
186 "easylist.txt", 192 "easylist.txt",
187 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0&lastVersion=201306302200", 193 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0&lastVersion=201306302200",
188 "-", 194 "-",
189 "adblockplus/2.3.1", 195 "adblockplus/2.3.1",
190 "unknown/unknown", 196 "unknown/unknown",
191 "gecko/23.0", 197 "gecko/23.0",
192 "1 month(s)", 198 "1 month(s)",
199 "1 month(s)",
193 "firstInMonth firstInWeek firstInDay", 200 "firstInMonth firstInWeek firstInDay",
194 ), 201 ),
195 ( 202 (
196 datetime(2013, 07, 31, 12, 03, 00), 203 datetime(2013, 07, 31, 12, 03, 00),
197 "easylist.txt", 204 "easylist.txt",
198 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0&lastVersion=201305302200", 205 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0&lastVersion=201305302200",
199 "-", 206 "-",
200 "adblockplus/2.3.1", 207 "adblockplus/2.3.1",
201 "unknown/unknown", 208 "unknown/unknown",
202 "gecko/23.0", 209 "gecko/23.0",
203 "2 month(s)", 210 "2 month(s)",
211 "2 month(s)",
204 "firstInMonth firstInWeek firstInDay", 212 "firstInMonth firstInWeek firstInDay",
205 ), 213 ),
206 ( 214 (
207 datetime(2013, 07, 31, 12, 03, 00), 215 datetime(2013, 07, 31, 12, 03, 00),
208 "easylist.txt", 216 "easylist.txt",
209 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0.1&lastVersion=201206302200", 217 "addonName=adblockplus&addonVersion=2.3.1&platform=gecko&platformVersion =23.0.1&lastVersion=201206302200",
210 "-", 218 "-",
211 "adblockplus/2.3.1", 219 "adblockplus/2.3.1",
212 "unknown/unknown", 220 "unknown/unknown",
213 "gecko/23.0", 221 "gecko/23.0",
214 "1 year(s)", 222 "1 year(s)",
223 "1 year(s)",
215 "firstInMonth firstInWeek firstInDay", 224 "firstInMonth firstInWeek firstInDay",
216 ), 225 ),
217 ( 226 (
218 datetime(2013, 07, 31, 12, 03, 00), 227 datetime(2013, 07, 31, 12, 03, 00),
219 "easylist.txt", 228 "easylist.txt",
220 "_=1375142394357", 229 "_=1375142394357",
221 "AdBlock/2.5.4", 230 "AdBlock/2.5.4",
222 "chromeadblock/2.5.4", 231 "chromeadblock/2.5.4",
223 "unknown/unknown", 232 "unknown/unknown",
224 "unknown/unknown", 233 "unknown/unknown",
225 "unknown", 234 "unknown",
235 "unknown",
226 "" 236 ""
227 ), 237 ),
228 ] 238 ]
229 for time, file, query, clientid, expected_addon, expected_application, expec ted_platform, expected_interval, expected_flags in tests: 239 for time, file, query, clientid, expected_addon, expected_application, expec ted_platform, expected_interval, expected_previous, expected_flags in tests:
230 info = {"time": time, "file": file, "query": query, "clientid": clientid} 240 info = {"time": time, "file": file, "query": query, "clientid": clientid}
231 logprocessor.parse_downloader_query(info) 241 logprocessor.parse_downloader_query(info)
232 self.assertEqual("%s/%s" % (info["addonName"], info["addonVersion"]), expe cted_addon, "Add-on for query '%s'" % query) 242 self.assertEqual("%s/%s" % (info["addonName"], info["addonVersion"]), expe cted_addon, "Add-on for query '%s'" % query)
233 self.assertEqual("%s/%s" % (info["application"], info["applicationVersion" ]), expected_application, "Application for query '%s'" % query) 243 self.assertEqual("%s/%s" % (info["application"], info["applicationVersion" ]), expected_application, "Application for query '%s'" % query)
234 self.assertEqual("%s/%s" % (info["platform"], info["platformVersion"]), ex pected_platform, "Platform for query '%s'" % query) 244 self.assertEqual("%s/%s" % (info["platform"], info["platformVersion"]), ex pected_platform, "Platform for query '%s'" % query)
235 self.assertEqual(info["downloadInterval"], expected_interval, "Download in terval for query '%s'" % query) 245 self.assertEqual(info["downloadInterval"], expected_interval, "Download in terval for query '%s'" % query)
246 self.assertEqual(info["previousDownload"], expected_previous, "Previous do wnload for query '%s'" % query)
236 247
237 flags = [] 248 flags = []
238 for flag in ("firstDownload", "firstInMonth", "firstInWeek", "firstInDay") : 249 for flag in ("firstDownload", "firstInMonth", "firstInWeek", "firstInDay") :
239 if flag in info: 250 if flag in info:
240 flags.append(flag) 251 flags.append(flag)
241 self.assertEqual(" ".join(flags), expected_flags, "Flags for query '%s'" % query) 252 self.assertEqual(" ".join(flags), expected_flags, "Flags for query '%s'" % query)
242 253
243 def test_nameparsing(self): 254 def test_nameparsing(self):
244 tests = [ 255 tests = [
245 ("devbuilds/adblockplus/update.rdf", "adblockplus"), 256 ("devbuilds/adblockplus/update.rdf", "adblockplus"),
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 "addonName": "adblockplusie", 397 "addonName": "adblockplusie",
387 "addonVersion": "2.0", 398 "addonVersion": "2.0",
388 "fullAddon": "adblockplusie 2.0", 399 "fullAddon": "adblockplusie 2.0",
389 "application": "msie64", 400 "application": "msie64",
390 "applicationVersion": "10.0", 401 "applicationVersion": "10.0",
391 "fullApplication": "msie64 10.0", 402 "fullApplication": "msie64 10.0",
392 "platform": "libadblockplus", 403 "platform": "libadblockplus",
393 "platformVersion": "1.0", 404 "platformVersion": "1.0",
394 "fullPlatform": "libadblockplus 1.0", 405 "fullPlatform": "libadblockplus 1.0",
395 "downloadInterval": "unknown", 406 "downloadInterval": "unknown",
407 "previousDownload": "unknown",
396 "firstDownload": True, 408 "firstDownload": True,
397 } 409 }
398 ), 410 ),
399 ( 411 (
400 '1.2.3.4 - - [31/Jul/2013:12:03:08 -0530] "GET /adblockplusandroid-1.1.2 .apk HTTP/1.1" 200 49152 "https://adblockplus.org/en/android-install" "Mozilla/5 .0 (Linux; U; Android 4.1.2; es-es; GT-I9100 Build/JZO54K) AppleWebKit/534.30 (K HTML, like Gecko) Version/4.0 Mobile Safari/534.30" "-" https "en-US" "downloads .adblockplus.org" "-"', 412 '1.2.3.4 - - [31/Jul/2013:12:03:08 -0530] "GET /adblockplusandroid-1.1.2 .apk HTTP/1.1" 200 49152 "https://adblockplus.org/en/android-install" "Mozilla/5 .0 (Linux; U; Android 4.1.2; es-es; GT-I9100 Build/JZO54K) AppleWebKit/534.30 (K HTML, like Gecko) Version/4.0 Mobile Safari/534.30" "-" https "en-US" "downloads .adblockplus.org" "-"',
401 { 413 {
402 "mirror": "mirror123", 414 "mirror": "mirror123",
403 "ip": "1.2.3.4", 415 "ip": "1.2.3.4",
404 "country": "xy", 416 "country": "xy",
405 "time": datetime(2013, 7, 31, 17, 33, 8), 417 "time": datetime(2013, 7, 31, 17, 33, 8),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 "addonName": "adblockplus", 471 "addonName": "adblockplus",
460 "addonVersion": "2.3.2", 472 "addonVersion": "2.3.2",
461 "fullAddon": "adblockplus 2.3.2", 473 "fullAddon": "adblockplus 2.3.2",
462 "application": "firefox", 474 "application": "firefox",
463 "applicationVersion": "22.0", 475 "applicationVersion": "22.0",
464 "fullApplication": "firefox 22.0", 476 "fullApplication": "firefox 22.0",
465 "platform": "gecko", 477 "platform": "gecko",
466 "platformVersion": "22.0", 478 "platformVersion": "22.0",
467 "fullPlatform": "gecko 22.0", 479 "fullPlatform": "gecko 22.0",
468 "downloadInterval": "2 hour(s)", 480 "downloadInterval": "2 hour(s)",
481 "previousDownload": "same day",
469 } 482 }
470 ), 483 ),
471 ( 484 (
472 '1.2.3.4 - - [31/Jul/2013:12:03:08 -0530] "GET /easylist.txt?_=137544652 8229 HTTP/1.1" 200 326120 "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 ( KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36" "-" https "nl-NL,nl;q=0.8, en-US;q=0.6,en;q=0.4" "easylist-downloads.adblockplus.org" "AdBlock/2.6.2"', 485 '1.2.3.4 - - [31/Jul/2013:12:03:08 -0530] "GET /easylist.txt?_=137544652 8229 HTTP/1.1" 200 326120 "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 ( KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36" "-" https "nl-NL,nl;q=0.8, en-US;q=0.6,en;q=0.4" "easylist-downloads.adblockplus.org" "AdBlock/2.6.2"',
473 { 486 {
474 "mirror": "mirror123", 487 "mirror": "mirror123",
475 "ip": "1.2.3.4", 488 "ip": "1.2.3.4",
476 "country": "xy", 489 "country": "xy",
477 "time": datetime(2013, 7, 31, 17, 33, 8), 490 "time": datetime(2013, 7, 31, 17, 33, 8),
478 "day": 31, 491 "day": 31,
(...skipping 10 matching lines...) Expand all
489 "addonName": "chromeadblock", 502 "addonName": "chromeadblock",
490 "addonVersion": "2.6.2", 503 "addonVersion": "2.6.2",
491 "fullAddon": "chromeadblock 2.6.2", 504 "fullAddon": "chromeadblock 2.6.2",
492 "application": "unknown", 505 "application": "unknown",
493 "applicationVersion": "unknown", 506 "applicationVersion": "unknown",
494 "fullApplication": "unknown unknown", 507 "fullApplication": "unknown unknown",
495 "platform": "unknown", 508 "platform": "unknown",
496 "platformVersion": "unknown", 509 "platformVersion": "unknown",
497 "fullPlatform": "unknown unknown", 510 "fullPlatform": "unknown unknown",
498 "downloadInterval": "unknown", 511 "downloadInterval": "unknown",
512 "previousDownload": "unknown",
499 } 513 }
500 ), 514 ),
501 ( 515 (
502 '1.2.3.4 - - [31/Jul/2013:12:03:08 -0530] "GET /easylistitaly.txt HTTP/1 .1" 200 85879 "-" "-" "-" https "-" "easylist-downloads.adblockplus.org" "-"', 516 '1.2.3.4 - - [31/Jul/2013:12:03:08 -0530] "GET /easylistitaly.txt HTTP/1 .1" 200 85879 "-" "-" "-" https "-" "easylist-downloads.adblockplus.org" "-"',
503 { 517 {
504 "mirror": "mirror123", 518 "mirror": "mirror123",
505 "ip": "1.2.3.4", 519 "ip": "1.2.3.4",
506 "country": "xy", 520 "country": "xy",
507 "time": datetime(2013, 7, 31, 17, 33, 8), 521 "time": datetime(2013, 7, 31, 17, 33, 8),
508 "day": 31, 522 "day": 31,
(...skipping 10 matching lines...) Expand all
519 "addonName": "unknown", 533 "addonName": "unknown",
520 "addonVersion": "unknown", 534 "addonVersion": "unknown",
521 "fullAddon": "unknown unknown", 535 "fullAddon": "unknown unknown",
522 "application": "unknown", 536 "application": "unknown",
523 "applicationVersion": "unknown", 537 "applicationVersion": "unknown",
524 "fullApplication": "unknown unknown", 538 "fullApplication": "unknown unknown",
525 "platform": "unknown", 539 "platform": "unknown",
526 "platformVersion": "unknown", 540 "platformVersion": "unknown",
527 "fullPlatform": "unknown unknown", 541 "fullPlatform": "unknown unknown",
528 "downloadInterval": "unknown", 542 "downloadInterval": "unknown",
543 "previousDownload": "unknown",
529 } 544 }
530 ), 545 ),
531 ( 546 (
532 '1.2.3.4 - - [31/Jul/2013:12:03:08 -0530] "GET /easylistitaly.tpl HTTP/1 .1" 200 85879 "-" "-" "-" https "-" "easylist-downloads.adblockplus.org" "-"', 547 '1.2.3.4 - - [31/Jul/2013:12:03:08 -0530] "GET /easylistitaly.tpl HTTP/1 .1" 200 85879 "-" "-" "-" https "-" "easylist-downloads.adblockplus.org" "-"',
533 { 548 {
534 "mirror": "mirror123", 549 "mirror": "mirror123",
535 "ip": "1.2.3.4", 550 "ip": "1.2.3.4",
536 "country": "xy", 551 "country": "xy",
537 "time": datetime(2013, 7, 31, 17, 33, 8), 552 "time": datetime(2013, 7, 31, 17, 33, 8),
538 "day": 31, 553 "day": 31,
(...skipping 30 matching lines...) Expand all
569 "addonName": "adblockpluschrome", 584 "addonName": "adblockpluschrome",
570 "addonVersion": "1.5.3", 585 "addonVersion": "1.5.3",
571 "fullAddon": "adblockpluschrome 1.5.3", 586 "fullAddon": "adblockpluschrome 1.5.3",
572 "application": "chrome", 587 "application": "chrome",
573 "applicationVersion": "28.0", 588 "applicationVersion": "28.0",
574 "fullApplication": "chrome 28.0", 589 "fullApplication": "chrome 28.0",
575 "platform": "chromium", 590 "platform": "chromium",
576 "platformVersion": "28.0", 591 "platformVersion": "28.0",
577 "fullPlatform": "chromium 28.0", 592 "fullPlatform": "chromium 28.0",
578 "downloadInterval": "1 day(s)", 593 "downloadInterval": "1 day(s)",
594 "previousDownload": "2 day(s)",
579 "firstInDay": True, 595 "firstInDay": True,
580 } 596 }
581 ), 597 ),
582 ] 598 ]
583 for line, expected_record in tests: 599 for line, expected_record in tests:
584 logprocessor.mirror_name = "mirror123" 600 logprocessor.mirror_name = "mirror123"
585 self.assertEqual(logprocessor.parse_record(line, set(), FakeGeo(), FakeGeo ()), expected_record, "Parsing log line '%s'" % line) 601 self.assertEqual(logprocessor.parse_record(line, set(), FakeGeo(), FakeGeo ()), expected_record, "Parsing log line '%s'" % line)
586 602
587 def test_record_adding(self): 603 def test_record_adding(self):
588 tests = [ 604 tests = [
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 "addonName": {"bar": {"hits": 1, "bandwidth": 200}} 652 "addonName": {"bar": {"hits": 1, "bandwidth": 200}}
637 }, 653 },
638 ), 654 ),
639 ] 655 ]
640 for info, section, ignored_fields, expected_result in tests: 656 for info, section, ignored_fields, expected_result in tests:
641 logprocessor.add_record(info, section, ignored_fields) 657 logprocessor.add_record(info, section, ignored_fields)
642 self.assertEqual(section, expected_result) 658 self.assertEqual(section, expected_result)
643 659
644 if __name__ == '__main__': 660 if __name__ == '__main__':
645 unittest.main() 661 unittest.main()
OLDNEW
« no previous file with comments | « sitescripts/stats/template/fileStats.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld