本文整理汇总了Python中test.unit.fake_http_connect函数的典型用法代码示例。如果您正苦于以下问题:Python fake_http_connect函数的具体用法?Python fake_http_connect怎么用?Python fake_http_connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fake_http_connect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:helen5haha,项目名称:swift,代码行数:25,代码来源:test_base.py
示例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)
开发者ID:10389030,项目名称:swift,代码行数:32,代码来源:test_base.py
示例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)
开发者ID:prashanthpai,项目名称:gluster-swift,代码行数:26,代码来源:test_container.py
示例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)
开发者ID:r0mik,项目名称:swift,代码行数:13,代码来源:test_base.py
示例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"])
开发者ID:prashanthpai,项目名称:gluster-swift,代码行数:8,代码来源:test_container.py
示例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'))
开发者ID:bebule,项目名称:swift,代码行数:8,代码来源:test_account.py
示例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
开发者ID:AsherBond,项目名称:swift,代码行数:19,代码来源:test_sysmeta.py
示例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)
开发者ID:10389030,项目名称:swift,代码行数:19,代码来源:test_account.py
示例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'])
开发者ID:BjoernT,项目名称:swift,代码行数:10,代码来源:test_account.py
示例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'])
开发者ID:Awingu,项目名称:swift,代码行数:10,代码来源:test_container.py
示例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)
开发者ID:BjoernT,项目名称:swift,代码行数:11,代码来源:test_account.py
示例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)
开发者ID:prashanthpai,项目名称:swift,代码行数:11,代码来源:test_container.py
示例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)
开发者ID:BjoernT,项目名称:swift,代码行数:21,代码来源:test_account.py
示例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)
开发者ID:harrisonfeng,项目名称:swift,代码行数:21,代码来源:test_container.py
示例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
开发者ID:atulshridhar,项目名称:swift,代码行数:12,代码来源:test_obj.py
示例16: _assert_responses
def _assert_responses(self, method, test_cases):
controller = proxy_server.ContainerController(self.app, "a", "c")
for responses, expected in test_cases:
with mock.patch("swift.proxy.controllers.base.http_connect", fake_http_connect(*responses)):
req = Request.blank("/v1/a/c")
resp = getattr(controller, method)(req)
self.assertEqual(
expected,
resp.status_int,
"Expected %s but got %s. Failed case: %s" % (expected, resp.status_int, str(responses)),
)
开发者ID:prashanthpai,项目名称:swift,代码行数:13,代码来源:test_container.py
示例17: setUp
def setUp(self):
skip_if_no_xattrs()
self.app = proxy.Application(None, FakeMemcache(),
logger=debug_logger('proxy-ut'),
account_ring=FakeRing(replicas=1),
container_ring=FakeRing(replicas=1))
self.copy_app = ServerSideCopyMiddleware(self.app, {})
self.tmpdir = mkdtemp()
self.testdir = os.path.join(self.tmpdir,
'tmp_test_object_server_ObjectController')
mkdirs(os.path.join(self.testdir, 'sda', '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))
self.orig_base_http_connect = swift.proxy.controllers.base.http_connect
self.orig_obj_http_connect = swift.proxy.controllers.obj.http_connect
swift.proxy.controllers.base.http_connect = http_connect
swift.proxy.controllers.obj.http_connect = http_connect
开发者ID:mahak,项目名称:swift,代码行数:23,代码来源:test_sysmeta.py
示例18: 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.tmpdir = mkdtemp()
self.testdir = os.path.join(self.tmpdir, "tmp_test_object_server_ObjectController")
mkdirs(os.path.join(self.testdir, "sda", "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)
)
self.orig_base_http_connect = swift.proxy.controllers.base.http_connect
self.orig_obj_http_connect = swift.proxy.controllers.obj.http_connect
swift.proxy.controllers.base.http_connect = http_connect
swift.proxy.controllers.obj.http_connect = http_connect
开发者ID:iloveyou416068,项目名称:swift-1,代码行数:23,代码来源:test_sysmeta.py
示例19: test_options_unauthorized
def test_options_unauthorized(self):
base = Controller(self.app)
base.account_name = "a"
base.container_name = "c"
self.app.cors_allow_origin = ["http://NOT_IT"]
req = Request.blank(
"/v1/a/c/o",
environ={"swift.cache": FakeCache()},
headers={"Origin": "http://m.com", "Access-Control-Request-Method": "GET"},
)
with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
resp = base.OPTIONS(req)
self.assertEqual(resp.status_int, 401)
开发者ID:helen5haha,项目名称:swift,代码行数:14,代码来源:test_base.py
示例20: 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)
开发者ID:ISCAS-VDI,项目名称:swift-base,代码行数:14,代码来源:test_container.py
注:本文中的test.unit.fake_http_connect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论