Exemple #1
0
    def test_8_usericon_valid(self):
        """Testing FormUserIcon with valid input"""
        log.info("Testing FormUserIcon with valid inputs")
        request = RequestObject()
        c = ContextObject()
        vf = VForm(compmgr)
        config['c'] = c
        c.authuser = g_byuser

        # Add user icon
        c.rclose = h.ZResp()
        request.params.clearfields()
        request.POST.clearfields()
        request.params.add('form', 'submit')
        request.params.add('formname', 'usericon')
        u = userscomp.get_user(u'someusername')
        attachfile = choice(attachfiles)
        attach = FileObject()
        attach.filename = os.path.basename(attachfile)
        attach.file = open(attachfile, 'r')
        request.POST.add('user_id', str(u.id))
        request.POST.add('attachfile', attach)
        user = choice(userscomp.get_user())
        defer = choice([True, False])
        vf.process(request,
                   c,
                   user=user.username,
                   defer=defer,
                   formnames=['usericon'])

        self._validate_defer(u.id, defer, c,
                             lambda u: 'uploaded user icon' in u.logs[-1].log)

        u = userscomp.get_user(u.username)
        assert_equal(u.iconfile.filename, attach.filename,
                     'Mismatch in icon attachment')
        a, cont = attachcomp.downloadattach(u.iconfile.id)
        assert_equal( str(cont), open( attachfile ).read(),
                      'icon files mismatches between files `%s` and `%s`' % \
                      (attachfile, u.iconfile.id)
                    )

        # Delete user icon
        c.rclose = h.ZResp()
        request.params.clearfields()
        request.POST.clearfields()
        request.params.add('form', 'submit')
        request.params.add('formname', 'delusericon')
        request.POST.add('user_id', str(u.id))
        defer = choice([True, False])
        vf.process(request, c, defer=defer, formnames=['delusericon'])
        self._validate_defer(u.id, defer, c,
                             lambda u: 'removed user icon' in u.logs[-1].log)

        u = userscomp.get_user(u.username)
        assert_false(u.iconfile,
                     'Found icon attachment even after removing it')
Exemple #2
0
    def test_E_wikifavorites( self ) :
        """Testing FormWikiFavorite with valid and invalid inputs"""
        log.info( "Testing FormWikiFavorite with valid and invalid inputs" )
        request     = RequestObject()
        c           = ContextObject()
        vf          = VForm( compmgr )
        config['c'] = c
        c.authuser  = g_byuser

        users    = userscomp.get_user()
        projects = projcomp.get_project()
        wikis    = wikicomp.get_wiki()
        user     = choice( users )
        p        = choice( projects )
        w        = choice( wikis )

        wikicomp.delfavorites( w, w.favoriteof, byuser=g_byuser )

        # Add favorite user
        c.rclose = h.ZResp()
        request.params.add( 'form', 'submit' )
        request.params.add( 'formname', 'wikifav' )
        request.POST.add( 'user_id', str(user.id) )
        request.POST.add( 'project_id', str(p.id) )
        request.POST.add( 'wiki_id', str(w.id) )
        request.POST.add( 'addfavuser', user.username )
        defer = choice([True, False])
        vf.process( request, c, defer=defer, formnames=['wikifav'] )

        self._validate_defer(
                c.authuser, defer, c,
                lambda _u : 'added wiki page as favorite' in _u.logs[-1].log
        )

        assert_equal( wikicomp.get_wiki( w.id ).favoriteof, [ user ],
                      'Mismatch in adding favorite user for wiki'
                    )

        # Del favorite user
        c.rclose = h.ZResp()
        request.POST.clearfields()
        request.POST.add( 'user_id', str(user.id) )
        request.POST.add( 'project_id', str(p.id) )
        request.POST.add( 'wiki_id', str(w.id) )
        request.POST.add( 'delfavuser', user.username )
        defer = choice([True, False])
        vf.process( request, c, defer=defer, formnames=['wikifav'] )

        self._validate_defer(
                c.authuser, defer, c,
                lambda _u : 'removed wiki page from favorite' in _u.logs[-1].log
        )

        assert_equal( wikicomp.get_wiki( w.id ).favoriteof, [],
                      'Mismatch in deleting favorite user for wiki'
                    )
