zuite.py 23.4 KB
Newer Older
Rafael Monnerat's avatar
Rafael Monnerat committed
1 2 3 4 5 6
""" Classes:  Zuite

Zuite instances are collections of Zelenium test cases.

$Id$
"""
7
from __future__ import absolute_import
Rafael Monnerat's avatar
Rafael Monnerat committed
8 9 10 11
import glob
import logging
import os
import re
12
from six.moves.urllib.parse import unquote
Rafael Monnerat's avatar
Rafael Monnerat committed
13
import zipfile
14
import io
Rafael Monnerat's avatar
Rafael Monnerat committed
15
import types
16
import six
Rafael Monnerat's avatar
Rafael Monnerat committed
17

18
from zope.interface import implementer
Rafael Monnerat's avatar
Rafael Monnerat committed
19 20 21 22 23 24 25 26 27 28 29 30 31

from AccessControl.SecurityInfo import ClassSecurityInfo
from App.class_init import InitializeClass
from App.Common import package_home
from App.config import getConfiguration
from App.ImageFile import ImageFile
from App.special_dtml import DTMLFile
from DateTime.DateTime import DateTime
from OFS.Folder import Folder
from OFS.Image import File
from OFS.OrderedFolder import OrderedFolder
from Products.PageTemplates.PageTemplateFile import PageTemplateFile

32 33 34
from .interfaces import IZuite
from .permissions import ManageSeleniumTestCases
from .permissions import View
Rafael Monnerat's avatar
Rafael Monnerat committed
35 36 37 38 39 40 41 42

logger = logging.getLogger('event.Zelenium')

_NOW = None   # set only for testing

_PINK_BACKGROUND = re.compile('bgcolor="#ffcfcf"')

_EXCLUDE_NAMES = ( 'CVS', '.svn', '.objects' )
43

Rafael Monnerat's avatar
Rafael Monnerat committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
#winzip awaits latin1
_DEFAULTENCODING = 'latin1'


def _getNow():
    if _NOW is not None:
        return _NOW

    return DateTime()

_WWW_DIR = os.path.join( package_home( globals() ), 'www' )

#
#   Selenium support files.
#
_SUPPORT_DIR = os.path.join( package_home( globals() ), 'selenium' )
_SUPPORT_FILES = {}

def _makeFile(filename, prefix=None, id=None):

    if prefix:
        path = os.path.join( prefix, filename )
    else:
        path = filename

    if id is None:
        id = os.path.split( path )[ 1 ]

    return File( id=id, title='', file=open(path).read() )


def registerFiles(directory, prefix):
    for filename in os.listdir(directory):
        ignored, extension = os.path.splitext(filename)

        if extension.lower() in ('.js', '.html', '.css', '.png'):
            _SUPPORT_FILES['%s_%s' % (prefix, filename)] = _makeFile( filename, prefix=directory)

_MARKER = object()


def _recurseFSTestCases( result, prefix, fsobjs ):

    test_cases = dict( [ ( x.getId(), x )
                            for x in fsobjs.get( 'testcases', () ) ] )
    subdirs = fsobjs.get( 'subdirs', {} )

    for name in fsobjs.get( 'ordered', [] ):

        if name in test_cases:
            test_case = test_cases[ name ]
            name = test_case.getId()
            path = '/'.join( prefix + ( name, ) )
            result.append( { 'id' : name
                            , 'title' : test_case.title_or_id()
                            , 'url' : path
                            , 'path' : path
                            , 'test_case' : test_case
                            } )

        if name in subdirs:
            info = subdirs[ name ]
            _recurseFSTestCases( result
                               , prefix + ( name, )
                               , info
                               )

