Coverage for tests/test_status_banner.py: 100%
29 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-18 22:11 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-18 22:11 +0000
1import unittest
2from unittest.mock import patch
4from flask import render_template
6from webapp.app import app
9class TestStatusBanner(unittest.TestCase):
10 def setUp(self):
11 app.testing = True
12 self.app = app
13 self.client = app.test_client()
15 def test_banner_rendered_when_status_banner_set(self):
16 message = "Temporary Charmhub maintenance in progress."
18 with patch("webapp.handlers.STATUS_BANNER", message):
19 response = self.client.get("/")
21 self.assertEqual(response.status_code, 200)
22 self.assertIn('id="status-banner"', response.text)
23 self.assertIn("p-notification--caution", response.text)
24 self.assertIn(message, response.text)
26 def test_banner_hidden_when_status_banner_empty(self):
27 with patch("webapp.handlers.STATUS_BANNER", ""):
28 response = self.client.get("/")
30 self.assertEqual(response.status_code, 200)
31 self.assertNotIn('id="status-banner"', response.text)
33 def test_publisher_layout_uses_banner(self):
34 message = "Publisher maintenance notice."
36 with patch("webapp.handlers.STATUS_BANNER", message):
37 with self.app.test_request_context("/test-entity/listing"):
38 body = render_template(
39 "publisher/publisher.html",
40 package={
41 "name": "test-entity",
42 "publisher": {"display-name": "Test Publisher"},
43 },
44 )
46 self.assertIn('id="status-banner"', body)
47 self.assertIn(message, body)