Exemple #3
0
    def test_8_reviewfavorite(self):
        """Testing FormReviewFavorite with valid and invalid inputs"""
        log.info("Testing FormReviewFavorite with valid and invalid inputs")
        request = RequestObject()
        c = ContextObject()
        vf = VForm(compmgr)
        config['c'] = c
        c.authuser = g_byuser

        users = userscomp.get_user()
        projects = projcomp.get_project()
        reviews = revcomp.get_review()
        user = choice(users)
        p = choice(projects)
        r = choice(reviews)

        revcomp.delfavorites(r, r.favoriteof, byuser=g_byuser)

        # Add favorite user
        c.rclose = h.ZResp()
        request.params.add('form', 'submit')
        request.params.add('formname', 'revwfav')
        request.POST.add('user_id', str(user.id))
        request.POST.add('project_id', str(p.id))
        request.POST.add('review_id', str(r.id))
        request.POST.add('addfavuser', user.username)
        defer = choice([True, False])
        vf.process(request, c, defer=defer, formnames=['revwfav'])

        self._validate_defer(
            c.authuser, defer, c,
            lambda u: 'added review as favorite' in u.logs[-1].log)

        assert_equal(
            revcomp.get_review(r.id).favoriteof, [user],
            'Mismatch in adding favorite user for review')

        # Del favorite user
        c.rclose = h.ZResp()
        request.POST.clearfields()
        request.POST.add('user_id', str(user.id))
        request.POST.add('project_id', str(p.id))
        request.POST.add('review_id', str(r.id))
        request.POST.add('delfavuser', user.username)
        defer = choice([True, False])
        vf.process(request, c, defer=defer, formnames=['revwfav'])

        self._validate_defer(
            c.authuser, defer, c,
            lambda u: 'removed review from favorite' in u.logs[-1].log)

        assert_equal(
            revcomp.get_review(r.id).favoriteof, [],
            'Mismatch in deleting favorite user for review')
Exemple #4
0
    def test_6_tags( self ) :
        """Testing tag additions and removals"""
        log.info( "Testing tag additions and removals ..." )
        c           = ContextObject()
        config['c'] = c
        c.authuser  = g_byuser

        for ln in licdata :
            c.rclose = h.ZResp()
            lic       = licdata[ln]
            l         = lic['id']
            byuser    = choice( lic['tags'].keys() )
            tags      = lic['tags'][byuser]
            tagaslist = tags and choice(tags) or ''
            tagasitem = tags and choice(tags) or ''
            rmtag     = tags and choice(tags) or ''
            defer = False

            tags and \
                liccomp.add_tags( choice([ l.id, l.licensename, l ]), 
                                  tags, c=c, defer=defer, byuser=byuser )
            tagaslist and \
                liccomp.add_tags( choice([ l.id, l.licensename, l ]),
                                  [tagaslist], c=c, defer=defer, byuser=byuser )
            tagasitem and \
                liccomp.add_tags( choice([ l.id, l.licensename, l ]),
                                  tagasitem, c=c, defer=defer, byuser=byuser )

            # Validate deferred post processing
            if tags or tagaslist or tagasitem :
                self._validate_defer(
                        byuser, defer, c,
                        lambda u : 'added tags' in u.logs[-1].log 
                )

            if rmtag :
                defer = choice([True, False])
                c.rclose = h.ZResp()
                liccomp.remove_tags( l, rmtag, c=c, defer=defer )
                lic['tags'][byuser].remove( rmtag )

                self._validate_defer(
                        c.authuser, defer, c,
                        lambda u : 'deleted tags' in u.logs[-1].log 
                )


        for l in liccomp.get_license() :
            tags = []
            [ tags.extend( v ) for v in  licdata[l.licensename]['tags'].values() ]
            assert_equal( sorted(tags),
                          sorted([ t.tagname for t in l.tags ]),
                          'Mismatch in tag creation'
                        )
