changeset 3851:d97d4fd47c55

renamed test for cache action (no other change)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 14 Jul 2008 17:06:42 +0200
parents 0324aa222029
children e814f653f02d
files MoinMoin/action/_tests/test_cache.py MoinMoin/action/_tests/test_sendcached.py
diffstat 2 files changed, 180 insertions(+), 180 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/action/_tests/test_cache.py	Mon Jul 14 17:06:42 2008 +0200
@@ -0,0 +1,180 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - tests of sendcached functions
+
+    @copyright: 2008 MoinMoin:ThomasWaldmann
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import os, StringIO
+
+from MoinMoin import caching
+from MoinMoin.action import AttachFile, sendcached
+
+from MoinMoin._tests import become_trusted, create_page, nuke_page
+
+class TestSendCached:
+    """ testing action sendcached """
+    pagename = u"AutoCreatedSillyPageToTestAttachments"
+
+    def test_cache_key_content(self):
+        request = self.request
+        result1 = sendcached.cache_key(request, content='foo', secret='bar')
+        result2 = sendcached.cache_key(request, content='foo', secret='baz')
+        assert result1  # not empty
+        assert result1 != result2  # different for different secret
+        result3 = sendcached.cache_key(request, content='foofoo', secret='baz')
+        assert result3 != result2  # different for different content
+        result4 = sendcached.cache_key(request, content='foo'*1000, secret='baz')
+        assert len(result4) == len(result3)  # same length of key for different input lengths
+
+    def test_cache_key_attachment(self):
+        request = self.request
+        pagename = self.pagename
+        attachname = 'foo.txt'
+
+        become_trusted(request)
+        create_page(request, pagename, u"Foo!")
+
+        AttachFile.add_attachment(request, pagename, attachname, "Test content1", True)
+
+        result1 = sendcached.cache_key(request, itemname=pagename, attachname=attachname, secret='bar')
+        result2 = sendcached.cache_key(request, itemname=pagename, attachname=attachname, secret='baz')
+        assert result1  # not empty
+        assert result1 != result2  # different for different secret
+
+        # test below does not work, because mtime is often same, inode can be same due to how add_attachment
+        # works, file size is same, attachment name is same, wikiname/pagename is same.
+        # In practice, this should rather rarely cause problems:
+        #AttachFile.add_attachment(request, pagename, attachname, "Test content2", True)
+        #result3 = sendcached.cache_key(request, itemname=pagename, attachname=attachname, secret='baz')
+        #assert result3 != result2  # different for different content
+
+        AttachFile.add_attachment(request, pagename, attachname, "Test content33333", True)
+        result4 = sendcached.cache_key(request, itemname=pagename, attachname=attachname, secret='baz')
+        assert len(result4) == len(result2)  # same length of key for different input lengths
+        nuke_page(request, pagename)
+
+    def test_put_cache_minimal(self):
+        """Test if put_cache() works"""
+        request = self.request
+        key = 'nooneknowsit'
+        data = "dontcare"
+        url = sendcached.put_cache(request, key, data)
+
+        assert key in url
+        meta_cache = caching.CacheEntry(request,
+                                        arena=sendcached.sendcached_arena,
+                                        scope=sendcached.sendcached_scope,
+                                        key=key+'.meta', use_pickle=True)
+        last_modified, headers = meta_cache.content()
+        assert last_modified.endswith(' GMT') # only a very rough check, it has used cache mtime as last_modified
+        assert "Content-Type: application/octet-stream" in headers
+        assert "Content-Length: %d" % len(data) in headers
+
+    def test_put_cache_guess_ct_give_lm(self):
+        """Test if put_cache() works, when we give filename (so it guesses content_type) and last_modified"""
+        request = self.request
+        key = 'nooneknowsit'
+        filename = "test.png"
+        data = "dontcare"
+        url = sendcached.put_cache(request, key, data,
+                                   filename=filename, last_modified=1)
+        assert key in url
+
+        meta_cache = caching.CacheEntry(request,
+                                        arena=sendcached.sendcached_arena,
+                                        scope=sendcached.sendcached_scope,
+                                        key=key+'.meta', use_pickle=True)
+        last_modified, headers = meta_cache.content()
+        assert last_modified == 'Thu, 01 Jan 1970 00:00:01 GMT'
+        assert "Content-Type: image/png" in headers
+        assert "Content-Length: %d" % len(data) in headers
+
+    def test_put_cache_file_like_data(self):
+        """Test if put_cache() works when we give it a file like object for the content"""
+        request = self.request
+        key = 'nooneknowsit'
+        filename = "test.png"
+        data = "dontcareatall"
+        data_file = StringIO.StringIO(data)
+        url = sendcached.put_cache(request, key, data_file)
+
+        assert key in url
+        meta_cache = caching.CacheEntry(request,
+                                        arena=sendcached.sendcached_arena,
+                                        scope=sendcached.sendcached_scope,
+                                        key=key+'.meta', use_pickle=True)
+        last_modified, headers = meta_cache.content()
+        assert last_modified.endswith(' GMT') # only a very rough check, it has used cache mtime as last_modified
+        assert "Content-Type: application/octet-stream" in headers
+        assert "Content-Length: %d" % len(data) in headers
+
+        data_cache = caching.CacheEntry(request,
+                                        arena=sendcached.sendcached_arena,
+                                        scope=sendcached.sendcached_scope,
+                                        key=key+'.data')
+        cached = data_cache.content()
+        assert data == cached
+
+    def test_put_cache_complex(self):
+        """Test if put_cache() works for a more complex, practical scenario:
+
+           As 'source' we just use some random integer as count value.
+
+           The 'rendered representation' of it is just the word "spam" repeated
+           count times, which we cache.
+
+           The cache key calculation (for the 'non-guessable' keys) is also
+           rather simple.
+
+           In real world, source would be likely some big image, rendered
+           representation of it a thumbnail / preview of it. Or some LaTeX
+           source and its rendered representation as png image.
+           Key calculation could be some MAC or some other hard to guess and
+           unique string.
+        """
+        import random
+        request = self.request
+        render = lambda data: "spam" * data
+        secret = 4223
+        keycalc = lambda data: str(data * secret)
+
+        source = random.randint(1, 100)
+        rendered1 = render(source)
+        key1 = keycalc(source)
+
+        url1 = sendcached.put_cache(request, key1, rendered1)
+        assert 'key=%s' % key1 in url1
+
+        data_cache = caching.CacheEntry(request,
+                                        arena=sendcached.sendcached_arena,
+                                        scope=sendcached.sendcached_scope,
+                                        key=key1+'.data')
+        cached1 = data_cache.content()
+
+        assert render(source) == cached1
+        # if that succeeds, we have stored the rendered representation of source in the cache under key1
+
+        # now we use some different source, render it and store it in the cache
+        source = source * 2
+        rendered2 = render(source)
+        key2 = keycalc(source)
+
+        url2 = sendcached.put_cache(request, key2, rendered2)
+        assert 'key=%s' % key2 in url2
+
+        data_cache = caching.CacheEntry(request,
+                                        arena=sendcached.sendcached_arena,
+                                        scope=sendcached.sendcached_scope,
+                                        key=key2+'.data')
+        cached2 = data_cache.content()
+
+        assert render(source) == cached2
+        # if that succeeds, we have stored the rendered representation of updated source in the cache under key2
+
+        assert url2 != url1  # URLs must be different for different source (implies different keys)
+
+
+coverage_modules = ['MoinMoin.action.sendcached']
+
--- a/MoinMoin/action/_tests/test_sendcached.py	Mon Jul 14 16:40:14 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,180 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-    MoinMoin - tests of sendcached functions
-
-    @copyright: 2008 MoinMoin:ThomasWaldmann
-    @license: GNU GPL, see COPYING for details.
-"""
-
-import os, StringIO
-
-from MoinMoin import caching
-from MoinMoin.action import AttachFile, sendcached
-
-from MoinMoin._tests import become_trusted, create_page, nuke_page
-
-class TestSendCached:
-    """ testing action sendcached """
-    pagename = u"AutoCreatedSillyPageToTestAttachments"
-
-    def test_cache_key_content(self):
-        request = self.request
-        result1 = sendcached.cache_key(request, content='foo', secret='bar')
-        result2 = sendcached.cache_key(request, content='foo', secret='baz')
-        assert result1  # not empty
-        assert result1 != result2  # different for different secret
-        result3 = sendcached.cache_key(request, content='foofoo', secret='baz')
-        assert result3 != result2  # different for different content
-        result4 = sendcached.cache_key(request, content='foo'*1000, secret='baz')
-        assert len(result4) == len(result3)  # same length of key for different input lengths
-
-    def test_cache_key_attachment(self):
-        request = self.request
-        pagename = self.pagename
-        attachname = 'foo.txt'
-
-        become_trusted(request)
-        create_page(request, pagename, u"Foo!")
-
-        AttachFile.add_attachment(request, pagename, attachname, "Test content1", True)
-
-        result1 = sendcached.cache_key(request, itemname=pagename, attachname=attachname, secret='bar')
-        result2 = sendcached.cache_key(request, itemname=pagename, attachname=attachname, secret='baz')
-        assert result1  # not empty
-        assert result1 != result2  # different for different secret
-
-        # test below does not work, because mtime is often same, inode can be same due to how add_attachment
-        # works, file size is same, attachment name is same, wikiname/pagename is same.
-        # In practice, this should rather rarely cause problems:
-        #AttachFile.add_attachment(request, pagename, attachname, "Test content2", True)
-        #result3 = sendcached.cache_key(request, itemname=pagename, attachname=attachname, secret='baz')
-        #assert result3 != result2  # different for different content
-
-        AttachFile.add_attachment(request, pagename, attachname, "Test content33333", True)
-        result4 = sendcached.cache_key(request, itemname=pagename, attachname=attachname, secret='baz')
-        assert len(result4) == len(result2)  # same length of key for different input lengths
-        nuke_page(request, pagename)
-
-    def test_put_cache_minimal(self):
-        """Test if put_cache() works"""
-        request = self.request
-        key = 'nooneknowsit'
-        data = "dontcare"
-        url = sendcached.put_cache(request, key, data)
-
-        assert key in url
-        meta_cache = caching.CacheEntry(request,
-                                        arena=sendcached.sendcached_arena,
-                                        scope=sendcached.sendcached_scope,
-                                        key=key+'.meta', use_pickle=True)
-        last_modified, headers = meta_cache.content()
-        assert last_modified.endswith(' GMT') # only a very rough check, it has used cache mtime as last_modified
-        assert "Content-Type: application/octet-stream" in headers
-        assert "Content-Length: %d" % len(data) in headers
-
-    def test_put_cache_guess_ct_give_lm(self):
-        """Test if put_cache() works, when we give filename (so it guesses content_type) and last_modified"""
-        request = self.request
-        key = 'nooneknowsit'
-        filename = "test.png"
-        data = "dontcare"
-        url = sendcached.put_cache(request, key, data,
-                                   filename=filename, last_modified=1)
-        assert key in url
-
-        meta_cache = caching.CacheEntry(request,
-                                        arena=sendcached.sendcached_arena,
-                                        scope=sendcached.sendcached_scope,
-                                        key=key+'.meta', use_pickle=True)
-        last_modified, headers = meta_cache.content()
-        assert last_modified == 'Thu, 01 Jan 1970 00:00:01 GMT'
-        assert "Content-Type: image/png" in headers
-        assert "Content-Length: %d" % len(data) in headers
-
-    def test_put_cache_file_like_data(self):
-        """Test if put_cache() works when we give it a file like object for the content"""
-        request = self.request
-        key = 'nooneknowsit'
-        filename = "test.png"
-        data = "dontcareatall"
-        data_file = StringIO.StringIO(data)
-        url = sendcached.put_cache(request, key, data_file)
-
-        assert key in url
-        meta_cache = caching.CacheEntry(request,
-                                        arena=sendcached.sendcached_arena,
-                                        scope=sendcached.sendcached_scope,
-                                        key=key+'.meta', use_pickle=True)
-        last_modified, headers = meta_cache.content()
-        assert last_modified.endswith(' GMT') # only a very rough check, it has used cache mtime as last_modified
-        assert "Content-Type: application/octet-stream" in headers
-        assert "Content-Length: %d" % len(data) in headers
-
-        data_cache = caching.CacheEntry(request,
-                                        arena=sendcached.sendcached_arena,
-                                        scope=sendcached.sendcached_scope,
-                                        key=key+'.data')
-        cached = data_cache.content()
-        assert data == cached
-
-    def test_put_cache_complex(self):
-        """Test if put_cache() works for a more complex, practical scenario:
-
-           As 'source' we just use some random integer as count value.
-
-           The 'rendered representation' of it is just the word "spam" repeated
-           count times, which we cache.
-
-           The cache key calculation (for the 'non-guessable' keys) is also
-           rather simple.
-
-           In real world, source would be likely some big image, rendered
-           representation of it a thumbnail / preview of it. Or some LaTeX
-           source and its rendered representation as png image.
-           Key calculation could be some MAC or some other hard to guess and
-           unique string.
-        """
-        import random
-        request = self.request
-        render = lambda data: "spam" * data
-        secret = 4223
-        keycalc = lambda data: str(data * secret)
-
-        source = random.randint(1, 100)
-        rendered1 = render(source)
-        key1 = keycalc(source)
-
-        url1 = sendcached.put_cache(request, key1, rendered1)
-        assert 'key=%s' % key1 in url1
-
-        data_cache = caching.CacheEntry(request,
-                                        arena=sendcached.sendcached_arena,
-                                        scope=sendcached.sendcached_scope,
-                                        key=key1+'.data')
-        cached1 = data_cache.content()
-
-        assert render(source) == cached1
-        # if that succeeds, we have stored the rendered representation of source in the cache under key1
-
-        # now we use some different source, render it and store it in the cache
-        source = source * 2
-        rendered2 = render(source)
-        key2 = keycalc(source)
-
-        url2 = sendcached.put_cache(request, key2, rendered2)
-        assert 'key=%s' % key2 in url2
-
-        data_cache = caching.CacheEntry(request,
-                                        arena=sendcached.sendcached_arena,
-                                        scope=sendcached.sendcached_scope,
-                                        key=key2+'.data')
-        cached2 = data_cache.content()
-
-        assert render(source) == cached2
-        # if that succeeds, we have stored the rendered representation of updated source in the cache under key2
-
-        assert url2 != url1  # URLs must be different for different source (implies different keys)
-
-
-coverage_modules = ['MoinMoin.action.sendcached']
-