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

1import unittest 

2from unittest.mock import patch 

3 

4from flask import render_template 

5 

6from webapp.app import app 

7 

8 

9class TestStatusBanner(unittest.TestCase): 

10 def setUp(self): 

11 app.testing = True 

12 self.app = app 

13 self.client = app.test_client() 

14 

15 def test_banner_rendered_when_status_banner_set(self): 

16 message = "Temporary Charmhub maintenance in progress." 

17 

18 with patch("webapp.handlers.STATUS_BANNER", message): 

19 response = self.client.get("/") 

20 

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) 

25 

26 def test_banner_hidden_when_status_banner_empty(self): 

27 with patch("webapp.handlers.STATUS_BANNER", ""): 

28 response = self.client.get("/") 

29 

30 self.assertEqual(response.status_code, 200) 

31 self.assertNotIn('id="status-banner"', response.text) 

32 

33 def test_publisher_layout_uses_banner(self): 

34 message = "Publisher maintenance notice." 

35 

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 ) 

45 

46 self.assertIn('id="status-banner"', body) 

47 self.assertIn(message, body)