comparison MoinMoin/action/_tests/test_cache.py @ 4580:606234778ffc

fixing cache action tests: headers cache now stores (key, value) tuples
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 15 Feb 2009 01:57:19 +0100
parents 0f86861f1adb
children
comparison
equal deleted inserted replaced
4579:87d97510de79 4580:606234778ffc
68 arena=cache.cache_arena, 68 arena=cache.cache_arena,
69 scope=cache.cache_scope, 69 scope=cache.cache_scope,
70 key=key+'.meta', use_pickle=True) 70 key=key+'.meta', use_pickle=True)
71 meta = meta_cache.content() 71 meta = meta_cache.content()
72 assert meta['httpdate_last_modified'].endswith(' GMT') # only a very rough check, it has used cache mtime as last_modified 72 assert meta['httpdate_last_modified'].endswith(' GMT') # only a very rough check, it has used cache mtime as last_modified
73 assert "Content-Type: application/octet-stream" in meta['headers'] 73 assert ("Content-Type", "application/octet-stream") in meta['headers']
74 assert "Content-Length: %d" % len(data) in meta['headers'] 74 assert ("Content-Length", len(data)) in meta['headers']
75 75
76 def test_put_cache_guess_ct_give_lm(self): 76 def test_put_cache_guess_ct_give_lm(self):
77 """Test if put_cache() works, when we give filename (so it guesses content_type) and last_modified""" 77 """Test if put_cache() works, when we give filename (so it guesses content_type) and last_modified"""
78 request = self.request 78 request = self.request
79 key = 'nooneknowsit' 79 key = 'nooneknowsit'
87 arena=cache.cache_arena, 87 arena=cache.cache_arena,
88 scope=cache.cache_scope, 88 scope=cache.cache_scope,
89 key=key+'.meta', use_pickle=True) 89 key=key+'.meta', use_pickle=True)
90 meta = meta_cache.content() 90 meta = meta_cache.content()
91 assert meta['httpdate_last_modified'] == 'Thu, 01 Jan 1970 00:00:01 GMT' 91 assert meta['httpdate_last_modified'] == 'Thu, 01 Jan 1970 00:00:01 GMT'
92 assert "Content-Type: image/png" in meta['headers'] 92 assert ("Content-Type", "image/png") in meta['headers']
93 assert "Content-Length: %d" % len(data) in meta['headers'] 93 assert ("Content-Length", len(data)) in meta['headers']
94 94
95 def test_put_cache_file_like_data(self): 95 def test_put_cache_file_like_data(self):
96 """Test if put_cache() works when we give it a file like object for the content""" 96 """Test if put_cache() works when we give it a file like object for the content"""
97 request = self.request 97 request = self.request
98 key = 'nooneknowsit' 98 key = 'nooneknowsit'
107 arena=cache.cache_arena, 107 arena=cache.cache_arena,
108 scope=cache.cache_scope, 108 scope=cache.cache_scope,
109 key=key+'.meta', use_pickle=True) 109 key=key+'.meta', use_pickle=True)
110 meta = meta_cache.content() 110 meta = meta_cache.content()
111 assert meta['httpdate_last_modified'].endswith(' GMT') # only a very rough check, it has used cache mtime as last_modified 111 assert meta['httpdate_last_modified'].endswith(' GMT') # only a very rough check, it has used cache mtime as last_modified
112 assert "Content-Type: application/octet-stream" in meta['headers'] 112 assert ("Content-Type", "application/octet-stream") in meta['headers']
113 assert "Content-Length: %d" % len(data) in meta['headers'] 113 assert ("Content-Length", len(data)) in meta['headers']
114 114
115 data_cache = caching.CacheEntry(request, 115 data_cache = caching.CacheEntry(request,
116 arena=cache.cache_arena, 116 arena=cache.cache_arena,
117 scope=cache.cache_scope, 117 scope=cache.cache_scope,
118 key=key+'.data') 118 key=key+'.data')