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

Side by Side Diff: sitescripts/notifications/test/parser.py

Issue 29527607: Issue 5458, 5457 - Refactor _parse_targetspec, add support for locales and blockTotal (Closed)
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:
View unified diff | Download patch
« no previous file with comments | « sitescripts/notifications/parser.py ('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 # 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 163
164 assert len(notifications) == 2 164 assert len(notifications) == 2
165 assert notifications[0]['urlFilters'] == ['ADBLOCKPLUS.ORG^$document'] 165 assert notifications[0]['urlFilters'] == ['ADBLOCKPLUS.ORG^$document']
166 assert 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):
171 self.notification_to_load = [
172 ('1', '\ntarget = extension=adblockplus\n'),
173 ('2', '\ntarget = extensionVersion=1.2.3\n'),
174 ('3', '\ntarget = extensionVersion>=1.2.3\n'),
175 ('4', '\ntarget = extensionVersion<=1.2.3\n'),
176 ('5', '\ntarget = application=chrome\n'),
177 ('6', '\ntarget = applicationVersion=1.2.3\n'),
178 ('7', '\ntarget = applicationVersion>=1.2.3\n'),
179 ('8', '\ntarget = applicationVersion<=1.2.3\n'),
180 ('9', '\ntarget = platform=chromium\n'),
181 ('10', '\ntarget = platformVersion=1.2.3\n'),
182 ('11', '\ntarget = platformVersion>=1.2.3\n'),
183 ('12', '\ntarget = platformVersion<=1.2.3\n'),
184 ('13', '\ntarget = blockedTotal=10\n'),
185 ('14', '\ntarget = blockedTotal>=10\n'),
186 ('15', '\ntarget = blockedTotal<=10\n'),
187 ('16', '\ntarget = locales=en-US\n'),
188 ('17', '\ntarget = locales=en-US,de-DE\n'),
189 ]
190
191 notifications = parser.load_notifications()
192
193 assert len(notifications) == 17
194 assert notifications[0]['targets'] == [{'extension': 'adblockplus'}]
195 assert notifications[1]['targets'] == [{
196 'extensionMinVersion': '1.2.3',
197 'extensionMaxVersion': '1.2.3'}]
198 assert notifications[2]['targets'] == [
199 {'extensionMinVersion': '1.2.3'}]
200 assert notifications[3]['targets'] == [{
201 'extensionMaxVersion': '1.2.3'}]
202 assert notifications[4]['targets'] == [{'application': 'chrome'}]
203 assert notifications[5]['targets'] == [{
204 'applicationMinVersion': '1.2.3',
205 'applicationMaxVersion': '1.2.3'}]
206 assert notifications[6]['targets'] == [{
207 'applicationMinVersion': '1.2.3'}]
208 assert notifications[7]['targets'] == [{
209 'applicationMaxVersion': '1.2.3'}]
210 assert notifications[8]['targets'] == [{'platform': 'chromium'}]
211 assert notifications[9]['targets'] == [{
212 'platformMinVersion': '1.2.3',
213 'platformMaxVersion': '1.2.3'}]
214 assert notifications[10]['targets'] == [{
215 'platformMinVersion': '1.2.3'}]
216 assert notifications[11]['targets'] == [{
217 'platformMaxVersion': '1.2.3'}]
218 assert notifications[12]['targets'] == [{
219 'blockedTotalMin': 10,
220 'blockedTotalMax': 10}]
221 assert notifications[13]['targets'] == [{'blockedTotalMin': 10}]
222 assert notifications[14]['targets'] == [{'blockedTotalMax': 10}]
223 assert notifications[15]['targets'] == [{'locales': ['en-US']}]
224 assert notifications[16]['targets'] == [{
225 'locales': ['en-US', 'de-DE']}]
226
170 227
171 if __name__ == '__main__': 228 if __name__ == '__main__':
172 unittest.main() 229 unittest.main()
OLDNEW
« no previous file with comments | « sitescripts/notifications/parser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld