2010-07-12 17:03:45 -05:00
|
|
|
# Copyright (c) 2010 OpenStack, LLC.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
|
|
# implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from webob import Request
|
|
|
|
|
2010-08-24 13:58:32 +00:00
|
|
|
from swift.common.middleware import memcache
|
2010-08-20 00:42:38 +00:00
|
|
|
from swift.common.memcached import MemcacheRing
|
2010-07-12 17:03:45 -05:00
|
|
|
|
2010-08-20 00:42:38 +00:00
|
|
|
class FakeApp(object):
|
|
|
|
def __call__(self, env, start_response):
|
|
|
|
return env
|
2010-07-12 17:03:45 -05:00
|
|
|
|
2010-08-20 00:42:38 +00:00
|
|
|
def start_response(*args):
|
|
|
|
pass
|
2010-07-12 17:03:45 -05:00
|
|
|
|
2010-08-20 00:42:38 +00:00
|
|
|
class TestCacheMiddleware(unittest.TestCase):
|
2010-07-12 17:03:45 -05:00
|
|
|
|
2010-08-20 00:42:38 +00:00
|
|
|
def setUp(self):
|
2010-08-24 13:58:32 +00:00
|
|
|
self.app = memcache.MemcacheMiddleware(FakeApp(), {})
|
2010-08-20 00:42:38 +00:00
|
|
|
|
|
|
|
def test_cache_middleware(self):
|
|
|
|
req = Request.blank('/something', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = self.app(req.environ, start_response)
|
|
|
|
self.assertTrue('swift.cache' in resp)
|
|
|
|
self.assertTrue(isinstance(resp['swift.cache'], MemcacheRing))
|
2010-07-12 17:03:45 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|