111
@implementer(IZuite)
Rafael Monnerat's avatar
Rafael Monnerat committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
class Zuite( OrderedFolder ):
    """ TTW-manageable browser test suite

    A Zuite instance is an ordered folder, whose 'index_html' provides the
    typical "TestRunner.html" view from Selenium.  It generates the
    "TestSuite.html" view from its 'objectItems' list (which allows the
    user to control ordering), selecting File and PageTemplate objects
    whose names start with 'test'.
    """
    meta_type = 'Zuite'

    manage_options = ( OrderedFolder.manage_options
                     + ( { 'label' : 'Zip', 'action' : 'manage_zipfile' },
                       )
                     )

    test_case_metatypes = ( 'File'
                          , 'Page Template'
                          )
    filesystem_path = ''
    filename_glob = ''
    testsuite_name = ''
    _v_filesystem_objects = None
    _v_selenium_objects = None

    _properties = ( { 'id' : 'test_case_metatypes'
                    , 'type' : 'lines'
                    , 'mode' : 'w'
                    }
                  , { 'id' : 'filesystem_path'
                    , 'type' : 'string'
                    , 'mode' : 'w'
                    }
                  , { 'id' : 'filename_glob'
                    , 'type' : 'string'
                    , 'mode' : 'w'
                    }
                  , { 'id' : 'testsuite_name'
                    , 'type' : 'string'
                    , 'mode' : 'w'
                    }
                  )

    security = ClassSecurityInfo()
    security.declareObjectProtected( View )

    security.declareProtected( ManageSeleniumTestCases, 'manage_main' )

    security.declareProtected( View, 'index_html' )
    index_html = PageTemplateFile( 'suiteView', _WWW_DIR )

    security.declareProtected( View, 'test_suite_html' )
    test_suite_html = PageTemplateFile( 'suiteTests', _WWW_DIR )

    security.declareProtected( View, 'splash_html' )
    splash_html = PageTemplateFile( 'suiteSplash', _WWW_DIR )
168

Rafael Monnerat's avatar
Rafael Monnerat committed
169 170
    security.declareProtected( View, 'test_prompt_html' )
    test_prompt_html = PageTemplateFile( 'testPrompt', _WWW_DIR )
171

Rafael Monnerat's avatar
Rafael Monnerat committed
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    security.declareProtected(ManageSeleniumTestCases, 'manage_zipfile')
    manage_zipfile = PageTemplateFile( 'suiteZipFile', _WWW_DIR )


    def __getitem__( self, key, default=_MARKER ):

        if key in self.objectIds():
            return self._getOb( key )

        if key in _SUPPORT_FILES.keys():
            return _SUPPORT_FILES[ key ].__of__( self )

        proxy = _FilesystemProxy( key
                                , self._listFilesystemObjects()
                                ).__of__( self )

        localdefault = object()

        value = proxy.get( key, localdefault )

        if value is not localdefault:
            return value
194

Rafael Monnerat's avatar
Rafael Monnerat committed
195 196 197 198 199 200 201 202 203
        proxy = _FilesystemProxy( key
                                , self._listSeleniumObjects()
                                ).__of__( self )

        value = proxy.get( key, default )

        if value is not _MARKER:
            return value

204
        raise KeyError(key)
Rafael Monnerat's avatar
Rafael Monnerat committed
205 206 207 208 209 210 211 212 213


    security.declareProtected( View, 'listTestCases' )
    def listTestCases( self, prefix=() ):
        """ Return a list of our contents which qualify as test cases.
        """
        result = []
        self._recurseListTestCases(result, prefix, self)
        return result
214

