Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style |
| 3 | # license that can be found in the LICENSE file or at |
| 4 | # https://developers.google.com/open-source/licenses/bsd |
| 5 | |
| 6 | """Tests for alert display helpers.""" |
| 7 | from __future__ import print_function |
| 8 | from __future__ import division |
| 9 | from __future__ import absolute_import |
| 10 | |
| 11 | import time |
| 12 | import unittest |
| 13 | |
| 14 | import ezt |
| 15 | |
| 16 | from framework import alerts |
| 17 | from testing import fake |
| 18 | from testing import testing_helpers |
| 19 | |
| 20 | |
| 21 | class AlertsViewTest(unittest.TestCase): |
| 22 | |
| 23 | def testTimestamp(self): |
| 24 | """Tests that alerts are only shown when the timestamp is valid.""" |
| 25 | project = fake.Project(project_name='testproj') |
| 26 | |
| 27 | now = int(time.time()) |
| 28 | mr = testing_helpers.MakeMonorailRequest( |
| 29 | path='/p/testproj/?updated=10&ts=%s' % now, project=project) |
| 30 | alerts_view = alerts.AlertsView(mr) |
| 31 | self.assertEqual(10, alerts_view.updated) |
| 32 | self.assertEqual(ezt.boolean(True), alerts_view.show) |
| 33 | |
| 34 | now -= 10 |
| 35 | mr = testing_helpers.MakeMonorailRequest( |
| 36 | path='/p/testproj/?updated=10&ts=%s' % now, project=project) |
| 37 | alerts_view = alerts.AlertsView(mr) |
| 38 | self.assertEqual(ezt.boolean(False), alerts_view.show) |
| 39 | |
| 40 | mr = testing_helpers.MakeMonorailRequest( |
| 41 | path='/p/testproj/?updated=10', project=project) |
| 42 | alerts_view = alerts.AlertsView(mr) |
| 43 | self.assertEqual(ezt.boolean(False), alerts_view.show) |