Beispiel #1
0
 def test_get_object_info_env(self):
     cached = {"status": 200, "length": 3333, "type": "application/json", "meta": {}}
     env_key = get_object_env_key("account", "cont", "obj")
     req = Request.blank("/v1/account/cont/obj", environ={env_key: cached, "swift.cache": FakeCache({})})
     resp = get_object_info(req.environ, "xxx")
     self.assertEquals(resp["length"], 3333)
     self.assertEquals(resp["type"], "application/json")
Beispiel #2
0
 def test_get_object_info_env(self):
     cached = {'status': 200,
               'length': 3333,
               'type': 'application/json',
               'meta': {}}
     env_key = get_object_env_key("account", "cont", "obj")
     req = Request.blank("/v1/account/cont/obj",
                         environ={env_key: cached,
                                  'swift.cache': FakeCache({})})
     resp = get_object_info(req.environ, 'xxx')
     self.assertEquals(resp['length'], 3333)
     self.assertEquals(resp['type'], 'application/json')
Beispiel #3
0
 def test_get_object_info_env(self):
     cached = {'status': 200,
               'length': 3333,
               'type': 'application/json',
               'meta': {}}
     env_key = get_object_env_key("account", "cont", "obj")
     req = Request.blank("/v1/account/cont/obj",
                         environ={env_key: cached,
                                  'swift.cache': FakeCache({})})
     resp = get_object_info(req.environ, 'xxx')
     self.assertEquals(resp['length'], 3333)
     self.assertEquals(resp['type'], 'application/json')
Beispiel #4
0
 def __call__(self, env, start_response):
     if env['REQUEST_METHOD'] == "HEAD" and \
             env['PATH_INFO'] == '/v1/a/c2/o2':
         env_key = get_object_env_key('a', 'c2', 'o2')
         env[env_key] = headers_to_object_info(self.headers, 200)
         start_response('200 OK', self.headers)
     elif env['REQUEST_METHOD'] == "HEAD" and \
             env['PATH_INFO'] == '/v1/a/c2/o3':
         start_response('404 Not Found', [])
     else:
         # Cache the account_info (same as a real application)
         cache_key, env_key = _get_cache_key('a', None)
         env[env_key] = headers_to_account_info(self.headers, 200)
         start_response('200 OK', self.headers)
     return []
Beispiel #5
0
    def __init__(self, headers, env, account, container, obj):
        self.headers = headers
        self.status_int = FakeResponse_status_int
        self.environ = env
        if obj:
            env_key = get_object_env_key(account, container, obj)
        else:
            cache_key, env_key = _get_cache_key(account, container)

        if account and container and obj:
            info = headers_to_object_info(headers, FakeResponse_status_int)
        elif account and container:
            info = headers_to_container_info(headers, FakeResponse_status_int)
        else:
            info = headers_to_account_info(headers, FakeResponse_status_int)
        env[env_key] = info
Beispiel #6
0
    def __init__(self, headers, env, account, container, obj):
        self.headers = headers
        self.status_int = FakeResponse_status_int
        self.environ = env
        if obj:
            env_key = get_object_env_key(account, container, obj)
        else:
            cache_key, env_key = _get_cache_key(account, container)

        if account and container and obj:
            info = headers_to_object_info(headers, FakeResponse_status_int)
        elif account and container:
            info = headers_to_container_info(headers, FakeResponse_status_int)
        else:
            info = headers_to_account_info(headers, FakeResponse_status_int)
        env[env_key] = info
 def __call__(self, env, start_response):
     if 'swift.authorize' in env:
         aresp = env['swift.authorize'](Request(env))
         if aresp:
             return aresp(env, start_response)
     if env['REQUEST_METHOD'] == "HEAD" and \
             env['PATH_INFO'] == '/v1/a/c2/o2':
         env_key = get_object_env_key('a', 'c2', 'o2')
         env.setdefault('swift.infocache', {})[env_key] = \
             headers_to_object_info(self.headers, 200)
         start_response('200 OK', self.headers)
     elif env['REQUEST_METHOD'] == "HEAD" and \
             env['PATH_INFO'] == '/v1/a/c2/o3':
         start_response('404 Not Found', [])
     else:
         # Cache the account_info (same as a real application)
         cache_key, env_key = _get_cache_key('a', None)
         env.setdefault('swift.infocache', {})[env_key] = \
             headers_to_account_info(self.headers, 200)
         start_response('200 OK', self.headers)
     return []