Rafael Monnerat's avatar
Rafael Monnerat committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
    def _recurseListTestCases( self, result, prefix, ob ):
        for tcid, test_case in ob.objectItems():
            if isinstance( test_case, self.__class__ ):
                result.extend( test_case.listTestCases(
                                        prefix=prefix + ( tcid, ) ) )
            elif test_case.isPrincipiaFolderish:
                self._recurseListTestCases(result, prefix+(tcid,), test_case)
            elif test_case.meta_type in self.test_case_metatypes:
                path = '/'.join( prefix + ( tcid, ) )
                result.append( { 'id' : tcid
                               , 'title' : test_case.title_or_id()
                               , 'url' : path
                               , 'path' : path
                               , 'test_case' : test_case
                               } )

        fsobjs = self._listFilesystemObjects()

        _recurseFSTestCases( result, prefix, fsobjs )


    security.declareProtected(ManageSeleniumTestCases, 'getZipFileName')
    def getZipFileName(self):
        """ Generate a suitable name for the zip file.
        """
        now = _getNow()
        now_str = now.ISO()[:10]
        return '%s-%s.zip' % ( self.getId(), now_str )


    security.declareProtected(ManageSeleniumTestCases, 'manage_getZipFile')
    def manage_getZipFile( self
                         , archive_name=None
                         , include_selenium=True
                         , RESPONSE=None
                         ):
        """ Export the test suite as a zip file.
        """
        if archive_name is None or archive_name.strip() == '':
            archive_name = self.getZipFileName()

        bits = self._getZipFile( include_selenium )

        if RESPONSE is None:
            return bits

        RESPONSE.setHeader('Content-type', 'application/zip')
        RESPONSE.setHeader('Content-length', str( len( bits ) ) )
        RESPONSE.setHeader('Content-disposition',
                            'inline;filename=%s' % archive_name )
        RESPONSE.write(bits)


    security.declareProtected(ManageSeleniumTestCases, 'manage_createSnapshot')
    def manage_createSnapshot( self
                             , archive_name=None
                             , include_selenium=True
                             , RESPONSE=None
                             ):
        """ Save the test suite as a zip file *in the zuite*.
        """
        if archive_name is None or archive_name.strip() == '':
            archive_name = self.getZipFileName()

        archive = File( archive_name
                      , title=''
                      , file=self._getZipFile( include_selenium )
                      )
        self._setObject( archive_name, archive )

        if RESPONSE is not None:
            RESPONSE.redirect( '%s/manage_main?manage_tabs_message=%s'
                              % ( self.absolute_url()
                                , 'Snapshot+added'
                                ) )


    security.declarePublic('postResults')
    def postResults(self, REQUEST):
        """ Record the results of a test run.

        o Create a folder with properties representing the summary results,
          and files containing the suite and the individual test runs.

        o REQUEST will have the following form fields:

          result -- one of "failed" or "passed"

          totalTime -- time in floating point seconds for the run

          numTestPasses -- count of test runs which passed

          numTestFailures -- count of test runs which failed

          numCommandPasses -- count of commands which passed

          numCommandFailures -- count of commands which failed

          numCommandErrors -- count of commands raising non-assert errors

          suite -- Colorized HTML of the suite table

          testTable.<n> -- Colorized HTML of each test run
        """
        completed = DateTime()
320
        result_id = 'result_%s' % completed.strftime( '%Y%m%d_%H%M%S.%f' )
Rafael Monnerat's avatar
Rafael Monnerat committed
321 322 323 324 325 326 327 328 329 330 331 332 333
        self._setObject( result_id, ZuiteResults( result_id ) )
        result = self._getOb( result_id )
        rfg = REQUEST.form.get
        reg = REQUEST.environ.get

        result._updateProperty( 'completed'
                              , completed
                              )

        result._updateProperty( 'passed'
                              , rfg( 'result' ).lower() == 'passed'
                              )

334 335 336 337
        result._updateProperty( 'finished'
                              , rfg( 'finished' ).lower() == 'true'
                              )

