Back to index

plone3  3.1.7
Classes | Functions | Variables
Archetypes.tests.utils Namespace Reference

Classes

class  Dummy
class  FakeRequestSession
class  DummySessionDataManager
class  DummySDMTraverseHook
class  SimpleView

Functions

def gen_class
def mkDummyInContext
def makeContent
def normalize_html
def nicerange
def showdiff
def populateFolder
def isWrapperMethod
def wrap_method
def unwrap_method
def aputrequest

Variables

tuple logger = logging.getLogger('Archetypes')
tuple PACKAGE_HOME = package_home(globals())
 ZOPE28 = False
 ZOPE29 = False
string WRAPPER = '__at_is_wrapper_method__'
string ORIG_NAME = '__at_original_method_name__'

Function Documentation

def Archetypes.tests.utils.aputrequest (   file,
  content_type 
)

Definition at line 270 of file utils.py.

00270 
00271 def aputrequest(file, content_type):
00272     resp = HTTPResponse(stdout=sys.stdout)
00273     environ = {}
00274     environ['SERVER_NAME']='foo'
00275     environ['SERVER_PORT']='80'
00276     environ['REQUEST_METHOD'] = 'PUT'
00277     environ['CONTENT_TYPE'] = content_type
00278     req = HTTPRequest(stdin=file, environ=environ, response=resp)
00279     return req

Here is the caller graph for this function:

def Archetypes.tests.utils.gen_class (   klass,
  schema = None 
)
generats and registers the klass

Definition at line 68 of file utils.py.

00068 
00069 def gen_class(klass, schema=None):
00070     """generats and registers the klass
00071     """
00072     if schema is not None:
00073         klass.schema = schema.copy()
00074     registerType(klass, 'Archetypes')
00075     content_types, constructors, ftis = process_types(listTypes(), PKG_NAME)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 167 of file utils.py.

00167 
00168 def isWrapperMethod(meth):
00169     return getattr(meth, WRAPPER, False)

Here is the caller graph for this function:

def Archetypes.tests.utils.makeContent (   container,
  portal_type,
  id = 'document',
  kw 
)

Definition at line 83 of file utils.py.

00083 
00084 def makeContent( container, portal_type, id='document', **kw ):
00085     container.invokeFactory( type_name=portal_type, id=id )
00086     return getattr( container, id )

def Archetypes.tests.utils.mkDummyInContext (   klass,
  oid,
  context,
  schema = None 
)

Definition at line 76 of file utils.py.

00076 
00077 def mkDummyInContext(klass, oid, context, schema=None):
00078     gen_class(klass, schema)
00079     dummy = klass(oid=oid).__of__(context)
00080     context._setObject(oid, dummy, suppress_events=True)
00081     dummy.initializeArchetype()
00082     return dummy

Here is the call graph for this function:

def Archetypes.tests.utils.nicerange (   lo,
  hi 
)

Definition at line 97 of file utils.py.

00097 
00098 def nicerange(lo, hi):
00099     if hi <= lo+1:
00100         return str(lo+1)
00101     else:
00102         return "%d,%d" % (lo+1, hi)

Here is the caller graph for this function:

Definition at line 91 of file utils.py.

00091 
00092 def normalize_html(s):
00093     s = re.sub(r"\s+", " ", s)
00094     s = re.sub(r"(?s)\s+<", "<", s)
00095     s = re.sub(r"(?s)>\s+", ">", s)
00096     return s

Here is the caller graph for this function:

def Archetypes.tests.utils.populateFolder (   folder,
  folder_type,
  doc_type 
)
Creates a structure like:

\index_html
\doc1
\folder1
   \folder11
   \folder12
   \doc11
\folder2
   \folder21
   \doc21
   \index_html
   \folder22
      \folder221
         \doc2211
         \doc2212
      \folder222
         \doc2221
         \doc2222
      \folder223
         \doc2231
         \doc2232

Definition at line 114 of file utils.py.

