|
1 | 1 | from __future__ import absolute_import, unicode_literals
|
2 | 2 |
|
| 3 | +import sys |
| 4 | +import unittest |
3 | 5 | from unittest import TestCase
|
4 | 6 | from wsgiref.util import setup_testing_defaults
|
5 | 7 |
|
6 | 8 | from prometheus_client import CollectorRegistry, Counter, make_wsgi_app
|
7 |
| -from prometheus_client.exposition import CONTENT_TYPE_LATEST |
| 9 | +from prometheus_client.exposition import _bake_output, CONTENT_TYPE_LATEST |
8 | 10 |
|
9 | 11 |
|
10 | 12 | class WSGITest(TestCase):
|
@@ -65,3 +67,22 @@ def test_report_metrics_3(self):
|
65 | 67 |
|
66 | 68 | def test_report_metrics_4(self):
|
67 | 69 | self.validate_metrics("failed_requests", "Number of failed requests", 7)
|
| 70 | + |
| 71 | + @unittest.skipIf(sys.version_info < (3, 3), "Test requires Python 3.3+.") |
| 72 | + def test_favicon_path(self): |
| 73 | + from unittest.mock import patch |
| 74 | + |
| 75 | + # Create mock to enable counting access of _bake_output |
| 76 | + with patch("prometheus_client.exposition._bake_output", side_effect=_bake_output) as mock: |
| 77 | + # Create and run WSGI app |
| 78 | + app = make_wsgi_app(self.registry) |
| 79 | + # Try accessing the favicon path |
| 80 | + favicon_environ = dict(self.environ) |
| 81 | + favicon_environ['PATH_INFO'] = '/favicon.ico' |
| 82 | + outputs = app(favicon_environ, self.capture) |
| 83 | + # Test empty response |
| 84 | + self.assertEqual(outputs, [b'']) |
| 85 | + self.assertEqual(mock.call_count, 0) |
| 86 | + # Try accessing normal paths |
| 87 | + app(self.environ, self.capture) |
| 88 | + self.assertEqual(mock.call_count, 1) |
0 commit comments