Rafael Monnerat's avatar
Rafael Monnerat committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
        result._updateProperty( 'time_secs'
                              , float( rfg( 'totalTime', 0 ) )
                              )

        result._updateProperty( 'tests_passed'
                              , int( rfg( 'numTestPasses', 0 ) )
                              )

        result._updateProperty( 'tests_failed'
                              , int( rfg( 'numTestFailures', 0 ) )
                              )

        result._updateProperty( 'commands_passed'
                              , int( rfg( 'numCommandPasses', 0 ) )
                              )

        result._updateProperty( 'commands_failed'
                              , int( rfg( 'numCommandFailures', 0 ) )
                              )

        result._updateProperty( 'commands_with_errors'
                              , int( rfg( 'numCommandErrors', 0 ) )
                              )

        result._updateProperty( 'user_agent'
                              , reg( 'HTTP_USER_AGENT', 'unknown' )
                              )

        result._updateProperty( 'remote_addr'
                              , reg( 'REMOTE_ADDR', 'unknown' )
                              )

        result._updateProperty( 'http_host'
                              , reg( 'HTTP_HOST', 'unknown' )
                              )

        result._updateProperty( 'server_software'
                              , reg( 'SERVER_SOFTWARE', 'unknown' )
                              )

        result._updateProperty( 'product_info'
                              , self._listProductInfo()
                              )

        result._setObject( 'suite.html'
                         , File( 'suite.html'
                               , 'Test Suite'
                               , unquote( rfg( 'suite' ) )
                               , 'text/html'
                               )
                         )

        test_ids = [ x for x in REQUEST.form.keys()
                        if x.startswith( 'testTable' ) ]
        test_ids.sort()

        for test_id in test_ids:
            body = unquote( rfg( test_id ) )
            result._setObject( test_id
                             , File( test_id
                                   , 'Test case: %s' % test_id
                                   , body
                                   , 'text/html'
                                   ) )
            testcase = result._getOb( test_id )

            # XXX:  this is silly, but we have no other metadata.
            testcase._setProperty( 'passed'
                                 , _PINK_BACKGROUND.search( body ) is None
                                 , 'boolean'
                                 )


    #
    #   Helper methods
    #
    security.declarePrivate('_listFilesystemObjects')
    def _listFilesystemObjects( self ):
        """ Return a mapping of any filesystem objects we "hold".
        """
        if ( self._v_filesystem_objects is not None and
             not getConfiguration().debug_mode ):
            return self._v_filesystem_objects

        if not self.filesystem_path:
            return { 'testcases' : (), 'subdirs' : {} }

        path = os.path.abspath( self.filesystem_path )

        self._v_filesystem_objects = self._grubFilesystem( path )
        return self._v_filesystem_objects

    security.declarePrivate('_listSeleniumObjects')
    def _listSeleniumObjects( self ):
        """ Return a mapping of any filesystem objects we "hold".
        """
        if ( self._v_selenium_objects is not None and
             not getConfiguration().debug_mode ):
            return self._v_selenium_objects

        self._v_selenium_objects = self._grubFilesystem(_SUPPORT_DIR)
        return self._v_selenium_objects

    security.declarePrivate('_grubFilesystem')
    def _grubFilesystem( self, path ):

        info = { 'testcases' : (), 'subdirs' : {} }

        # Look for a specified test suite
        # or a '.objects' file with an explicit manifiest
        manifest = os.path.join( path, self.testsuite_name or '.objects' )

        if os.path.isfile( manifest ):
451
            filenames = [_f for _f in [ x.strip() for x in open( manifest ).readlines() ] if _f]
Rafael Monnerat's avatar
Rafael Monnerat committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498

        elif self.filename_glob:
            globbed = glob.glob( os.path.join( path, self.filename_glob ) )
            filenames = [ os.path.split( x )[ 1 ] for x in globbed ]

        else:   # guess
            filenames = [ x for x in os.listdir( path )
                                if x not in _EXCLUDE_NAMES ]
            filenames.sort()

        info[ 'ordered' ] = filenames

        for name in filenames:

            fqfn = os.path.join( path, name )

            if os.path.isfile( fqfn ):
                testcase = _makeFile( fqfn )
                info[ 'testcases' ] += ( testcase, )

            elif os.path.isdir( fqfn ):
                info[ 'subdirs' ][ name ] = self._grubFilesystem( fqfn )

            else:

                logger.warning(
                    '%r was neither a file nor directory and so has been ignored',
                    fqfn
                    )

        return info


    security.declarePrivate('_getFilename')
    def _getFilename(self, name):
        """ Convert 'name' to a suitable filename, if needed.
        """
        if '.' not in name:
            return '%s.html' % name

        return name


    security.declarePrivate( '_getZipFile' )
    def _getZipFile( self, include_selenium=True ):
        """ Generate a zip file containing both tests and scaffolding.
        """
