changeset 3697:57d85b82bc3e

test_attachfile: refactored to test class
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 10 Jun 2008 09:02:51 +0200
parents 207ae45bab18
children 23a5fefa9553
files MoinMoin/action/_tests/test_attachfile.py
diffstat 1 files changed, 57 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/_tests/test_attachfile.py	Tue Jun 10 08:44:35 2008 +0200
+++ b/MoinMoin/action/_tests/test_attachfile.py	Tue Jun 10 09:02:51 2008 +0200
@@ -11,65 +11,66 @@
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin._tests import become_trusted, create_page, nuke_page
 
-
-def test_add_attachment(request):
-    """Test if add_attachment() works"""
-
-    become_trusted(request)
-    pagename = "AutoCreatedSillyPageToTestAttachments"
-    filename = "AutoCreatedSillyAttachment"
-
-    create_page(request, pagename, u"Foo!")
-
-    AttachFile.add_attachment(request, pagename, filename, "Test content", True)
-    exists = AttachFile.exists(request, pagename, filename)
-
-    nuke_page(request, pagename)
-
-    assert exists
-
-def test_add_attachment_for_file_object(request):
-    """Test if add_attachment() works with file like object"""
-
-    become_trusted(request)
-    pagename = "AutoCreatedSillyPageToTestAttachments"
-    filename = "AutoCreatedSillyAttachment.png"
-
-    create_page(request, pagename, u"FooBar!")
-    data = "Test content"
-
-    filecontent = StringIO.StringIO(data)
+class TestAttachFile:
+    """ testing action AttachFile"""
+    pagename = u"AutoCreatedSillyPageToTestAttachments"
 
-    AttachFile.add_attachment(request, pagename, filename, filecontent, True)
-    exists = AttachFile.exists(request, pagename, filename)
-    path = AttachFile.getAttachDir(request, pagename)
-    imagef = os.path.join(path, filename)
-    file_size = os.path.getsize(imagef)
-
-    nuke_page(request, pagename)
-
-    assert exists and file_size == len(data)
+    def test_add_attachment(self):
+        """Test if add_attachment() works"""
 
-def test_get_attachment_path_created_on_getFilename(request):
-    """
-    Tests if AttachFile.getFilename creates the attachment dir on requesting
-    """
-    pagename = "ThisPageDoesOnlyExistForThisTest"
-    filename = ""
-    file_exists = os.path.exists(AttachFile.getFilename(request, pagename, filename))
-
-    nuke_page(request, pagename)
+        become_trusted(self.request)
+        filename = "AutoCreatedSillyAttachment"
 
-    assert file_exists
+        create_page(self.request, self.pagename, u"Foo!")
 
-def test_getAttachUrl(request):
-    """
-    Tests if AttachFile.getAttachUrl taints a filename
-    """
-    pagename = "ThisPageDoesOnlyExistForThisTest"
-    filename = "<test2.txt>"
-    expect = "rename=_test2.txt_&"
-    result = AttachFile.getAttachUrl(pagename, filename, request, upload=True)
+        AttachFile.add_attachment(self.request, self.pagename, filename, "Test content", True)
+        exists = AttachFile.exists(self.request, self.pagename, filename)
 
-    assert expect in result
+        nuke_page(self.request, self.pagename)
 
+        assert exists
+
+    def test_add_attachment_for_file_object(self):
+        """Test if add_attachment() works with file like object"""
+
+        become_trusted(self.request)
+
+        filename = "AutoCreatedSillyAttachment.png"
+
+        create_page(self.request, self.pagename, u"FooBar!")
+        data = "Test content"
+
+        filecontent = StringIO.StringIO(data)
+
+        AttachFile.add_attachment(self.request, self.pagename, filename, filecontent, True)
+        exists = AttachFile.exists(self.request, self.pagename, filename)
+        path = AttachFile.getAttachDir(self.request, self.pagename)
+        imagef = os.path.join(path, filename)
+        file_size = os.path.getsize(imagef)
+
+        nuke_page(self.request, self.pagename)
+
+        assert exists and file_size == len(data)
+
+    def test_get_attachment_path_created_on_getFilename(self):
+        """
+        Tests if AttachFile.getFilename creates the attachment dir on self.requesting
+        """
+        filename = ""
+        file_exists = os.path.exists(AttachFile.getFilename(self.request, self.pagename, filename))
+
+        nuke_page(self.request, self.pagename)
+
+        assert file_exists
+
+    def test_getAttachUrl(self):
+        """
+        Tests if AttachFile.getAttachUrl taints a filename
+        """
+        filename = "<test2.txt>"
+        expect = "rename=_test2.txt_&"
+        result = AttachFile.getAttachUrl(self.pagename, filename, self.request, upload=True)
+
+        assert expect in result
+
+coverage_modules = ['MoinMoin.action.AttachFile']