OLD | NEW |
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 severity = information | 56 severity = information |
57 title.en-US = The title | 57 title.en-US = The title |
58 message.en-US = The message | 58 message.en-US = The message |
59 """) | 59 """) |
60 notifications = parser.load_notifications() | 60 notifications = parser.load_notifications() |
61 self.assertEqual(len(notifications), 1) | 61 self.assertEqual(len(notifications), 1) |
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 self.assertNotIn("inactive", notifications[0]) |
66 | 67 |
67 def test_inactive(self): | 68 def test_inactive(self): |
68 self.notification_to_load = ("1", """ | 69 self.notification_to_load = ("1", """ |
69 inactive = True | 70 inactive = True |
70 """) | 71 """) |
71 notifications = parser.load_notifications() | 72 notifications = parser.load_notifications() |
72 self.assertEqual(len(notifications), 0) | 73 self.assertEqual(len(notifications), 1) |
| 74 self.assertTrue(notifications[0]["inactive"]) |
73 | 75 |
74 def test_in_range(self): | 76 def test_in_range(self): |
75 current_time = datetime.datetime.now() | 77 current_time = datetime.datetime.now() |
76 hour_delta = datetime.timedelta(hours=1) | 78 hour_delta = datetime.timedelta(hours=1) |
77 start_time = current_time - hour_delta | 79 start_time = current_time - hour_delta |
78 end_time = current_time + hour_delta | 80 end_time = current_time + hour_delta |
79 self.notification_to_load = ("1", """ | 81 self.notification_to_load = ("1", """ |
80 start = %s | 82 start = %s |
81 end = %s | 83 end = %s |
82 """ % (_format_time(start_time), _format_time(end_time))) | 84 """ % (_format_time(start_time), _format_time(end_time))) |
83 notifications = parser.load_notifications() | 85 notifications = parser.load_notifications() |
84 self.assertEqual(len(notifications), 1) | 86 self.assertEqual(len(notifications), 1) |
85 self.assertEqual(notifications[0]["id"], "1") | 87 self.assertEqual(notifications[0]["id"], "1") |
| 88 self.assertNotIn("inactive", notifications[0]) |
86 | 89 |
87 def test_after_range(self): | 90 def test_after_range(self): |
88 current_time = datetime.datetime.now() | 91 current_time = datetime.datetime.now() |
89 start_time = current_time - datetime.timedelta(hours=2) | 92 start_time = current_time - datetime.timedelta(hours=2) |
90 end_time = current_time - datetime.timedelta(hours=1) | 93 end_time = current_time - datetime.timedelta(hours=1) |
91 self.notification_to_load = ("1", """ | 94 self.notification_to_load = ("1", """ |
92 start = %s | 95 start = %s |
93 end = %s | 96 end = %s |
94 """ % (_format_time(start_time), _format_time(end_time))) | 97 """ % (_format_time(start_time), _format_time(end_time))) |
95 notifications = parser.load_notifications() | 98 notifications = parser.load_notifications() |
96 self.assertEqual(len(notifications), 0) | 99 self.assertEqual(len(notifications), 1) |
| 100 self.assertTrue(notifications[0]["inactive"]) |
97 | 101 |
98 def test_before_range(self): | 102 def test_before_range(self): |
99 current_time = datetime.datetime.now() | 103 current_time = datetime.datetime.now() |
100 start_time = current_time + datetime.timedelta(hours=1) | 104 start_time = current_time + datetime.timedelta(hours=1) |
101 end_time = current_time + datetime.timedelta(hours=2) | 105 end_time = current_time + datetime.timedelta(hours=2) |
102 self.notification_to_load = ("1", """ | 106 self.notification_to_load = ("1", """ |
103 start = %s | 107 start = %s |
104 end = %s | 108 end = %s |
105 """ % (_format_time(start_time), _format_time(end_time))) | 109 """ % (_format_time(start_time), _format_time(end_time))) |
106 notifications = parser.load_notifications() | 110 notifications = parser.load_notifications() |
107 self.assertEqual(len(notifications), 0) | 111 self.assertEqual(len(notifications), 1) |
| 112 self.assertTrue(notifications[0]["inactive"]) |
108 | 113 |
109 def test_start_and_end_not_present(self): | 114 def test_start_and_end_not_present(self): |
110 current_time = datetime.datetime.now() | 115 current_time = datetime.datetime.now() |
111 hour_delta = datetime.timedelta(hours=1) | 116 hour_delta = datetime.timedelta(hours=1) |
112 start_time = current_time - hour_delta | 117 start_time = current_time - hour_delta |
113 end_time = current_time + hour_delta | 118 end_time = current_time + hour_delta |
114 self.notification_to_load = ("1", """ | 119 self.notification_to_load = ("1", """ |
115 start = %s | 120 start = %s |
116 end = %s | 121 end = %s |
117 """ % (_format_time(start_time), _format_time(end_time))) | 122 """ % (_format_time(start_time), _format_time(end_time))) |
118 notifications = parser.load_notifications() | 123 notifications = parser.load_notifications() |
119 self.assertEqual(len(notifications), 1) | 124 self.assertEqual(len(notifications), 1) |
| 125 self.assertNotIn("inactive", notifications[0]) |
120 self.assertNotIn("start", notifications[0]) | 126 self.assertNotIn("start", notifications[0]) |
121 self.assertNotIn("end", notifications[0]) | 127 self.assertNotIn("end", notifications[0]) |
122 | 128 |
123 if __name__ == "__main__": | 129 if __name__ == "__main__": |
124 unittest.main() | 130 unittest.main() |
OLD | NEW |