499
        stream = io.BytesIO()
Rafael Monnerat's avatar
Rafael Monnerat committed
500 501 502 503
        archive = zipfile.ZipFile( stream, 'w' )


        def convertToBytes(body):
504
            if isinstance(body, six.text_type):
Rafael Monnerat's avatar
Rafael Monnerat committed
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
                return body.encode(_DEFAULTENCODING)
            else:
                return body

        archive.writestr( 'index.html'
                        , convertToBytes(self.index_html( suite_name='testSuite.html' ) ) )

        test_cases = self.listTestCases()

        paths = { '' : [] }

        def _ensurePath( prefix, element ):
            elements = paths.setdefault( prefix, [] )
            if element not in elements:
                elements.append( element )

        for info in test_cases:
            # ensure suffixes
            path = self._getFilename( info[ 'path' ] )
            info[ 'path' ] = path
            info[ 'url' ] = self._getFilename( info[ 'url' ] )

            elements = path.split( os.path.sep )
            _ensurePath( '', elements[ 0 ] )

            for i in range( 1, len( elements ) ):
                prefix = '/'.join( elements[ : i ] )
                _ensurePath( prefix, elements[ i ] )

        archive.writestr( 'testSuite.html'
                        , convertToBytes(self.test_suite_html( test_cases=test_cases ) ) )

        for pathname, filenames in paths.items():

            if pathname == '':
                filename = '.objects'
            else:
                filename = '%s/.objects' % pathname

            archive.writestr( convertToBytes(filename)
                            , convertToBytes(u'\n'.join( filenames ) ) )

        for info in test_cases:
            test_case = info[ 'test_case' ]

            if getattr( test_case, '__call__', None ) is not None:
                body = test_case()  # XXX: DTML?
            else:
                body = test_case.manage_FTPget()

            archive.writestr( convertToBytes(info[ 'path' ])
                            , convertToBytes(body) )

        if include_selenium:

            for k, v in _SUPPORT_FILES.items():
                archive.writestr( convertToBytes(k),
                       convertToBytes(v.__of__(self).manage_FTPget() ) )

        archive.close()
        return stream.getvalue()

    security.declarePrivate('_listProductInfo')
    def _listProductInfo( self ):
        """ Return a list of strings of form '%(name)s %(version)s'.

        o Each line describes one product installed in the Control_Panel.
        """
        result = []
        cp = self.getPhysicalRoot().Control_Panel
        products = cp.Products.objectItems()
        products.sort()

        for product_name, product in products:
            version = product.version or 'unreleased'
            result.append( '%s %s' % ( product_name, version ) )

        return result


InitializeClass( Zuite )