00114 
00115 def populateFolder(folder, folder_type, doc_type):
00116     """ Creates a structure like:
00117 
00118     \index_html
00119     \doc1
00120     \folder1
00121        \folder11
00122        \folder12
00123        \doc11
00124     \folder2
00125        \folder21
00126        \doc21
00127        \index_html
00128        \folder22
00129           \folder221
00130              \doc2211
00131              \doc2212
00132           \folder222
00133              \doc2221
00134              \doc2222
00135           \folder223
00136              \doc2231
00137              \doc2232
00138     """
00139     folder.invokeFactory(doc_type, id='index_html')
00140     folder.invokeFactory(doc_type, id='doc1')
00141     folder.invokeFactory(folder_type, id='folder1')
00142     folder.invokeFactory(folder_type, id='folder2')
00143     f1 = folder.folder1
00144     f2 = folder.folder2
00145     f1.invokeFactory(folder_type, id='folder11')
00146     f1.invokeFactory(folder_type, id='folder12')
00147     f1.invokeFactory(doc_type, id='doc11')
00148     f2.invokeFactory(folder_type, id='folder21')
00149     f2.invokeFactory(folder_type, id='folder22')
00150     f2.invokeFactory(doc_type, id='doc21')
00151     f2.invokeFactory(doc_type, id='index_html')
00152     f22 = f2.folder22
00153     f22.invokeFactory(folder_type, id='folder221')
00154     f221 = f22.folder221
00155     f221.invokeFactory(doc_type, id='doc2211')
00156     f221.invokeFactory(doc_type, id='doc2212')
00157     f22.invokeFactory(folder_type, id='folder222')
00158     f222 = f22.folder222
00159     f222.invokeFactory(doc_type, id='doc2221')
00160     f222.invokeFactory(doc_type, id='doc2222')
00161     f22.invokeFactory(folder_type, id='folder223')
00162     f223 = f22.folder223
00163     f223.invokeFactory(doc_type, id='doc2231')
00164     f223.invokeFactory(doc_type, id='doc2232')

Here is the caller graph for this function:

def Archetypes.tests.utils.showdiff (   a,
  b 
)

Definition at line 103 of file utils.py.

00103 
00104 def showdiff(a, b):
00105     cruncher = ndiff.SequenceMatcher(ndiff.IS_LINE_JUNK, a, b)
00106     for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
00107         if tag == "equal":
00108             continue
00109         print nicerange(alo, ahi) + tag[0] + nicerange(blo, bhi)
00110         ndiff.dump('<', a, alo, ahi)
00111         if a and b:
00112             print '---'
00113         ndiff.dump('>', b, blo, bhi)

Here is the call graph for this function:

def Archetypes.tests.utils.unwrap_method (   klass,
  name 
)

Definition at line 181 of file utils.py.

00181 
00182 def unwrap_method(klass, name):
00183     old_method = getattr(klass, name)
00184     if not isWrapperMethod(old_method):
00185         raise ValueError, ('Trying to unwrap non-wrapped '
00186                            'method at %s.%s' % (klass.__name__, name))
00187     orig_name = getattr(old_method, ORIG_NAME)
00188     new_method = getattr(klass, orig_name)
00189     delattr(klass, orig_name)
00190     setattr(klass, name, new_method)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.tests.utils.wrap_method (   klass,
  name,
  method,
  pattern = '__at_wrapped_%s__' 
)

Definition at line 170 of file utils.py.

00170 
00171 def wrap_method(klass, name, method, pattern='__at_wrapped_%s__'):
00172     old_method = getattr(klass, name)
00173     if isWrapperMethod(old_method):
00174         logger.warning('Wrapping already wrapped method at %s.%s' %
00175                        (klass.__name__, name))
00176     new_name = pattern % name
00177     setattr(klass, new_name, old_method)
00178     setattr(method, ORIG_NAME, new_name)
00179     setattr(method, WRAPPER, True)
00180     setattr(klass, name, method)

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

tuple Archetypes.tests.utils.logger = logging.getLogger('Archetypes')

Definition at line 49 of file utils.py.

string Archetypes.tests.utils.ORIG_NAME = '__at_original_method_name__'

Definition at line 166 of file utils.py.

tuple Archetypes.tests.utils.PACKAGE_HOME = package_home(globals())

Definition at line 51 of file utils.py.

string Archetypes.tests.utils.WRAPPER = '__at_is_wrapper_method__'

Definition at line 165 of file utils.py.

Definition at line 56 of file utils.py.

Definition at line 63 of file utils.py.