Merge "Remove requests to example.com during unit testing"
This commit is contained in:
commit
98af3b309e
|
@ -18,6 +18,7 @@ from six.moves import urllib
|
|||
|
||||
import glance.common.exception as exception
|
||||
from glance.common.scripts.image_import import main as image_import_script
|
||||
from glance.common.scripts import utils
|
||||
from glance.common import store_utils
|
||||
|
||||
import glance.tests.utils as test_utils
|
||||
|
@ -83,9 +84,11 @@ class TestImageImport(test_utils.BaseTestCase):
|
|||
image_properties,
|
||||
None))
|
||||
|
||||
def test_set_image_data_http(self):
|
||||
@mock.patch.object(utils, 'get_image_data_iter')
|
||||
def test_set_image_data_http(self, mock_image_iter):
|
||||
uri = 'http://www.example.com'
|
||||
image = mock.Mock()
|
||||
mock_image_iter.return_value = test_utils.FakeHTTPResponse()
|
||||
self.assertEqual(None,
|
||||
image_import_script.set_image_data(image, uri, None))
|
||||
|
||||
|
|
|
@ -135,23 +135,3 @@ class TestScriptsUtils(test_utils.BaseTestCase):
|
|||
location = 'cinder://'
|
||||
self.assertRaises(urllib.error.URLError,
|
||||
script_utils.validate_location_uri, location)
|
||||
|
||||
def test_get_image_data_http(self):
|
||||
uri = "http://example.com"
|
||||
response = urllib.request.urlopen(uri)
|
||||
expected = response.read()
|
||||
self.assertEqual(expected,
|
||||
script_utils.get_image_data_iter(uri).read())
|
||||
|
||||
def test_get_image_data_https(self):
|
||||
uri = "https://example.com"
|
||||
response = urllib.request.urlopen(uri)
|
||||
expected = response.read()
|
||||
self.assertEqual(expected,
|
||||
script_utils.get_image_data_iter(uri).read())
|
||||
|
||||
def test_get_image_data_http_error(self):
|
||||
uri = "http:/example.com"
|
||||
self.assertRaises(urllib.error.URLError,
|
||||
script_utils.get_image_data_iter,
|
||||
uri)
|
||||
|
|
|
@ -1059,7 +1059,7 @@ class TestGlanceAPI(base.IsolatedUnitTest):
|
|||
fixture_headers = {'x-image-meta-store': 'file',
|
||||
'x-image-meta-disk-format': 'vhd',
|
||||
'x-glance-api-copy-from':
|
||||
'http://example.com/i.ovf',
|
||||
self._http_loc_url('/non_existing_image_path'),
|
||||
'x-image-meta-container-format': 'ovf',
|
||||
'x-image-meta-name': 'fake image #F'}
|
||||
|
||||
|
@ -1181,19 +1181,19 @@ class TestGlanceAPI(base.IsolatedUnitTest):
|
|||
def test_create_image_with_nonexistent_location_url(self):
|
||||
# Ensure HTTP 404 response returned when try to create
|
||||
# image with non-existent http location URL.
|
||||
|
||||
fixture_headers = {
|
||||
'x-image-meta-name': 'bogus',
|
||||
'x-image-meta-location': 'http://example.com/images/123',
|
||||
'x-image-meta-location':
|
||||
self._http_loc_url('/non_existing_image_path'),
|
||||
'x-image-meta-disk-format': 'qcow2',
|
||||
'x-image-meta-container-format': 'bare',
|
||||
}
|
||||
|
||||
req = webob.Request.blank("/images")
|
||||
req.method = 'POST'
|
||||
|
||||
for k, v in six.iteritems(fixture_headers):
|
||||
req.headers[k] = v
|
||||
|
||||
res = req.get_response(self.api)
|
||||
self.assertEqual(404, res.status_int)
|
||||
|
||||
|
|
|
@ -444,7 +444,12 @@ def start_http_server(image_id, image_data):
|
|||
return
|
||||
|
||||
def do_HEAD(self):
|
||||
self.send_response(200)
|
||||
# reserve non_existing_image_path for the cases where we expect
|
||||
# 404 from the server
|
||||
if 'non_existing_image_path' in self.path:
|
||||
self.send_response(404)
|
||||
else:
|
||||
self.send_response(200)
|
||||
self.send_header('Content-Length', str(len(fixture)))
|
||||
self.end_headers()
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue