[CMF-checkins] CVS: CMF - test_ContentTypeRegistry.py:1.3
tseaver@digicool.com
tseaver@digicool.com
Sat, 26 May 2001 00:35:54 -0400 (EDT)
Update of /cvs-repository/CMF/CMFCore/tests
In directory korak.digicool.com:/tmp/cvs-serv24297/tests
Modified Files:
test_ContentTypeRegistry.py
Log Message:
- Pretty close for the specification UI; still need to wire up the PUT_factory.
--- Updated File test_ContentTypeRegistry.py in package CMF --
--- test_ContentTypeRegistry.py 2001/05/26 02:56:43 1.2
+++ test_ContentTypeRegistry.py 2001/05/26 04:35:53 1.3
@@ -3,37 +3,97 @@
import re
from Products.CMFCore.ContentTypeRegistry import *
-class MimeTypePredicateTests( unittest.TestCase ):
+class MajorMinorPredicateTests( unittest.TestCase ):
def test_empty( self ):
- pred = MimeTypePredicate( 'empty' )
+ pred = MajorMinorPredicate( 'empty' )
+ assert pred.getMajorType() == 'None'
+ assert pred.getMinorType() == 'None'
+ assert not pred( 'foo', 'text/plain', 'asdfljksadf' )
+
+ def test_simple( self ):
+ pred = MajorMinorPredicate( 'plaintext' )
+ pred.edit( 'text', 'plain' )
+ assert pred.getMajorType() == 'text'
+ assert pred.getMinorType() == 'plain'
+ assert pred( 'foo', 'text/plain', 'asdfljksadf' )
+ assert not pred( 'foo', 'text/html', 'asdfljksadf' )
+
+ def test_wildcard( self ):
+ pred = MajorMinorPredicate( 'alltext' )
+ pred.edit( 'text', '' )
+ assert pred.getMajorType() == 'text'
+ assert pred.getMinorType() == ''
+ assert pred( 'foo', 'text/plain', 'asdfljksadf' )
+ assert pred( 'foo', 'text/html', 'asdfljksadf' )
+ assert not pred( 'foo', 'image/png', 'asdfljksadf' )
+
+ pred.edit( '', 'html' )
+ assert pred.getMajorType() == ''
+ assert pred.getMinorType() == 'html'
+ assert not pred( 'foo', 'text/plain', 'asdfljksadf' )
+ assert pred( 'foo', 'text/html', 'asdfljksadf' )
+ assert not pred( 'foo', 'image/png', 'asdfljksadf' )
+
+class ExtensionPredicateTests( unittest.TestCase ):
+
+ def test_empty( self ):
+ pred = ExtensionPredicate( 'empty' )
+ assert pred.getExtensions() == 'None'
+ assert not pred( 'foo', 'text/plain', 'asdfljksadf' )
+ assert not pred( 'foo.txt', 'text/plain', 'asdfljksadf' )
+ assert not pred( 'foo.bar', 'text/html', 'asdfljksadf' )
+
+ def test_simple( self ):
+ pred = ExtensionPredicate( 'stardottext' )
+ pred.edit( 'txt' )
+ assert pred.getExtensions() == 'txt'
+ assert not pred( 'foo', 'text/plain', 'asdfljksadf' )
+ assert pred( 'foo.txt', 'text/plain', 'asdfljksadf' )
+ assert not pred( 'foo.bar', 'text/html', 'asdfljksadf' )
+
+ def test_multi( self ):
+ pred = ExtensionPredicate( 'stardottext' )
+ pred.edit( 'txt text html htm' )
+ assert pred.getExtensions() == 'txt text html htm'
+ assert not pred( 'foo', 'text/plain', 'asdfljksadf' )
+ assert pred( 'foo.txt', 'text/plain', 'asdfljksadf' )
+ assert pred( 'foo.text', 'text/plain', 'asdfljksadf' )
+ assert pred( 'foo.html', 'text/plain', 'asdfljksadf' )
+ assert pred( 'foo.htm', 'text/plain', 'asdfljksadf' )
+ assert not pred( 'foo.bar', 'text/html', 'asdfljksadf' )
+
+class MimeTypeRegexPredicateTests( unittest.TestCase ):
+
+ def test_empty( self ):
+ pred = MimeTypeRegexPredicate( 'empty' )
assert pred.getPatternStr() == 'None'
assert not pred( 'foo', 'text/plain', 'asdfljksadf' )
def test_simple( self ):
- pred = MimeTypePredicate( 'plaintext' )
+ pred = MimeTypeRegexPredicate( 'plaintext' )
pred.edit( 'text/plain' )
assert pred.getPatternStr() == 'text/plain'
assert pred( 'foo', 'text/plain', 'asdfljksadf' )
assert not pred( 'foo', 'text/html', 'asdfljksadf' )
def test_pattern( self ):
- pred = MimeTypePredicate( 'alltext' )
+ pred = MimeTypeRegexPredicate( 'alltext' )
pred.edit( 'text/*' )
assert pred.getPatternStr() == 'text/*'
assert pred( 'foo', 'text/plain', 'asdfljksadf' )
assert pred( 'foo', 'text/html', 'asdfljksadf' )
assert not pred( 'foo', 'image/png', 'asdfljksadf' )
-class NamePredicateTests( unittest.TestCase ):
+class NameRegexPredicateTests( unittest.TestCase ):
def test_empty( self ):
- pred = NamePredicate( 'empty' )
+ pred = NameRegexPredicate( 'empty' )
assert pred.getPatternStr() == 'None'
assert not pred( 'foo', 'text/plain', 'asdfljksadf' )
def test_simple( self ):
- pred = NamePredicate( 'onlyfoo' )
+ pred = NameRegexPredicate( 'onlyfoo' )
pred.edit( 'foo' )
assert pred.getPatternStr() == 'foo'
assert pred( 'foo', 'text/plain', 'asdfljksadf' )
@@ -41,7 +101,7 @@
assert not pred( 'bar', 'text/plain', 'asdfljksadf' )
def test_pattern( self ):
- pred = NamePredicate( 'allfwords' )
+ pred = NameRegexPredicate( 'allfwords' )
pred.edit( 'f.*' )
assert pred.getPatternStr() == 'f.*'
assert pred( 'foo', 'text/plain', 'asdfljksadf' )
@@ -80,8 +140,10 @@
def test_suite():
suite = unittest.TestSuite()
- suite.addTest( unittest.makeSuite( MimeTypePredicateTests ) )
- suite.addTest( unittest.makeSuite( NamePredicateTests ) )
+ suite.addTest( unittest.makeSuite( MajorMinorPredicateTests ) )
+ suite.addTest( unittest.makeSuite( ExtensionPredicateTests ) )
+ suite.addTest( unittest.makeSuite( MimeTypeRegexPredicateTests ) )
+ suite.addTest( unittest.makeSuite( NameRegexPredicateTests ) )
suite.addTest( unittest.makeSuite( ContentTypeRegistryTests ) )
return suite