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

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

Issue 29327106: Issue 3048 - Mark inactive notifications instead of removing them (Closed)
Patch Set: Created Sept. 10, 2015, 11:16 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 # 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-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 self.assertEqual(notifications[0]["id"], "1") 62 self.assertEqual(notifications[0]["id"], "1")
63 self.assertEqual(notifications[0]["severity"], "information") 63 self.assertEqual(notifications[0]["severity"], "information")
64 self.assertEqual(notifications[0]["title"]["en-US"], "The title") 64 self.assertEqual(notifications[0]["title"]["en-US"], "The title")
65 self.assertEqual(notifications[0]["message"]["en-US"], "The message") 65 self.assertEqual(notifications[0]["message"]["en-US"], "The message")
66 66
67 def test_inactive(self): 67 def test_inactive(self):
68 self.notification_to_load = ("1", """ 68 self.notification_to_load = ("1", """
69 inactive = True 69 inactive = True
70 """) 70 """)
71 notifications = parser.load_notifications() 71 notifications = parser.load_notifications()
72 self.assertEqual(len(notifications), 0) 72 self.assertEqual(len(notifications), 1)
73 self.assertTrue(notifications[0]["inactive"])
73 74
74 def test_in_range(self): 75 def test_in_range(self):
75 current_time = datetime.datetime.now() 76 current_time = datetime.datetime.now()
76 hour_delta = datetime.timedelta(hours=1) 77 hour_delta = datetime.timedelta(hours=1)
77 start_time = current_time - hour_delta 78 start_time = current_time - hour_delta
78 end_time = current_time + hour_delta 79 end_time = current_time + hour_delta
79 self.notification_to_load = ("1", """ 80 self.notification_to_load = ("1", """
80 start = %s 81 start = %s
81 end = %s 82 end = %s
82 """ % (_format_time(start_time), _format_time(end_time))) 83 """ % (_format_time(start_time), _format_time(end_time)))
83 notifications = parser.load_notifications() 84 notifications = parser.load_notifications()
84 self.assertEqual(len(notifications), 1) 85 self.assertEqual(len(notifications), 1)
85 self.assertEqual(notifications[0]["id"], "1") 86 self.assertEqual(notifications[0]["id"], "1")
87 self.assertNotIn("inactive", notifications[0])
86 88
87 def test_after_range(self): 89 def test_after_range(self):
88 current_time = datetime.datetime.now() 90 current_time = datetime.datetime.now()
89 start_time = current_time - datetime.timedelta(hours=2) 91 start_time = current_time - datetime.timedelta(hours=2)
90 end_time = current_time - datetime.timedelta(hours=1) 92 end_time = current_time - datetime.timedelta(hours=1)
91 self.notification_to_load = ("1", """ 93 self.notification_to_load = ("1", """
92 start = %s 94 start = %s
93 end = %s 95 end = %s
94 """ % (_format_time(start_time), _format_time(end_time))) 96 """ % (_format_time(start_time), _format_time(end_time)))
95 notifications = parser.load_notifications() 97 notifications = parser.load_notifications()
96 self.assertEqual(len(notifications), 0) 98 self.assertEqual(len(notifications), 1)
99 self.assertTrue(notifications[0]["inactive"])
97 100
98 def test_before_range(self): 101 def test_before_range(self):
99 current_time = datetime.datetime.now() 102 current_time = datetime.datetime.now()
100 start_time = current_time + datetime.timedelta(hours=1) 103 start_time = current_time + datetime.timedelta(hours=1)
101 end_time = current_time + datetime.timedelta(hours=2) 104 end_time = current_time + datetime.timedelta(hours=2)
102 self.notification_to_load = ("1", """ 105 self.notification_to_load = ("1", """
103 start = %s 106 start = %s
104 end = %s 107 end = %s
105 """ % (_format_time(start_time), _format_time(end_time))) 108 """ % (_format_time(start_time), _format_time(end_time)))
106 notifications = parser.load_notifications() 109 notifications = parser.load_notifications()
107 self.assertEqual(len(notifications), 0) 110 self.assertEqual(len(notifications), 1)
111 self.assertTrue(notifications[0]["inactive"])
108 112
109 def test_start_and_end_not_present(self): 113 def test_start_and_end_not_present(self):
110 current_time = datetime.datetime.now() 114 current_time = datetime.datetime.now()
111 hour_delta = datetime.timedelta(hours=1) 115 hour_delta = datetime.timedelta(hours=1)
112 start_time = current_time - hour_delta 116 start_time = current_time - hour_delta
113 end_time = current_time + hour_delta 117 end_time = current_time + hour_delta
114 self.notification_to_load = ("1", """ 118 self.notification_to_load = ("1", """
115 start = %s 119 start = %s
116 end = %s 120 end = %s
117 """ % (_format_time(start_time), _format_time(end_time))) 121 """ % (_format_time(start_time), _format_time(end_time)))
118 notifications = parser.load_notifications() 122 notifications = parser.load_notifications()
119 self.assertEqual(len(notifications), 1) 123 self.assertEqual(len(notifications), 1)
120 self.assertNotIn("start", notifications[0]) 124 self.assertNotIn("start", notifications[0])
121 self.assertNotIn("end", notifications[0]) 125 self.assertNotIn("end", notifications[0])
122 126
123 if __name__ == "__main__": 127 if __name__ == "__main__":
124 unittest.main() 128 unittest.main()
OLDNEW
« no previous file with comments | « sitescripts/notifications/test/notification.py ('k') | sitescripts/notifications/web/notification.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld