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

Delta Between Two Patch Sets: sitescripts/notifications/test/parser.py

Issue 29527607: Issue 5458, 5457 - Refactor _parse_targetspec, add support for locales and blockTotal (Closed)
Left Patch Set: Added test for target parsing Created Sept. 11, 2017, 1:32 p.m.
Right Patch Set: Use assert instead of assertEqual across the board, also test no additional targets are present Created Sept. 21, 2017, 10:10 a.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/notifications/parser.py ('k') | no next file » | 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-present eyeo GmbH 2 # Copyright (C) 2006-present 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 self.assertEqual(notifications[1]['severity'], 'critical') 153 self.assertEqual(notifications[1]['severity'], 'critical')
154 self.assertEqual(notifications[2]['severity'], 'normal') 154 self.assertEqual(notifications[2]['severity'], 'normal')
155 self.assertEqual(notifications[3]['severity'], 'relentless') 155 self.assertEqual(notifications[3]['severity'], 'relentless')
156 156
157 def test_urls(self): 157 def test_urls(self):
158 self.notification_to_load = [ 158 self.notification_to_load = [
159 ('1', '\nurls = adblockplus.org\n'), 159 ('1', '\nurls = adblockplus.org\n'),
160 ('1', '\nurls = adblockplus.org eyeo.com\n'), 160 ('1', '\nurls = adblockplus.org eyeo.com\n'),
161 ] 161 ]
162 notifications = parser.load_notifications() 162 notifications = parser.load_notifications()
163 self.assertEqual(len(notifications), 2) 163
164 self.assertEqual( 164 assert len(notifications) == 2
165 notifications[0]['urlFilters'], ['ADBLOCKPLUS.ORG^$document']) 165 assert notifications[0]['urlFilters'] == ['ADBLOCKPLUS.ORG^$document']
166 self.assertEqual(notifications[1]['urlFilters'], [ 166 assert notifications[1]['urlFilters'] == [
167 'ADBLOCKPLUS.ORG^$document', 167 'ADBLOCKPLUS.ORG^$document',
168 'EYEO.COM^$document']) 168 'EYEO.COM^$document']
169 169
170 def test_target(self): 170 def test_target(self):
171 self.notification_to_load = [ 171 self.notification_to_load = [
172 ('1', '\ntarget = extension=adblockplus\n'), 172 ('1', '\ntarget = extension=adblockplus\n'),
173 ('2', '\ntarget = extensionVersion=1.2.3\n'), 173 ('2', '\ntarget = extensionVersion=1.2.3\n'),
174 ('3', '\ntarget = extensionVersion>=1.2.3\n'), 174 ('3', '\ntarget = extensionVersion>=1.2.3\n'),
175 ('4', '\ntarget = extensionVersion<=1.2.3\n'), 175 ('4', '\ntarget = extensionVersion<=1.2.3\n'),
176 ('5', '\ntarget = application=chrome\n'), 176 ('5', '\ntarget = application=chrome\n'),
177 ('6', '\ntarget = applicationVersion=1.2.3\n'), 177 ('6', '\ntarget = applicationVersion=1.2.3\n'),
178 ('7', '\ntarget = applicationVersion>=1.2.3\n'), 178 ('7', '\ntarget = applicationVersion>=1.2.3\n'),
179 ('8', '\ntarget = applicationVersion<=1.2.3\n'), 179 ('8', '\ntarget = applicationVersion<=1.2.3\n'),
180 ('9', '\ntarget = platform=chromium\n'), 180 ('9', '\ntarget = platform=chromium\n'),
181 ('10', '\ntarget = platformVersion=1.2.3\n'), 181 ('10', '\ntarget = platformVersion=1.2.3\n'),
182 ('11', '\ntarget = platformVersion>=1.2.3\n'), 182 ('11', '\ntarget = platformVersion>=1.2.3\n'),
183 ('12', '\ntarget = platformVersion<=1.2.3\n'), 183 ('12', '\ntarget = platformVersion<=1.2.3\n'),
184 ('13', '\ntarget = blockedTotal=10\n'), 184 ('13', '\ntarget = blockedTotal=10\n'),
185 ('14', '\ntarget = blockedTotal>=10\n'), 185 ('14', '\ntarget = blockedTotal>=10\n'),
186 ('15', '\ntarget = blockedTotal<=10\n'), 186 ('15', '\ntarget = blockedTotal<=10\n'),
187 ('16', '\ntarget = locales=en-US\n'), 187 ('16', '\ntarget = locales=en-US\n'),
188 ('17', '\ntarget = locales=en-US,de-DE\n'), 188 ('17', '\ntarget = locales=en-US,de-DE\n'),
189 ] 189 ]
190 190
191 notifications = parser.load_notifications() 191 notifications = parser.load_notifications()
192 self.assertEqual(len(notifications), 17) 192
Vasily Kuznetsov 2017/09/20 15:45:33 These tests are run with pytest nowadays, so you c
wspee 2017/09/21 08:10:52 Done.
Vasily Kuznetsov 2017/09/21 09:41:30 I actually meant it for all new assertions (the on
193 193 assert len(notifications) == 17
194 self.assertEqual( 194 assert notifications[0]['targets'] == [{'extension': 'adblockplus'}]
195 notifications[0]['targets'][0]['extension'], 'adblockplus') 195 assert notifications[1]['targets'] == [{
196 self.assertEqual( 196 'extensionMinVersion': '1.2.3',
197 notifications[1]['targets'][0]['extensionMinVersion'], '1.2.3') 197 'extensionMaxVersion': '1.2.3'}]
198 self.assertEqual( 198 assert notifications[2]['targets'] == [
199 notifications[1]['targets'][0]['extensionMaxVersion'], '1.2.3') 199 {'extensionMinVersion': '1.2.3'}]
200 self.assertEqual( 200 assert notifications[3]['targets'] == [{
201 notifications[2]['targets'][0]['extensionMinVersion'], '1.2.3') 201 'extensionMaxVersion': '1.2.3'}]
202 self.assertEqual( 202 assert notifications[4]['targets'] == [{'application': 'chrome'}]
203 notifications[3]['targets'][0]['extensionMaxVersion'], '1.2.3') 203 assert notifications[5]['targets'] == [{
204 self.assertEqual( 204 'applicationMinVersion': '1.2.3',
205 notifications[4]['targets'][0]['application'], 'chrome') 205 'applicationMaxVersion': '1.2.3'}]
206 self.assertEqual( 206 assert notifications[6]['targets'] == [{
207 notifications[5]['targets'][0]['applicationMinVersion'], '1.2.3') 207 'applicationMinVersion': '1.2.3'}]
208 self.assertEqual( 208 assert notifications[7]['targets'] == [{
209 notifications[5]['targets'][0]['applicationMaxVersion'], '1.2.3') 209 'applicationMaxVersion': '1.2.3'}]
210 self.assertEqual( 210 assert notifications[8]['targets'] == [{'platform': 'chromium'}]
211 notifications[6]['targets'][0]['applicationMinVersion'], '1.2.3') 211 assert notifications[9]['targets'] == [{
212 self.assertEqual( 212 'platformMinVersion': '1.2.3',
213 notifications[7]['targets'][0]['applicationMaxVersion'], '1.2.3') 213 'platformMaxVersion': '1.2.3'}]
214 self.assertEqual( 214 assert notifications[10]['targets'] == [{
215 notifications[8]['targets'][0]['platform'], 'chromium') 215 'platformMinVersion': '1.2.3'}]
216 self.assertEqual( 216 assert notifications[11]['targets'] == [{
217 notifications[9]['targets'][0]['platformMinVersion'], '1.2.3') 217 'platformMaxVersion': '1.2.3'}]
218 self.assertEqual( 218 assert notifications[12]['targets'] == [{
219 notifications[9]['targets'][0]['platformMaxVersion'], '1.2.3') 219 'blockedTotalMin': 10,
220 self.assertEqual( 220 'blockedTotalMax': 10}]
221 notifications[10]['targets'][0]['platformMinVersion'], '1.2.3') 221 assert notifications[13]['targets'] == [{'blockedTotalMin': 10}]
222 self.assertEqual( 222 assert notifications[14]['targets'] == [{'blockedTotalMax': 10}]
223 notifications[11]['targets'][0]['platformMaxVersion'], '1.2.3') 223 assert notifications[15]['targets'] == [{'locales': ['en-US']}]
224 self.assertEqual( 224 assert notifications[16]['targets'] == [{
225 notifications[12]['targets'][0]['blockedTotalMin'], 10) 225 'locales': ['en-US', 'de-DE']}]
226 self.assertEqual(
227 notifications[12]['targets'][0]['blockedTotalMax'], 10)
228 self.assertEqual(
229 notifications[13]['targets'][0]['blockedTotalMin'], 10)
230 self.assertEqual(
231 notifications[14]['targets'][0]['blockedTotalMax'], 10)
232 self.assertEqual(
233 notifications[15]['targets'][0]['locales'], ['en-US'])
234 self.assertEqual(
235 notifications[16]['targets'][0]['locales'], ['en-US', 'de-DE'])
236 226
237 227
238 if __name__ == '__main__': 228 if __name__ == '__main__':
239 unittest.main() 229 unittest.main()
LEFTRIGHT

Powered by Google App Engine
This is Rietveld