Unit test for fetch_url() header handling
(self)
| 166 | error_msg) |
| 167 | |
| 168 | def test_fetch_url_headers(self): |
| 169 | """Unit test for fetch_url() header handling""" |
| 170 | with patch('bleachbit.Network.requests.Session') as mock_session: |
| 171 | session_instance = MagicMock() |
| 172 | session_instance.get.return_value = Mock() |
| 173 | mock_session.return_value.__enter__.return_value = session_instance |
| 174 | |
| 175 | tests = [ |
| 176 | # (custom_headers, expected_custom_key) |
| 177 | (None, None), |
| 178 | ({'X-BleachBit-Version': '5.1.0'}, 'X-BleachBit-Version'), |
| 179 | ] |
| 180 | for custom_headers, expected_custom_key in tests: |
| 181 | with self.subTest(custom_headers=custom_headers): |
| 182 | response = fetch_url('https://example.com', max_retries=0, timeout=5, |
| 183 | headers=custom_headers) |
| 184 | kwargs = session_instance.get.call_args.kwargs |
| 185 | headers = kwargs['headers'] |
| 186 | self.assertEqual( |
| 187 | response, session_instance.get.return_value) |
| 188 | self.assertIsInstance(headers, dict) |
| 189 | self.assertIn('User-Agent', headers) |
| 190 | self.assertEqual(headers['User-Agent'], get_user_agent()) |
| 191 | self.assertNotIn('X-OS-Type', headers) |
| 192 | if expected_custom_key: |
| 193 | self.assertIn(expected_custom_key, headers) |
| 194 | self.assertEqual(headers[expected_custom_key], |
| 195 | custom_headers[expected_custom_key]) |
| 196 | else: |
| 197 | self.assertNotIn('X-BleachBit-Version', headers) |
| 198 | |
| 199 | def test_fetch_url_retry(self): |
| 200 | """Unit test for fetch_url() with retry""" |
nothing calls this directly
no test coverage detected