blob: 0c398c1ca3a7c717fa81ac93c35b6dbbee58e5f0 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# 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."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11import time
12import unittest
13
14import ezt
15
16from framework import alerts
17from testing import fake
18from testing import testing_helpers
19
20
21class 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)