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