Exemple #5
0
    def test_G_resetpass(self):
        """Testing FormResetPass with valid input"""
        log.info("Testing FormResetPass with valid input")

        # Setup mail-db
        mdb = MailDB(config)
        assert_true(mdb.Session, "Mismatch, Session is false")
        mdb.deldomains(mdb.listdomains())
        [mdb.deluser(e) for e, p in mdb.listusers()]

        mdb.adddomains('virtual.test')
        mdb.adddomains('example.com')
        mdb.adduser(config, '*****@*****.**', 'pratap123')
        mdb.adduser(config, '*****@*****.**', 'password')

        request = RequestObject()
        c = ContextObject()
        vf = VForm(compmgr)
        config['c'] = c
        c.rclose = h.ZResp()

        u = choice(userscomp.get_user())

        # Try adding invalid perm_group
        passwd = 'newpass123'
        c.rclose = h.ZResp()
        request.params.clearfields()
        request.POST.clearfields()
        request.params.add('form', 'submit')
        request.params.add('formname', 'resetpass')
        request.POST.add('confpass', passwd)
        request.POST.add('password', passwd)

        defer = choice([True, False])
        vf.process(request,
                   c,
                   defer=defer,
                   emailid=u.emailid,
                   formnames=['resetpass'])
        self._validate_defer(
            u.id, defer, c,
            lambda u: 'updated user preference' in u.logs[-1].log)

        assert_equal(u.password,
                     sha1(passwd).hexdigest(),
                     'Mismatch in resetting password')

        # Cleanup db
        mdb = MailDB(config)
        mdb.deldomains(mdb.listdomains())
        [mdb.deluser(e) for e, p in mdb.listusers()]
Exemple #6
0
    def test_6_removewikicontent( self ) :
        """Testing FormRemoveWikiContent with valid and invalid input"""
        log.info( "Testing FormRemoveWikiContent with valid and invalid inputs" )
        request     = RequestObject()
        c           = ContextObject()
        vf          = VForm( compmgr )
        config['c'] = c
        c.authuser  = g_byuser

        request.params.add( 'form', 'submit' )
        request.params.add( 'formname', 'rmwikicont' )

        users    = userscomp.get_user()
        projects = projcomp.get_project()
        u        = choice( users )

        # Create wiki content
        c.rclose = h.ZResp()
        w = wikicomp.get_wiki( u'some wiki url' )
        wpages = wikicomp.get_content( w.id, all=True ) # Get all versions
        assert_true( len(wpages) == 2, 'Mismatch in no of created wiki contents' )
        request.POST.add( 'user_id', str(u.id) )
        request.POST.add( 'wiki_id', str(w.id) )
        request.POST.add( 'version_id', str(wpages[1].id) )
        defer = choice([True, False])
        vf.process( request, c, defer=defer, formnames=['rmwikicont'] )

        self._validate_defer(
                c.authuser, defer, c,
                lambda _u : 'removed wiki page version' in _u.logs[-1].log 
        )

        wpages   = wikicomp.get_content( w.id, all=True ) # Get all versions
        assert_true( len(wpages) == 1, 'Mismatch in no of removed wiki contents' )
Exemple #7
0
    def timeline( self, environ, username ) :
        """User timeline
        URLS :
            /u/timeline/{username}
        """
        from zeta.config.environment import userscomp

        c.rclose = h.ZResp()

        # Action specific query parameters
        logid   = request.params.get( 'logid', None )
        dir     = request.params.get( 'dir', None )
        fromoff = request.params.get( 'fromoff', 1 )
        logid   = logid and int(logid)
        fromoff = int(fromoff)
        
        c.user = userscomp.get_user( username )
        self.tline_controller(
            h.r_usertline, { 'username' : username }, [ 'user' ],
            fromoff, logid, dir, c.user
        )
        c.title   = '%s:timeline' % username
        c.datatline, c.startdt = h.tlineplot( c.logs[:] )
        c.timeline = True

        # Html page generation
        c.rclose.append(render( '/derived/userpage/usertline.html' ))
        return c.rclose
