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

Delta Between Two Patch Sets: sitescripts/subscriptions/test/test_updateMalwareDomainsList.py

Issue 29370984: Fixes 4784 - Improve error reporting in updateMalwareDomainsList and add tests (Closed)
Left Patch Set: Created Jan. 10, 2017, 6:08 p.m.
Right Patch Set: Improve the error handling flow in try_mirror Created Jan. 20, 2017, 1:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/subscriptions/bin/updateMalwareDomainsList.py ('k') | tox.ini » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 def urlopen(mocker): 53 def urlopen(mocker):
54 """Mock urlopen function""" 54 """Mock urlopen function"""
55 real_urlopen = urllib2.urlopen 55 real_urlopen = urllib2.urlopen
56 56
57 def mock_urlopen(url): 57 def mock_urlopen(url):
58 if url.startswith('good'): 58 if url.startswith('good'):
59 zf_data = io.BytesIO() 59 zf_data = io.BytesIO()
60 with zipfile.ZipFile(zf_data, 'w') as zf: 60 with zipfile.ZipFile(zf_data, 'w') as zf:
61 zf.writestr('justdomains', 'success\n') 61 zf.writestr('justdomains', 'success\n')
62 return io.BytesIO(zf_data.getvalue()) 62 return io.BytesIO(zf_data.getvalue())
63 if url.startswith('bad') or url.startswith('ugly'): 63 if url.startswith('bad'):
64 raise urllib2.URLError('Bad') 64 raise urllib2.HTTPError('Bad', '42', 'No good', [], None)
65 if url.startswith('ugly'):
66 raise urllib2.URLError('Ugly')
65 return real_urlopen(url) 67 return real_urlopen(url)
66 68
67 mocker.patch('urllib2.urlopen', mock_urlopen) 69 mocker.patch('urllib2.urlopen', mock_urlopen)
68 70
69 71
70 def test_good(md_repo): 72 def test_good(md_repo):
71 main() 73 main()
72 subprocess.check_call(['hg', 'up'], cwd=md_repo.strpath) 74 subprocess.check_call(['hg', 'up'], cwd=md_repo.strpath)
73 result = md_repo.join('malwaredomains_full.txt').read() 75 result = md_repo.join('malwaredomains_full.txt').read()
74 assert 'success' in result 76 assert 'success' in result
75 77
76 78
77 def test_bad(md_repo, config): 79 def test_bad(md_repo, config):
78 config.set(CONF_SECTION, 'malwaredomains_mirrors', 'bad') 80 config.set(CONF_SECTION, 'malwaredomains_mirrors', 'bad')
79 try: 81 try:
80 main() 82 main()
81 except SystemExit as exc: 83 except SystemExit as exc:
82 err_lines = str(exc).splitlines() 84 err_lines = str(exc).splitlines()
83 assert len(err_lines) == 3 85 assert len(err_lines) == 3
84 assert 'Failed to fetch bad/files/justdomains.zip' in err_lines[2] 86 assert 'Failed to fetch bad/files/justdomains.zip' in err_lines[2]
87 assert '42: No good' in err_lines[2]
85 88
86 89
87 def test_ugly(md_repo, config): 90 def test_ugly(md_repo, config):
88 config.set(CONF_SECTION, 'malwaredomains_mirrors', 'bad\nugly') 91 config.set(CONF_SECTION, 'malwaredomains_mirrors', 'bad\nugly')
89 try: 92 try:
90 main() 93 main()
91 except SystemExit as exc: 94 except SystemExit as exc:
92 err_lines = str(exc).splitlines() 95 err_lines = str(exc).splitlines()
93 assert len(err_lines) == 4 96 assert len(err_lines) == 4
94 assert 'Failed to fetch bad/files/justdomains.zip' in err_lines[2] 97 assert 'Failed to fetch bad/files/justdomains.zip' in err_lines[2]
95 assert 'Failed to fetch ugly/files/justdomains.zip' in err_lines[3] 98 assert 'Failed to fetch ugly/files/justdomains.zip' in err_lines[3]
99 assert 'Ugly' in err_lines[3]
LEFTRIGHT

Powered by Google App Engine
This is Rietveld