class ZuiteResults( Folder ):

    security = ClassSecurityInfo()
    meta_type = 'Zuite Results'

    _properties = ( { 'id' : 'test_case_metatypes'
                    , 'type' : 'lines'
                    , 'mode' : 'w'
                    },
                    { 'id' : 'completed'
                    , 'type' : 'date'
                    , 'mode' : 'w'
                    },
601 602 603 604
                    { 'id' : 'finished'
                    , 'type' : 'boolean'
                    , 'mode' : 'w'
                    },
Rafael Monnerat's avatar
Rafael Monnerat committed
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
                    { 'id' : 'passed'
                    , 'type' : 'boolean'
                    , 'mode' : 'w'
                    },
                    { 'id' : 'time_secs'
                    , 'type' : 'float'
                    , 'mode' : 'w'
                    },
                    { 'id' : 'tests_passed'
                    , 'type' : 'int'
                    , 'mode' : 'w'
                    },
                    { 'id' : 'tests_failed'
                    , 'type' : 'int'
                    , 'mode' : 'w'
                    },
                    { 'id' : 'commands_passed'
                    , 'type' : 'int'
                    , 'mode' : 'w'
                    },
                    { 'id' : 'commands_failed'
                    , 'type' : 'int'
                    , 'mode' : 'w'
                    },
                    { 'id' : 'commands_with_errors'
                    , 'type' : 'int'
                    , 'mode' : 'w'
                    },
                    { 'id' : 'user_agent'
                    , 'type' : 'string'
                    , 'mode' : 'w'
                    },
                    { 'id' : 'remote_addr'
                    , 'type' : 'string'
                    , 'mode' : 'w'
                    },
                    { 'id' : 'http_host'
                    , 'type' : 'string'
                    , 'mode' : 'w'
                    },
                    { 'id' : 'server_software'
                    , 'type' : 'string'
                    , 'mode' : 'w'
                    },
                    { 'id' : 'product_info'
                    , 'type' : 'lines'
                    , 'mode' : 'w'
                    },
                  )

    security.declareObjectProtected( View )

    security.declarePublic( 'index_html' )
    index_html = PageTemplateFile( 'resultsView', _WWW_DIR )

    security.declareProtected( View, 'error_icon' )
    error_icon = ImageFile( 'error.gif', _WWW_DIR )

    security.declareProtected( View, 'check_icon' )
    check_icon = ImageFile( 'check.gif', _WWW_DIR )


    def __getitem__( self, key, default=_MARKER ):

        if key in self.objectIds():
            return self._getOb( key )

        if key == 'error.gif':
            return self.error_icon

        if key == 'check.gif':
            return self.check_icon

        if default is not _MARKER:
            return default

681
        raise KeyError(key)
Rafael Monnerat's avatar
Rafael Monnerat committed
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714

InitializeClass( ZuiteResults )

class _FilesystemProxy( Folder ):

    security = ClassSecurityInfo()

    def __init__( self, id, fsobjs ):

        self._setId( id )
        self._fsobjs = fsobjs

    def __getitem__( self, key ):

        return self.get( key )

    security.declareProtected( View, 'index_html' )
    index_html = PageTemplateFile( 'suiteView', _WWW_DIR )

    security.declareProtected( View, 'test_suite_html' )
    test_suite_html = PageTemplateFile( 'suiteTests', _WWW_DIR )

    security.declareProtected( View, 'get' )
    def get( self, key, default=_MARKER ):

        for tc in self._fsobjs[ 'testcases' ]:
            if tc.getId() == key:
                return tc.__of__( self.aq_parent )

        if key in self._fsobjs[ 'subdirs' ]:
            return self.__class__( key, self._fsobjs[ 'subdirs' ][ key ]
                                 ).__of__( self.aq_parent )

715 716 717 718 719
        try:
            file = _SUPPORT_FILES[key]
        except KeyError:
            if default is _MARKER:
                raise
Rafael Monnerat's avatar
Rafael Monnerat committed
720 721
            return default

722
        return file.__of__(self)
Rafael Monnerat's avatar
Rafael Monnerat committed
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749

    security.declareProtected( View, 'listTestCases' )
    def listTestCases( self, prefix=() ):
        """ Return a list of our contents which qualify as test cases.
        """
        result = []
        _recurseFSTestCases( result, prefix, self._fsobjs )
        return result

InitializeClass( _FilesystemProxy )

#
#   Factory methods
#
manage_addZuiteForm = PageTemplateFile( 'addZuite', _WWW_DIR )

def manage_addZuite(dispatcher, id, title='', REQUEST=None):
    """ Add a new Zuite to dispatcher's objects.
    """
    zuite = Zuite(id)
    zuite.title = title
    dispatcher._setObject(id, zuite)
    zuite = dispatcher._getOb(id)

    if REQUEST is not None:
        REQUEST['RESPONSE'].redirect('%s/manage_main'
                                       % zuite.absolute_url() )