blob: 122a0feeec4cfb9418dfdd4378c9befbe579291a [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# 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.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Tests for alert display helpers."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10import time
11import unittest
12
13import ezt
14
15from framework import alerts
16from testing import fake
17from testing import testing_helpers
18
19
20class 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)