File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,15 +105,23 @@ def test_metadata_does_not_exist(self):
105105 self .assertIsNone (metadata )
106106
107107 def test_request_exception (self ):
108+ import requests
109+
108110 metadata_key = 'test_url_cannot_connect'
109111 metadata_url = 'http://metadata.invalid/'
110112
111- patch = mock .patch (
113+ requests_get_mock = mock .Mock (spec = ['__call__' ])
114+ requests_get_mock .side_effect = requests .exceptions .RequestException
115+
116+ requests_get_patch = mock .patch ('requests.get' , requests_get_mock )
117+
118+ url_patch = mock .patch (
112119 'google.cloud.logging._helpers.METADATA_URL' ,
113120 new = metadata_url )
114121
115- with patch :
116- metadata = self ._call_fut (metadata_key )
122+ with requests_get_patch :
123+ with url_patch :
124+ metadata = self ._call_fut (metadata_key )
117125
118126 self .assertIsNone (metadata )
119127
You can’t perform that action at this time.
0 commit comments