Exemple #8
0
    def usercharts( self, environ, username='' ) :
        """User charts
        URLS :
            /u/{username}/charts
            /u/{username}/charts?chartname=<name>
        """
        from zeta.config.environment import userscomp

        c.rclose = h.ZResp()

        # Setup context for page rendering
        c.chartname = c.chartname or 'chart12'
        c.selectedchart = (c.chartname, self._usercharts[c.chartname])
        c.chartoptions = [ (self.url_userschart(name), text)
                           for name, text in self._usercharts.iteritems() ]

        c.user = userscomp.get_user( unicode(username) )
        c.ua   = ca.get_analyticobj( 'users' )

        data   = getattr( c.ua, 'chart12_data', {} ).get(
                          c.user.id, [ c.user.id, c.user.username, [] ] )
        c.chart12_data = data
        c.title   = '%s:Charts' % username

        # Html page generation
        c.rclose.append(render( '/derived/userpage/usercharts.html' ))
        return c.rclose
Exemple #9
0
    def charts( self, environ ) :
        """Charts for combined users
        URLS :
            /u/charts
            /u/charts?chartname=<name>
        """
        from zeta.config.environment import userscomp

        c.rclose = h.ZResp()

        # Setup context for page rendering
        c.chartname = c.chartname or 'chart8'
        c.selectedchart = (c.chartname, self._userscharts[c.chartname])
        c.chartoptions = [ (self.url_userschart(name), text)
                           for name, text in self._userscharts.iteritems() ]

        c.ua     = ca.get_analyticobj( 'users' )

        if c.chartname == 'chart8' :    # User activity
            c.chart8_data  = getattr( c.ua, 'chart8_data', [] )
        elif c.chartname == 'chart9' :  # User site-permission
            c.chart9_data  = getattr( c.ua, 'chart9_data', [] )
        elif c.chartname == 'chart10' : # project administrators
            c.chart10_data = getattr( c.ua, 'chart10_data', [] )
        elif c.chartname == 'chart11' : # Component owners
            c.chart11_data = getattr( c.ua, 'chart11_data', [] )
            c.chart11_ccnt = getattr( c.ua, 'chart11_ccnt', [] )

        c.title = 'Users:Charts'

        # Html page generation
        c.rclose.append(render( '/derived/userpage/userscharts.html' ))
        return c.rclose
Exemple #10
0
    def index( self, environ ) :
        """Index of all registered users
        URLS :
            /u
            /u?alphaindex=<a>
        """
        from zeta.config.environment import userscomp

        c.rclose = h.ZResp()

        # Setup context for page rendering
        c.users = userscomp.get_user( attrload=[ 'userinfo', 'photofile' ] )
        byindex = {}
        [ byindex.setdefault( u.username[0], [] ).append(u) for u in c.users ]
        c.indexlist = sorted( byindex.keys() )
        if (c.alphaindex == None) and (len(c.users) > h.MAX2SWITCH_ALPHAINDEX) :
            c.alphaindex = c.indexlist[0]
        if c.alphaindex :
            c.users = byindex[c.alphaindex]
        c.urlusersphoto = dict([
            ( u.id, h.url_attach( u.photofile.id ) )
            for u in c.users if u.photofile
        ])
        c.title = 'Users'

        # Html page generation
        if c.jsonobj and c.view == 'js' :
            html = self.handlejson(environ)
        else :
            html = render( '/derived/userpage/usersindex.html' )
        c.rclose.append(html)
        return c.rclose
Exemple #11
0
    def liccreate(self, environ):
        """Create a new license to be hosted on this site.
        URLS :
            /license/create
            /license/create?form=submit&formname=createlic
        """
        from zeta.config.environment import vfcomp

        c.rclose = h.ZResp()

        # Form handling
        def errhandler(errmsg):
            c.errmsg = errmsg

        vfcomp.process(request,
                       c,
                       defer=True,
                       errhandler=h.hitchfn(errhandler),
                       formnames=['createlic'],
                       user=c.authuser)

        # Setup context for page generation
        c.licensenames, c.licenselist, licfields = self._selectoptions()
        c.title = (c.form == 'request' and '-Skip-') or 'CreateLicense'

        # Html page generation
        if c.errmsg:
            html = self.returnerrmsg(environ)
        else:
            html = render('/derived/license/liccreate.html')
        c.rclose.append(html)
        return c.rclose