def setUpModule(): """Create database and tables.""" global compmgr, userscomp, liccomp, attcomp, syscomp, projcomp, wikicomp, \ tckcomp, revcomp, xicomp, cachemgr testdir = os.path.basename(os.path.dirname(__file__)) testfile = os.path.basename(__file__) seed = config['seed'] and int(config['seed']) or genseed() log_mheader(log, testdir, testfile, seed) random.seed(seed) info = " Creating models (module-level) ... " log.info(info) print info # Setup SQLAlchemy database engine engine = engine_from_config(config, 'sqlalchemy.') # init_model( engine ) create_models(engine, config, sysentries_cfg=meta.sysentries_cfg, permissions=permissions) compmgr = config['compmgr'] userscomp = config['userscomp'] liccomp = LicenseComponent(compmgr) syscomp = SystemComponent(compmgr) attcomp = AttachComponent(compmgr) projcomp = ProjectComponent(compmgr) wikicomp = WikiComponent(compmgr) tckcomp = TicketComponent(compmgr) revcomp = ReviewComponent(compmgr) xicomp = XInterfaceComponent(compmgr) # Populate DataBase with sample entries print " Populating permissions ..." pop_permissions(seed=seed) print " Populating users ( no_of_users=%s, no_of_relations=%s ) ..." % \ ( no_of_users, no_of_relations ) pop_user(no_of_users, no_of_relations, seed=seed) print " Populating licenses ( no_of_tags=%s, no_of_attachs=%s ) ..." % \ ( no_of_tags, no_of_attachs ) pop_licenses(no_of_tags, no_of_attachs, seed=seed) print " Populating projects ( no_of_projects=%s ) ..." % no_of_projects pop_projects(no_of_projects, no_of_tags, no_of_attachs, seed=seed) print " Populating tickets ( no_of_tickets=%s ) ..." % no_of_tickets pop_tickets(no_of_tickets, no_of_tags, no_of_attachs, seed=seed) print " Populating vcs ( no_of_vcs=%s ) ..." % no_of_vcs pop_vcs(no_of_vcs=no_of_vcs, seed=seed) print " Populating wikis ( no_of_wikis=%s ) ..." % no_of_wikis pop_wikipages(no_of_tags, no_of_attachs, seed=seed) print " Populating reviews ( no_of_reviews=%s ) ..." % no_of_reviews pop_reviews(no_of_reviews, no_of_tags, no_of_attachs, seed=seed) print ( " no_of_users=%s, no_of_relations=%s, no_of_tags=%s, " + \ "no_of_attach=%s, no_of_projects=%s, no_of_reviews=%s" ) % \ ( no_of_users, no_of_relations, no_of_tags, no_of_attachs, no_of_projects, no_of_reviews ) # Setup cache manager isdir(cachedir) or os.makedirs(cachedir) cachemgr = cachemod.cachemanager(cachedir) config['cachemgr'] = cachemgr
def setUpModule() : """Create database and tables.""" global compmgr, userscomp, tagcomp, attachcomp, projcomp, wikicomp, wikidata, \ votcomp, zwparser, seed, cachemgr testdir = os.path.basename( os.path.dirname( __file__ )) testfile = os.path.basename( __file__ ) seed = config['seed'] and int(config['seed']) or genseed() log_mheader( log, testdir, testfile, seed ) random.seed( seed ) info = " Creating models (module-level) ... " log.info( info ) print info # Setup SQLAlchemy database engine engine = engine_from_config( config, 'sqlalchemy.' ) # init_model( engine ) create_models( engine, config, sysentries_cfg=meta.sysentries_cfg, permissions=permissions ) compmgr = config['compmgr'] userscomp = config['userscomp'] tagcomp = TagComponent( compmgr ) attachcomp = AttachComponent( compmgr ) projcomp = ProjectComponent( compmgr ) wikicomp = WikiComponent( compmgr ) votcomp = VoteComponent( compmgr ) # Populate DataBase with sample entries print " Populating permissions ..." pop_permissions( seed=seed ) print " Populating users ( no_of_users=%s, no_of_relations=%s ) ..." % \ ( no_of_users, no_of_relations ) pop_user( no_of_users, no_of_relations, seed=seed ) print " Populating licenses ( no_of_tags=%s, no_of_attachs=%s ) ..." % \ ( no_of_tags, no_of_attachs ) pop_licenses( no_of_tags, no_of_attachs, seed=seed ) print " Populating projects ( no_of_projects=%s ) ..." % no_of_projects pop_projects( no_of_projects, no_of_tags, no_of_attachs, seed=seed ) print " Populating tickets ( no_of_tickets=%s ) ..." % no_of_tickets pop_tickets( no_of_tickets, no_of_tags, no_of_attachs, seed=seed ) print " Populating vcs ( no_of_vcs=%s ) ..." % no_of_vcs pop_vcs( no_of_vcs=no_of_vcs, seed=seed ) print " Populating reviews ( no_of_reviews=%s ) ..." % no_of_reviews pop_reviews( no_of_reviews, no_of_tags, no_of_attachs, seed=seed ) # Collect the expected database objects. wikidata = gen_wiki( no_of_tags, no_of_attachs, seed=seed ) print ( " no_of_users=%s, no_of_relations=%s, no_of_tags=%s, " + \ "no_of_attach=%s, no_of_projects=%s, no_of_wikis=%s" ) % \ ( no_of_users, no_of_relations, no_of_tags, no_of_attachs, no_of_projects, no_of_wikis ) zwparser = ZWParser( lex_optimize=True, yacc_debug=True, yacc_optimize=False ) # Setup cache manager isdir( cachedir ) or os.makedirs( cachedir ) cachemgr = cachemod.cachemanager( cachedir ) config['cachemgr'] = cachemgr
def setUpModule() : """Create database and tables.""" global taglist, fnamelist, lines, compmgr, userscomp, filenames, \ attachcomp, liccomp, projcomp, tckcomp, revcomp, wikicomp, \ tagcomp, seed, cachemgr testdir = os.path.basename( os.path.dirname( __file__ )) testfile = os.path.basename( __file__ ) seed = config['seed'] and int(config['seed']) or genseed() log_mheader( log, testdir, testfile, seed ) random.seed( seed ) info = " Creating models (module-level) ... " log.info( info ) print info # Setup SQLAlchemy database engine engine = engine_from_config( config, 'sqlalchemy.' ) # init_model( engine ) create_models( engine, config, sysentries_cfg=meta.sysentries_cfg, permissions=permissions ) # prepare data for testing taglist = [ unicode(h.randomname( randint(0,LEN_TAGNAME), alphanum)) for i in range(randint(0,500)) ] fnamelist = [ h.randomname( randint(1,128) ) + choice( extnames ) for i in range(1000) ] lines = [ ''.join([ choice( alphanum ) for i in range(80) ]) for i in range(50) ] compmgr = config['compmgr'] userscomp = config['userscomp'] attachcomp= AttachComponent( compmgr ) tagcomp = TagComponent( config['compmgr'] ) liccomp = LicenseComponent( compmgr ) projcomp = ProjectComponent( compmgr ) tckcomp = TicketComponent( compmgr ) revcomp = ReviewComponent( compmgr ) wikicomp = WikiComponent( compmgr ) print " Creating `%s` directory for generating attachments ..." % tmp_dir not os.path.isdir( tmp_dir ) and os.makedirs( tmp_dir ) filenames = gen_localfiles( tmp_dir, [ fnamelist.pop( fnamelist.index(choice(fnamelist)) ) for i in range( no_of_attach ) ] ) # Populate DataBase with sample entries print " Populating permissions ..." pop_permissions( seed=seed ) print " Populating users ( no_of_users=%s, no_of_relations=%s ) ..." % \ ( no_of_users, no_of_relations ) pop_user( no_of_users, no_of_relations, seed=seed ) print " no_of_users=%s, no_of_relations=%s, no_of_attach=%s" % \ (no_of_users, no_of_relations, no_of_attach) # Setup cache manager isdir( cachedir ) or os.makedirs( cachedir ) cachemgr = cachemod.cachemanager( cachedir ) config['cachemgr'] = cachemgr
def setUpModule(): """Create database and tables.""" global compmgr, userscomp, attachcomp, tagcomp, projcomp, tckcomp, taglist,\ seed, cachemgr isdir(dotdir) or os.makedirs(dotdir) testdir = os.path.basename(os.path.dirname(__file__)) testfile = os.path.basename(__file__) seed = config['seed'] and int(config['seed']) or genseed() log_mheader(log, testdir, testfile, seed) random.seed(seed) info = " Creating models (module-level) ... " log.info(info) print info # Setup SQLAlchemy database engine engine = engine_from_config(config, 'sqlalchemy.') # init_model( engine ) create_models(engine, config, sysentries_cfg=meta.sysentries_cfg, permissions=permissions) compmgr = config['compmgr'] userscomp = config['userscomp'] attachcomp = AttachComponent(compmgr) tagcomp = TagComponent(compmgr) liccomp = LicenseComponent(compmgr) projcomp = ProjectComponent(compmgr) tckcomp = TicketComponent(compmgr) taglist = [ unicode(h.randomname(randint(1, LEN_TAGNAME), tagchars)) for i in range(randint(1, no_of_tags)) ] # Populate DataBase with sample entries print " Populating permissions ..." pop_permissions(seed=seed) print " Populating users ( no_of_users=%s, no_of_relations=%s ) ..." % \ ( no_of_users, no_of_relations ) pop_user(no_of_users, no_of_relations, seed=seed) print " Populating licenses ( no_of_tags=%s, no_of_attachs=%s ) ..." % \ ( no_of_tags, no_of_attachs ) pop_licenses(no_of_tags, no_of_attachs, seed=seed) print " Populating projects ( no_of_projects=%s ) ..." % no_of_projects pop_projects(no_of_projects, no_of_tags, no_of_attachs, seed=seed) print " Populating tickets ( no_of_tickets=%s ) ..." % no_of_tickets pop_tickets(no_of_tickets, no_of_tags, no_of_attachs, seed=seed) print ( " no_of_users=%s, no_of_relations=%s, no_of_tags=%s, " + \ "no_of_attach=%s, no_of_projects=%s, no_of_tickets=%s" ) % \ ( no_of_users, no_of_relations, no_of_tags, no_of_attachs, no_of_projects, no_of_tickets ) # Setup cache manager isdir(cachedir) or os.makedirs(cachedir) cachemgr = cachemod.cachemanager(cachedir) config['cachemgr'] = cachemgr
def setUpModule(): """Create database and tables.""" global compmgr, userscomp, syscomp, attachcomp, seed, cachemgr testdir = os.path.basename(os.path.dirname(__file__)) testfile = os.path.basename(__file__) seed = config['seed'] and int(config['seed']) or genseed() log_mheader(log, testdir, testfile, seed) random.seed(seed) info = " Creating models (module-level) ... " log.info(info) print info # Setup SQLAlchemy database engine engine = engine_from_config(config, 'sqlalchemy.') # init_model( engine ) create_models(engine, config, sysentries_cfg=meta.sysentries_cfg, permissions=permissions) userscomp = config['userscomp'] compmgr = config['compmgr'] syscomp = SystemComponent(compmgr) attachcomp = AttachComponent(compmgr) print " Populating permissions ..." pop_permissions(seed=seed) print " Populating users ( no_of_users=%s, no_of_relations=%s ) ..." % \ ( no_of_users, no_of_relations ) pop_user(no_of_users, no_of_relations, seed=seed) # initialize the PMS system mapmod = eval_import(config['zeta.pmap.module']) permmod.init_pms = eval_import(config['zeta.pmap.mapfunc']) permmod.pms_root = permmod.init_pms(ctxt=ctxt) permmod.default_siteperms = mapmod.default_siteperms permmod.default_projperms = mapmod.default_projperms # Setup cache manager isdir(cachedir) or os.makedirs(cachedir) cachemgr = cachemod.cachemanager(cachedir) config['cachemgr'] = cachemgr
def loadcomponents(config, global_conf, app_conf): from zeta.auth.users import UserComponent from zeta.comp.system import SystemComponent from zeta.comp.attach import AttachComponent from zeta.comp.license import LicenseComponent from zeta.comp.project import ProjectComponent from zeta.comp.review import ReviewComponent from zeta.comp.tag import TagComponent from zeta.comp.ticket import TicketComponent from zeta.comp.timeline import TimelineComponent from zeta.comp.vcs import VcsComponent from zeta.comp.vote import VoteComponent from zeta.comp.wiki import WikiComponent from zeta.comp.xinterface import XInterfaceComponent from zeta.comp.xsearch import XSearchComponent from zeta.comp.zmail import ZMailComponent from zeta.comp.forms import VForm global userscomp, syscomp, attcomp, attachcomp, liccomp, projcomp, prjcomp,\ revcomp, revwcomp, tagcomp, tckcomp, tlcomp, vcscomp, votecomp, \ votcomp, wikicomp, xintcomp, xicomp, srchcomp, zmailcomp, mailcomp, \ vfcomp userscomp = config['userscomp'] = UserComponent(compmgr) syscomp = SystemComponent(compmgr) attcomp = attachcomp = AttachComponent(compmgr) liccomp = LicenseComponent(compmgr) projcomp = prjcomp = ProjectComponent(compmgr) revcomp = revwcomp = ReviewComponent(compmgr) tagcomp = TagComponent(compmgr) tckcomp = TicketComponent(compmgr) tlcomp = TimelineComponent(compmgr) vcscomp = VcsComponent(compmgr) votecomp = votcomp = VoteComponent(compmgr) wikicomp = WikiComponent(compmgr) xintcomp = xicomp = XInterfaceComponent(compmgr) srchcomp = XSearchComponent(compmgr) zmailcomp = mailcomp = ZMailComponent(compmgr, config=config) vfcomp = VForm(compmgr) return None
def setUpModule() : """Create database and tables.""" global compmgr, liccomp, userscomp, attachcomp, licdata, zwparser, seed, \ cachemgr testdir = os.path.basename( os.path.dirname( __file__ )) testfile = os.path.basename( __file__ ) seed = config['seed'] and int(config['seed']) or genseed() log_mheader( log, testdir, testfile, seed ) random.seed( seed ) info = " Creating models (module-level) ... " log.info( info ) print info # Setup SQLAlchemy database engine engine = engine_from_config( config, 'sqlalchemy.' ) # init_model( engine ) create_models( engine, config, sysentries_cfg=meta.sysentries_cfg, permissions=permissions ) compmgr = config['compmgr'] userscomp = config['userscomp'] liccomp = LicenseComponent( compmgr ) attachcomp = AttachComponent( compmgr ) # Populate DataBase with sample entries print " Populating permissions ..." pop_permissions( seed=seed ) print " Populating users ( no_of_users=%s, no_of_relations=%s ) ..." % \ ( no_of_users, no_of_relations ) pop_user( no_of_users, no_of_relations, seed=seed ) licdata = gen_licenses( no_of_tags=no_of_tags, no_of_attachs=no_of_attachs ) print " no_of_users=%s, no_of_relations=%s, no_of_tags=%s, no_of_attach=%s" % \ ( no_of_users, no_of_relations, no_of_tags, no_of_attachs ) zwparser = ZWParser( lex_optimize=True, yacc_debug=True, yacc_optimize=False ) # Setup cache manager isdir( cachedir ) or os.makedirs( cachedir ) cachemgr = cachemod.cachemanager( cachedir ) config['cachemgr'] = cachemgr
def test_B_photoicon( self ) : """Testing user photo and icon methods""" log.info( "Testing user photo and icon methods ..." ) c = ContextObject() config['c'] = c attachcomp = AttachComponent( config['compmgr'] ) for username in userdata : d = userdata[username] user = userscomp.get_user( username.lower() ) photofile = d['photofile'] photo = None # Photo file api c.rclose = h.ZResp() defer = choice([True, False]) if photofile : photo = attachcomp.create_attach( os.path.basename( photofile ), fdfile=open( photofile, 'r' ), uploader=user ) userscomp.user_set_photo( choice([ user, user.username, user.id ]), photo, c=c, defer=defer ) self._validate_defer( user, defer, c, lambda u : 'uploaded user photo' in u.logs[-1].log ) # Icon file api c.rclose = h.ZResp() defer = choice([True, False]) iconfile = d['iconfile'] icon = None if iconfile : icon = attachcomp.create_attach( os.path.basename( iconfile ), fdfile=open( iconfile, 'r' ), uploader=username ) userscomp.user_set_icon( choice([ user, user.username, user.id ]), icon, c=c, defer=defer ) self._validate_defer( user, defer, c, lambda u : 'uploaded user icon' in u.logs[-1].log, ) # Delete photo or icon c.rclose = h.ZResp() defer = choice([True, False]) update = choice([ True, False ]) # Randomly update if update : userscomp.user_set_photo( user, photo=None, c=c, defer=defer ) userscomp.user_set_icon( user, icon=None, c=c, defer=defer ) d['photofile'] = photofile = None d['iconfile'] = iconfile = None # _validate_defer defer and c.rclose.close() user = userscomp.get_user( user.id, attrload=[ 'logs' ] ) if iconfile : assert_true( 'removed user icon' in user.logs[-1].log, 'Mismatch in defer' ) if photofile : assert_true( 'removed user photo' in user.logs[-2].log, 'Mismatch in defer' ) if photofile : assert_equal( user.photofile.filename, os.path.basename( photofile ), 'Mismatching photo file name' ) a, content = attachcomp.downloadattach(user.photofile) assert_equal( str(content), open( photofile, 'r' ).read(), 'Mismatch in user photo attachment' ) if iconfile : assert_equal( user.iconfile.filename, os.path.basename( iconfile ), 'Mismatching icon file name' ) a, content = attachcomp.downloadattach(user.iconfile) assert_equal( str( content ), open( iconfile ).read(), 'Mismatch in user icon attachment' ) self._validate_user( userdata )