def _test_verify_https_request(self, https_ca_bundle=None): mock_service = base.BaseHTTPMetadataService( base_url=mock.sentinel.url, https_allow_insecure=mock.sentinel.allow_insecure, https_ca_bundle=https_ca_bundle) response = mock_service._verify_https_request() if not https_ca_bundle: self.assertTrue(mock.sentinel.allow_insecure) else: self.assertEqual(response, https_ca_bundle)
def _test_get_data(self, mock_http_request, mock_urljoin, expected_response, expected_value): fake_base_url = mock.Mock() http_service = base.BaseHTTPMetadataService(fake_base_url) mock_request = mock.Mock() mock_urljoin.return_value = 'some_url' mock_http_request.side_effect = [expected_response] if expected_value: self.assertRaises(expected_value, http_service._get_data, mock_request) else: response = http_service._get_data(mock_request) self.assertEqual(expected_response, response)
def setUp(self): self._mock_base_url = "http://metadata.mock/" self._service = base.BaseHTTPMetadataService("http://metadata.mock/")