Changeset 3015 in products


Ignore:
Timestamp:
Nov 13, 2010 5:38:53 PM (13 years ago)
Author:
fenix
Message:

added test for whole 'ownership_by_type' view

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.analytics/trunk/quintagroup/analytics/tests.py

    r3014 r3015  
    5656    @classmethod 
    5757    def setupContent(cls, portal): 
    58         """ Creates users""" 
     58        """ Creates test content.""" 
    5959        uf = portal.acl_users 
    6060        pm = portal.portal_membership 
     
    161161    layer = SetUpContent 
    162162 
     163    def afterSetUp(self): 
     164        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST), 
     165                                 name="ownership_by_type") 
     166        self.pc = self.portal.portal_catalog 
     167 
    163168    def test_getUsers(self): 
    164         """ 
    165         """ 
    166         view = queryMultiAdapter((self.portal, self.portal.REQUEST), 
    167                                  name="ownership_by_type") 
    168  
    169         self.assert_(False in map(lambda u1, u2:u1==u2, 
    170                      [u[0] for u in self.layer.users], view.getUsers())) 
    171  
     169        """ Tests method that returns ordered list of users.""" 
     170        users = [u[0] for u in self.layer.users] 
     171        users.reverse() 
     172        self.assert_(False not in map(lambda u1, u2:u1==u2, 
     173                     users, self.view.getUsers())) 
     174 
     175    def test_getTypes(self): 
     176        """ Tests method that returns ordered list of types.""" 
     177        data = {} 
     178        index = self.pc._catalog.getIndex('portal_type') 
     179        for k in index._index.keys(): 
     180            if not k: 
     181                continue 
     182            haslen = hasattr(index._index[k], '__len__') 
     183            if haslen: 
     184                data[k] = len(index._index[k]) 
     185            else: 
     186                data[k] = 1 
     187        data = data.items() 
     188        data.sort(lambda a, b: a[1] - b[1]) 
     189        data.reverse() 
     190        types = [i[0] for i in data] 
     191        self.assert_(False not in map(lambda t1, t2:t1==t2, 
     192                     self.view.getTypes(), types)) 
     193 
     194    def test_getContent(self): 
     195        """ This test verifies method that returns list of numbers. 
     196            Each number is amount of specified content type objects 
     197            that owned  by particular user. 
     198        """ 
     199        # we need to login in to the site as Manager to be able to 
     200        # see catalog results 
     201        self.loginAsPortalOwner() 
     202 
     203        for type_ in self.layer.types_: 
     204            self.assert_(False not in \ 
     205            map(lambda i, j:i==j, [len(self.pc(portal_type=type_, Creator=user)) 
     206                                   for user in self.view.getUsers()], 
     207                                  self.view.getContent(type_))) 
     208 
     209    def test_getChart(self): 
     210        """ This test verifies creation of chart image tag.""" 
     211        chart_tag = """<img src="http://chart.apis.google.com/chart?chxt=y&amp; 
     212                       chds=0,57&amp;chd=t:19.0,18.0,17.0,16.0,15.0,14.0, 
     213                       13.0,12.0,11.0,10.0|19.0,18.0,17.0,16.0,15.0,14.0,13.0, 
     214                       12.0,11.0,10.0|19.0,18.0,17.0,16.0,15.0,14.0,13.0,12.0, 
     215                       11.0,10.0|0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0|&amp; 
     216                       chxr=0,0,57&amp;chco=669933,cc9966,993300,ff6633,e8e4e3, 
     217                       a9a486,dcb57e,ffcc99,996633,333300,00ff00&amp;chl=user9| 
     218                       user8|user7|user6|user5|user4|user3|user2|user1|user0&amp; 
     219                       chbh=a,10,0&amp;chs=800x375&amp;cht=bvs&amp; 
     220                       chtt=Content+ownership+by+type&amp;chdl=Folder|Document| 
     221                       Event|Topic|Other+types&amp;chdlp=b" />""" 
     222        self.loginAsPortalOwner() 
     223        self.assertEqual(*map(lambda s:''.join(s.split()), 
     224                              [chart_tag, self.view.getChart()])) 
    172225 
    173226 
Note: See TracChangeset for help on using the changeset viewer.