[CMF-checkins] CVS: CMF - test_Document.py:1.6

Jeffrey Shell jeffrey@digicool.com
Thu, 24 May 2001 22:24:19 -0400 (EDT)


Update of /cvs-repository/CMF/CMFDefault/tests
In directory korak.digicool.com:/home/jeffrey/InstanceHomes/cmf-dev/CMF/CMFDefault/tests

Modified Files:
	test_Document.py 
Log Message:
A new class of test cases for trying to catch various supposed FTP 
scenarios, prompted by the following bullet item:

 o Dealt with interesting case where a full HTML example in a structured
   text document uploaded via FTP would be thought of as an HTML document,
   which would throw everything outside of the first HTML example it found
   away.




--- Updated File test_Document.py in package CMF --
--- test_Document.py	2001/05/21 21:58:36	1.5
+++ test_Document.py	2001/05/25 02:24:18	1.6
@@ -9,6 +9,7 @@
   <title>Title in tag</title>
   <meta name="description" content="Describe me">
   <meta name="contributors" content="foo@bar.com baz@bam.net">
+  <meta name="title" content="Title in meta">
  </head>
  <body bgcolor="#ffffff">
   <h1>Not a lot here</h1>
@@ -32,16 +33,32 @@
 Description: A document by me
 Contributors: foo@bar.com baz@bam.net no@yes.maybe
 
-This is the header and it supercedes the title
+This is the header
 
   Body body body body body
   body body body.
 
-   o What does this do
+   o A list item
    
-   o if it happens to you?
+   o And another thing...
 '''
 
+STX_WITH_HTML = """\
+Sometimes people do interesting things
+
+  Sometimes people do interesting things like have examples
+  of HTML inside their structured text document.  We should
+  be detecting that this is indeed a structured text document
+  and **NOT** an HTML document::
+
+    <html>
+    <head><title>Hello World</title></head>
+    <body><p>Hello world, I am Bruce.</p></body>
+    </html>
+
+  All in favor say pi!
+"""
+
 class DocumentTests(unittest.TestCase):
 
     def test_Empty(self):
@@ -120,11 +137,71 @@
         assert d.Format() == 'text/plain'
 
 
+class TestDocumentPUT(unittest.TestCase):
+    def setUp(self):
+        class Request:
+            body = ''
+            def get_header(self, h, d=''): return d
+            def get(self, *args): return self.body
+        class Response:
+            status = 0
+            def setHeader(self, *args): pass
+            def setStatus(self, status): self.status = status
+        self._request, self._response = Request(), Response()
+
+    def tearDown(self):
+        del self._response
+        del self._request
+
+    def test_PutStructuredTextWithHTML(self):
+        d = Document('foo')
+            
+        self._request.body = STX_WITH_HTML
+
+        r = d.PUT(self._request, self._response)
+        assert d.Format() == 'text/plain', "%s != %s" % (
+            d.Format(), 'text/plain')
+        assert r.status == 204
+
+    def test_PutStructuredText(self):
+        d = Document('foo')
+
+        self._request.body = BASIC_STRUCTUREDTEXT
+
+        r = d.PUT(self._request, self._response)
+        assert d.Format() == 'text/plain', '%s != %s' % (
+            d.Format(), 'text/plain')
+        assert r.status == 204
+
+    def test_PutHtmlWithDoctype(self):
+        d = Document('foo')
+        html = '%s\n\n  \n   %s' % (DOCTYPE, BASIC_HTML)
+        self._request.body = html
+        r = d.PUT(self._request, self._response)
+        assert d.Format() == 'text/html', "%s != %s" % (
+            d.Format(), 'text/html')
+        assert d.Description() == 'Describe me'
+        assert r.status == 204
 
+    def test_PutHtml(self):
+        d = Document('foo')
+        self._request.body = BASIC_HTML
+        r = d.PUT(self._request, self._response)
+        assert d.Format() == 'text/html', "%s != %s" % (
+            d.Format(), 'text/html')
+        assert d.Description() == 'Describe me'
+        assert r.status == 204
+
+
 def test_suite():
-    return unittest.makeSuite(DocumentTests)
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(DocumentTests))
+    suite.addTest(unittest.makeSuite(TestDocumentPUT))
+    return suite
 
-def main():
+def run():
     unittest.TextTestRunner().run(test_suite())
+
+if __name__ == '__main__':
+    run()
 
-if __name__=='__main__': main()