Back to index

plone3  3.1.7
Public Member Functions
GroupUserFolder.tests.testInterface.TestInterface Class Reference

klasses = ( # tell which classes to check GroupUserFolder.GroupUserFolder, GRUFUser.GRUFUser, GRUFUser.GRUFGroup, ) More...

Inheritance diagram for GroupUserFolder.tests.testInterface.TestInterface:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def test01Interfaces
def test02TestCaseCompletude
def test03ClassSecurityInfo

Detailed Description

klasses = ( # tell which classes to check GroupUserFolder.GroupUserFolder, GRUFUser.GRUFUser, GRUFUser.GRUFGroup, )

Definition at line 79 of file testInterface.py.


Member Function Documentation

Test that interfaces are okay

Definition at line 81 of file testInterface.py.

00081 
00082     def test01Interfaces(self,):
00083         """
00084         Test that interfaces are okay
00085         """
00086         # Check interface for each and every class
00087         ignore = getattr(self, "ignore_interfaces", [])
00088         for klass in self.klasses:
00089             intfs = getattr(klass, "__implements__", None)
00090             self.failUnless(intfs, "'%s' class doesn't implement an interface!" % (klass.__name__, ))
00091 
00092             # Flatten interfaces
00093             intfs = flattenList(intfs)
00094 
00095             # Check each and everyone
00096             for intf in intfs:
00097                 if intf in ignore:
00098                     continue
00099                 self.failUnless(
00100                     Verify.verifyClass(
00101                     intf,
00102                     klass,
00103                     ),
00104                     "'%s' class doesn't implement '%s' interface correctly." % (klass.__name__, intf.__name__, ),
00105                     )
00106 

Here is the call graph for this function:

Check that the test case is complete : each interface entry xxx must be associated
to a test_xxx method in the test class.

Definition at line 107 of file testInterface.py.

00107 
00108     def test02TestCaseCompletude(self,):
00109         """
00110         Check that the test case is complete : each interface entry xxx must be associated
00111         to a test_xxx method in the test class.
00112         """
00113         not_defined = []
00114         tests = dir(self)
00115         count = 0
00116         
00117         # Check interface for each and every class
00118         ignore = getattr(self, "ignore_interfaces", [])
00119         for klass in self.klasses:
00120             intfs = getattr(klass, "__implements__", None)
00121             self.failUnless(intfs, "'%s' class doesn't implement an interface!" % (klass.__name__, ))
00122 
00123             # Flatten interfaces
00124             intfs = flattenInterfaces(intfs)
00125 
00126             # Check each and every interface
00127             for intf in intfs:
00128                 if intf in ignore:
00129                     continue
00130                 for name in intf.names():
00131                     count += 1
00132                     if not "test_%s" % (name,) in tests:
00133                         not_defined.append("%s.%s" % (klass.__name__, name))
00134 
00135 
00136         # Raise in case some tests are missing
00137         if not_defined:
00138             raise RuntimeError, "%d (over %d) MISSING TESTS:\n%s do not have a test associated." % (
00139                 len(not_defined),
00140                 count,
00141                 string.join(not_defined, ", "),
00142                 )
00143         
        

Here is the call graph for this function:

This method tests that each and every method has a ClassSecurityInfo() declaration
XXX This doesn't walk through inheritance :(

Reimplemented in GroupUserFolder.tests.testUserAPI.TestUserFolderAPI.

Definition at line 144 of file testInterface.py.

00144 
00145     def test03ClassSecurityInfo(self):
00146         """
00147         This method tests that each and every method has a ClassSecurityInfo() declaration
00148         XXX This doesn't walk through inheritance :(
00149         """
00150         not_defined = []
00151         count = 0
00152         
00153         # Check interface for each and every class
00154         ignore = getattr(self, "ignore_interfaces", [])
00155         for klass in self.klasses:
00156             dict = dir(klass)
00157             intfs = getattr(klass, "__implements__", None)
00158             self.failUnless(intfs, "'%s' class doesn't implement an interface!" % (klass.__name__, ))
00159 
00160             # Flatten interfaces
00161             intfs = flattenInterfaces(intfs)
00162             
00163             # Now check the resulting class to see if the mapping was made
00164             # correctly. Note that this uses carnal knowledge of the internal
00165             # structures used to store this information!
00166             # Check each method of every interface
00167             for intf in intfs:
00168                 if intf in ignore:
00169                     continue
00170                 for name in intf.names():
00171                     count += 1
00172                     if not "%s__roles__" % (name,) in dict:
00173                         not_defined.append("%s.%s" % (klass.__name__, name))
00174 
00175         # Raise in case some tests are missing
00176         if not_defined:
00177             raise RuntimeError, "%d (over %d) MISSING SECURITY DECLARATIONS:\n%s do not have a security declaration associated." % (
00178                 len(not_defined),
00179                 count,
00180                 string.join(not_defined, ", "),
00181                 )
00182         

Here is the call graph for this function:


The documentation for this class was generated from the following file: