MCPcopy Create free account
hub / github.com/bleachbit/bleachbit / test_check_updates_mock

Method test_check_updates_mock

tests/TestUpdate.py:44–81  ·  view source on GitHub ↗

Unit test for function check_updates() using mock

(self)

Source from the content-addressed store, hash-verified

42 """Test case for module Update"""
43
44 def test_check_updates_mock(self):
45 """Unit test for function check_updates() using mock"""
46 wa = '<winapp2 url="http://katana.oooninja.com/bleachbit/winapp2.ini" sha512="ce9e18252f608c8aff28811e372124d29a86404f328d3cd51f1f220578744bb8b15f55549eabfe8f1a80657fc940f6d6deece28e0532b3b0901a4c74110f7ba7"/>'
47 update_tests = [
48 ('<updates><stable ver="0.8.4">http://084</stable><beta ver="0.8.5beta">http://085beta</beta>%s</updates>' % wa,
49 (('0.8.4', 'http://084'), ('0.8.5beta', 'http://085beta'))),
50 ('<updates><stable ver="0.8.4">http://084</stable>%s</updates>' % wa,
51 (('0.8.4', 'http://084'), )),
52 ('<updates><beta ver="0.8.5beta">http://085beta</beta>%s</updates>' % wa,
53 (('0.8.5beta', 'http://085beta'), )),
54 ('<updates></updates>', ())]
55
56 with patch('bleachbit.Update.fetch_url') as mock_fetch:
57 # Configure mock responses
58 mock_response = Mock()
59 mock_response.status_code = 200
60 mock_response.content = b''
61
62 for xml, expected in update_tests:
63 # Set up mock response content
64 mock_response.text = xml
65 mock_response.content = xml.encode()
66 mock_fetch.return_value = mock_response
67
68 # Run test
69 updates = check_updates(True, False, None, None)
70 self.assertEqual(updates, expected)
71
72 # check_updates() must send update-specific headers
73 mock_fetch.assert_called()
74 _, fetch_kwargs = mock_fetch.call_args
75 sent_headers = fetch_kwargs['headers']
76 self.assertIn('X-BleachBit-Version', sent_headers)
77 self.assertIn('X-OS-Type', sent_headers)
78 self.assertIn('X-OS-Version', sent_headers)
79 self.assertIn('X-Locale', sent_headers)
80 if 'X-GTK-Version' in sent_headers:
81 self.assertIsInstance(sent_headers['X-GTK-Version'], str)
82
83 def test_check_updates_real_network(self):
84 """Unit test for function check_updates() using real network"""

Callers

nothing calls this directly

Calls 1

check_updatesFunction · 0.90

Tested by

no test coverage detected