Merge "Convert httpretty tests to requests-mock"

This commit is contained in:
Jenkins 2015-02-25 20:47:34 +00:00 committed by Gerrit Code Review
commit 08ee0a0eef
2 changed files with 17 additions and 29 deletions

@ -6,9 +6,9 @@ mock>=1.0
# Unit testing
coverage>=3.6
httpretty>=0.8.0,!=0.8.1,!=0.8.2,!=0.8.3
fixtures>=0.3.14
python-subunit>=0.0.18
requests-mock>=0.5.1 # Apache-2.0
testrepository>=0.0.18
testscenarios>=0.4
testtools>=0.9.34

@ -23,10 +23,10 @@ import mock
import tempfile
import uuid
import httpretty
from oslo_config import cfg
from oslo_utils import units
from oslotest import moxstubout
import requests_mock
import six
import StringIO
import swiftclient
@ -1207,42 +1207,29 @@ class TestMultiTenantStoreContext(base.StoreBaseTest):
}]
self.addCleanup(self.conf.reset)
@httpretty.activate
def test_download_context(self):
@requests_mock.mock()
def test_download_context(self, m):
"""Verify context (ie token) is passed to swift on download."""
self.config(swift_store_multi_tenant=True)
store = Store(self.conf)
store.configure()
uri = "swift+http://127.0.0.1:0/glance_123/123"
uri = "swift+http://127.0.0.1/glance_123/123"
loc = location.get_location_from_uri(uri, conf=self.conf)
ctx = context.RequestContext(
service_catalog=self.service_catalog, user='tenant:user1',
tenant='tenant', auth_token='0123')
httpretty.register_uri(httpretty.GET,
"http://127.0.0.1:0/glance_123/123",
status=200)
m.get("http://127.0.0.1/glance_123/123")
store.get(loc, context=ctx)
self.assertEqual(
'0123', httpretty.last_request().headers['X-Auth-Token'])
self.assertEqual('0123', m.last_request.headers['X-Auth-Token'])
@httpretty.activate
def test_upload_context(self):
@requests_mock.mock()
def test_upload_context(self, m):
"""Verify context (ie token) is passed to swift on upload."""
def put_callback(request, uri, headers):
self.assertEqual('Some data', request.body)
self.assertEqual('0123', request.headers['X-Auth-Token'])
return (201, headers, "")
def head_callback(request, uri, headers):
self.assertEqual('0123', request.headers['X-Auth-Token'])
return (200, headers, "")
httpretty.register_uri(httpretty.HEAD,
"http://127.0.0.1:0/glance_123",
head_callback)
httpretty.register_uri(httpretty.PUT,
"http://127.0.0.1:0/glance_123/123",
put_callback)
head_req = m.head("http://127.0.0.1/glance_123",
text='Some data',
status_code=201)
put_req = m.put("http://127.0.0.1/glance_123/123")
self.config(swift_store_multi_tenant=True)
store = Store(self.conf)
@ -1253,8 +1240,9 @@ class TestMultiTenantStoreContext(base.StoreBaseTest):
tenant='tenant', auth_token='0123')
store.add('123', pseudo_file, pseudo_file.len,
context=ctx)
self.assertEqual(
'0123', httpretty.last_request().headers['X-Auth-Token'])
self.assertEqual('0123', head_req.last_request.headers['X-Auth-Token'])
self.assertEqual('0123', put_req.last_request.headers['X-Auth-Token'])
class FakeGetEndpoint(object):