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

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

Issue 29570562: Issue 5827 - Assign new groups even if prior groups are present (Closed)
Patch Set: Revert back to mocking load_notification Created Oct. 10, 2017, 9:02 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
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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 def test_stays_in_group_when_notification_inactive(self): 343 def test_stays_in_group_when_notification_inactive(self):
344 self.load_notifications_mock.return_value = [ 344 self.load_notifications_mock.return_value = [
345 {'id': 'a', 'inactive': True} 345 {'id': 'a', 'inactive': True}
346 ] 346 ]
347 result = json.loads(notification.notification({ 347 result = json.loads(notification.notification({
348 'QUERY_STRING': 'lastVersion=197001010000-a/0-b/1' 348 'QUERY_STRING': 'lastVersion=197001010000-a/0-b/1'
349 }, lambda *args: None)) 349 }, lambda *args: None))
350 self.assertEqual(len(result['notifications']), 0) 350 self.assertEqual(len(result['notifications']), 0)
351 self.assertRegexpMatches(result['version'], r'-a/0') 351 self.assertRegexpMatches(result['version'], r'-a/0')
352 352
353 def test_stays_in_group_when_notification_inactive_assign_new_group(self):
354 # See: https://issues.adblockplus.org/ticket/5827
355 self.load_notifications_mock.return_value = [
356 {'id': '1', 'inactive': True},
357 {'id': '2', 'variants': [
358 {'sample': 1, 'title': {'en-US': '2.1'}, 'message': {'en-US': '2 .1'}},
359 ]},
360 ]
361 result = json.loads(notification.notification({
362 'QUERY_STRING': 'lastVersion=197001010000-1/0'
363 }, lambda *args: None))
364 self.assertEqual(len(result['notifications']), 1)
365 self.assertRegexpMatches(result['version'], r'-1/0-2/1')
366
353 def test_inactive_notifications_not_returned(self): 367 def test_inactive_notifications_not_returned(self):
354 self.load_notifications_mock.return_value = [ 368 self.load_notifications_mock.return_value = [
355 {'id': 'a', 'title': {'en-US': ''}, 'message': {'en-US': ''}, 'inact ive': True}, 369 {'id': 'a', 'title': {'en-US': ''}, 'message': {'en-US': ''}, 'inact ive': True},
356 {'id': 'b', 'title': {'en-US': ''}, 'message': {'en-US': ''}, 'inact ive': False}, 370 {'id': 'b', 'title': {'en-US': ''}, 'message': {'en-US': ''}, 'inact ive': False},
357 {'id': 'c', 'title': {'en-US': ''}, 'message': {'en-US': ''}} 371 {'id': 'c', 'title': {'en-US': ''}, 'message': {'en-US': ''}}
358 ] 372 ]
359 result = json.loads(notification.notification({}, lambda *args: None)) 373 result = json.loads(notification.notification({}, lambda *args: None))
360 self.assertEqual(len(result['notifications']), 2) 374 self.assertEqual(len(result['notifications']), 2)
361 self.assertEqual(result['notifications'][0]['id'], 'b') 375 self.assertEqual(result['notifications'][0]['id'], 'b')
362 self.assertEqual(result['notifications'][1]['id'], 'c') 376 self.assertEqual(result['notifications'][1]['id'], 'c')
363 377
364 def test_inactive_notification_variant_not_returned(self): 378 def test_inactive_notification_variant_not_returned(self):
365 self.load_notifications_mock.return_value = [ 379 self.load_notifications_mock.return_value = [
366 {'id': 'a', 'inactive': True} 380 {'id': 'a', 'inactive': True}
367 ] 381 ]
368 result = json.loads(notification.notification({ 382 result = json.loads(notification.notification({
369 'QUERY_STRING': 'lastVersion=197001010000-a/1' 383 'QUERY_STRING': 'lastVersion=197001010000-a/1'
370 }, lambda *args: None)) 384 }, lambda *args: None))
371 self.assertEqual(len(result['notifications']), 0) 385 self.assertEqual(len(result['notifications']), 0)
372 386
373 387
374 if __name__ == '__main__': 388 if __name__ == '__main__':
375 unittest.main() 389 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | sitescripts/notifications/web/notification.py » ('j') | sitescripts/notifications/web/notification.py » ('J')

Powered by Google App Engine
This is Rietveld