本文整理汇总了Python中test.unit.fake_http_connect函数的典型用法代码示例。如果您正苦于以下问题:Python fake_http_connect函数的具体用法?Python fake_http_connect怎么用?Python fake_http_connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fake_http_connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_GETorHEAD_base
def test_GETorHEAD_base(self):
base = Controller(self.app)
req = Request.blank("/v1/a/c/o/with/slashes")
ring = FakeRing()
nodes = list(ring.get_part_nodes(0)) + list(ring.get_more_nodes(0))
with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
resp = base.GETorHEAD_base(req, "object", iter(nodes), "part", "/a/c/o/with/slashes")
self.assertTrue("swift.object/a/c/o/with/slashes" in resp.environ)
self.assertEqual(resp.environ["swift.object/a/c/o/with/slashes"]["status"], 200)
req = Request.blank("/v1/a/c/o")
with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
resp = base.GETorHEAD_base(req, "object", iter(nodes), "part", "/a/c/o")
self.assertTrue("swift.object/a/c/o" in resp.environ)
self.assertEqual(resp.environ["swift.object/a/c/o"]["status"], 200)
req = Request.blank("/v1/a/c")
with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
resp = base.GETorHEAD_base(req, "container", iter(nodes), "part", "/a/c")
self.assertTrue("swift.container/a/c" in resp.environ)
self.assertEqual(resp.environ["swift.container/a/c"]["status"], 200)
req = Request.blank("/v1/a")
with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
resp = base.GETorHEAD_base(req, "account", iter(nodes), "part", "/a")
self.assertTrue("swift.account/a" in resp.environ)
self.assertEqual(resp.environ["swift.account/a"]["status"], 200)
示例2: test_GETorHEAD_base
def test_GETorHEAD_base(self):
base = Controller(self.app)
req = Request.blank('/v1/a/c/o/with/slashes')
with patch('swift.proxy.controllers.base.'
'http_connect', fake_http_connect(200)):
resp = base.GETorHEAD_base(req, 'object', FakeRing(), 'part',
'/a/c/o/with/slashes')
self.assertTrue('swift.object/a/c/o/with/slashes' in resp.environ)
self.assertEqual(
resp.environ['swift.object/a/c/o/with/slashes']['status'], 200)
req = Request.blank('/v1/a/c/o')
with patch('swift.proxy.controllers.base.'
'http_connect', fake_http_connect(200)):
resp = base.GETorHEAD_base(req, 'object', FakeRing(), 'part',
'/a/c/o')
self.assertTrue('swift.object/a/c/o' in resp.environ)
self.assertEqual(resp.environ['swift.object/a/c/o']['status'], 200)
req = Request.blank('/v1/a/c')
with patch('swift.proxy.controllers.base.'
'http_connect', fake_http_connect(200)):
resp = base.GETorHEAD_base(req, 'container', FakeRing(), 'part',
'/a/c')
self.assertTrue('swift.container/a/c' in resp.environ)
self.assertEqual(resp.environ['swift.container/a/c']['status'], 200)
req = Request.blank('/v1/a')
with patch('swift.proxy.controllers.base.'
'http_connect', fake_http_connect(200)):
resp = base.GETorHEAD_base(req, 'account', FakeRing(), 'part',
'/a')
self.assertTrue('swift.account/a' in resp.environ)
self.assertEqual(resp.environ['swift.account/a']['status'], 200)
示例3: test_swift_owner
def test_swift_owner(self):
owner_headers = {
"x-container-read": "value",
"x-container-write": "value",
"x-container-sync-key": "value",
"x-container-sync-to": "value",
}
controller = proxy_server.ContainerController(self.app, "a", "c")
req = Request.blank("/v1/a/c")
with mock.patch(
"swift.proxy.controllers.base.http_connect", fake_http_connect(200, 200, headers=owner_headers)
):
resp = controller.HEAD(req)
self.assertEquals(2, resp.status_int // 100)
for key in owner_headers:
self.assertTrue(key not in resp.headers)
req = Request.blank("/v1/a/c", environ={"swift_owner": True})
with mock.patch(
"swift.proxy.controllers.base.http_connect", fake_http_connect(200, 200, headers=owner_headers)
):
resp = controller.HEAD(req)
self.assertEquals(2, resp.status_int // 100)
for key in owner_headers:
self.assertTrue(key in resp.headers)
示例4: test_GETorHEAD_base
def test_GETorHEAD_base(self):
base = Controller(self.app)
req = Request.blank("/a/c")
with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
resp = base.GETorHEAD_base(req, "container", FakeRing(), "part", "/a/c")
self.assertTrue("swift.container/a/c" in resp.environ)
self.assertEqual(resp.environ["swift.container/a/c"]["status"], 200)
req = Request.blank("/a")
with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
resp = base.GETorHEAD_base(req, "account", FakeRing(), "part", "/a")
self.assertTrue("swift.account/a" in resp.environ)
self.assertEqual(resp.environ["swift.account/a"]["status"], 200)
示例5: test_container_info_in_response_env
def test_container_info_in_response_env(self):
controller = proxy_server.ContainerController(self.app, "a", "c")
with mock.patch("swift.proxy.controllers.base.http_connect", fake_http_connect(200, 200, body="")):
req = Request.blank("/v1/a/c", {"PATH_INFO": "/v1/a/c"})
resp = controller.HEAD(req)
self.assertEqual(2, resp.status_int // 100)
self.assertTrue("swift.container/a/c" in resp.environ)
self.assertEqual(headers_to_container_info(resp.headers), resp.environ["swift.container/a/c"])
示例6: test_get_deleted_account_410
def test_get_deleted_account_410(self):
resp_headers = {'x-account-status': 'deleted'}
req = Request.blank('/v1/a')
with mock.patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(404, headers=resp_headers)):
info = get_account_info(req.environ, self.app)
self.assertEqual(410, info.get('status'))
示例7: setUp
def setUp(self):
self.app = proxy.Application(None, FakeMemcache(),
logger=debug_logger('proxy-ut'),
account_ring=FakeRing(replicas=1),
container_ring=FakeRing(replicas=1))
monkey_patch_mimetools()
self.testdir = \
os.path.join(mkdtemp(), 'tmp_test_object_server_ObjectController')
mkdirs(os.path.join(self.testdir, 'sda1', 'tmp'))
conf = {'devices': self.testdir, 'mount_check': 'false'}
self.obj_ctlr = object_server.ObjectController(
conf, logger=debug_logger('obj-ut'))
http_connect = get_http_connect(fake_http_connect(200),
fake_http_connect(200),
FakeServerConnection(self.obj_ctlr))
swift.proxy.controllers.base.http_connect = http_connect
swift.proxy.controllers.obj.http_connect = http_connect
示例8: test_long_acct_names
def test_long_acct_names(self):
long_acct_name = '%sLongAccountName' % ('Very' * (MAX_ANAME_LEN // 4))
controller = proxy_server.AccountController(self.app, long_acct_name)
req = Request.blank('/v1/%s' % long_acct_name)
with mock.patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(200)):
resp = controller.HEAD(req)
self.assertEquals(400, resp.status_int)
with mock.patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(200)):
resp = controller.GET(req)
self.assertEquals(400, resp.status_int)
with mock.patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(200)):
resp = controller.POST(req)
self.assertEquals(400, resp.status_int)
示例9: test_account_info_in_response_env
def test_account_info_in_response_env(self):
controller = proxy_server.AccountController(self.app, 'AUTH_bob')
with mock.patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(200, body='')):
req = Request.blank('/v1/AUTH_bob', {'PATH_INFO': '/v1/AUTH_bob'})
resp = controller.HEAD(req)
self.assertEqual(2, resp.status_int // 100)
self.assertTrue('swift.account/AUTH_bob' in resp.environ)
self.assertEqual(headers_to_account_info(resp.headers),
resp.environ['swift.account/AUTH_bob'])
示例10: test_container_info_in_response_env
def test_container_info_in_response_env(self):
controller = proxy_server.ContainerController(self.app, 'a', 'c')
with mock.patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(200, 200, body='')):
req = Request.blank('/a/c', {'PATH_INFO': '/a/c'})
resp = controller.HEAD(req)
self.assertEqual(2, resp.status_int // 100)
self.assertTrue("swift.container/a/c" in resp.environ)
self.assertEqual(headers_to_container_info(resp.headers),
resp.environ['swift.container/a/c'])
示例11: test_get_deleted_account
def test_get_deleted_account(self):
resp_headers = {
'x-account-status': 'deleted',
}
controller = proxy_server.AccountController(self.app, 'a')
req = Request.blank('/v1/a')
with mock.patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(404, headers=resp_headers)):
resp = controller.HEAD(req)
self.assertEqual(410, resp.status_int)
示例12: test_container_info_got_cached
def test_container_info_got_cached(self):
controller = proxy_server.ContainerController(self.app, "a", "c")
with mock.patch("swift.proxy.controllers.base.http_connect", fake_http_connect(200, 200, body="")):
req = Request.blank("/v1/a/c", {"PATH_INFO": "/v1/a/c"})
resp = controller.HEAD(req)
self.assertEqual(2, resp.status_int // 100)
# Make sure it's in both swift.infocache and memcache
self.assertIn("container/a/c", resp.environ["swift.infocache"])
self.assertEqual(headers_to_container_info(resp.headers), resp.environ["swift.infocache"]["container/a/c"])
from_memcache = self.app.memcache.get("container/a/c")
self.assertTrue(from_memcache)
示例13: test_swift_owner
def test_swift_owner(self):
owner_headers = {
'x-account-meta-temp-url-key': 'value',
'x-account-meta-temp-url-key-2': 'value'}
controller = proxy_server.AccountController(self.app, 'a')
req = Request.blank('/v1/a')
with mock.patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(200, headers=owner_headers)):
resp = controller.HEAD(req)
self.assertEqual(2, resp.status_int // 100)
for key in owner_headers:
self.assertTrue(key not in resp.headers)
req = Request.blank('/v1/a', environ={'swift_owner': True})
with mock.patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(200, headers=owner_headers)):
resp = controller.HEAD(req)
self.assertEqual(2, resp.status_int // 100)
for key in owner_headers:
self.assertTrue(key in resp.headers)
示例14: test_swift_owner
def test_swift_owner(self):
owner_headers = {
'x-container-read': 'value', 'x-container-write': 'value',
'x-container-sync-key': 'value', 'x-container-sync-to': 'value'}
controller = proxy_server.ContainerController(self.app, 'a', 'c')
req = Request.blank('/v1/a/c')
with mock.patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(200, 200, headers=owner_headers)):
resp = controller.HEAD(req)
self.assertEqual(2, resp.status_int // 100)
for key in owner_headers:
self.assertTrue(key not in resp.headers)
req = Request.blank('/v1/a/c', environ={'swift_owner': True})
with mock.patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(200, 200, headers=owner_headers)):
resp = controller.HEAD(req)
self.assertEqual(2, resp.status_int // 100)
for key in owner_headers:
self.assertTrue(key in resp.headers)
示例15: set_http_connect
def set_http_connect(*args, **kwargs):
old_connect = swift.proxy.controllers.base.http_connect
new_connect = fake_http_connect(*args, **kwargs)
swift.proxy.controllers.base.http_connect = new_connect
swift.proxy.controllers.obj.http_connect = new_connect
swift.proxy.controllers.account.http_connect = new_connect
swift.proxy.controllers.container.http_connect = new_connect
yield new_connect
swift.proxy.controllers.base.http_connect = old_connect
swift.proxy.controllers.obj.http_connect = old_connect
swift.proxy.controllers.account.http_connect = old_connect
swift.proxy.controllers.container.http_connect = old_connect