Index: quintagroup.analytics/branches/treemap/quintagroup/analytics/browser/treemap.py
===================================================================
--- quintagroup.analytics/branches/treemap/quintagroup/analytics/browser/treemap.py	(revision 3374)
+++ quintagroup.analytics/branches/treemap/quintagroup/analytics/browser/treemap.py	(revision 3404)
@@ -390,5 +390,6 @@
                         text = field_name, font = font, 
                         fill = self.getPilColor(treemap.data.color))
-        
+            return True
+
     def drawTreemap(self, treemap, image):
         """ Method generates treemap image """
Index: quintagroup.analytics/branches/treemap/quintagroup/analytics/test_treemap.py
===================================================================
--- quintagroup.analytics/branches/treemap/quintagroup/analytics/test_treemap.py	(revision 3374)
+++ 	(revision )
@@ -1,301 +1,0 @@
-import unittest
-from unittest import TestSuite, makeSuite, TestCase
-from itertools import izip
-
-from quintagroup.analytics.browser.treemap import TreemapBTree, Treemap, \
-                                                  TreemapControl, \
-                                                  TreemapHtml, \
-                                                  TreemapImage
-
-#class TestQRectangle(unittest.TestCase):
-#    def setUp(self):
-#        self.rect = QRectangle(100,100,200,200,1000)
-#        self.rect.append(QRectangle(size=10))
-#        self.rect.append(QRectangle(size=20))
-#    
-#    def test_length(self):
-#        """ Testing lengths 'self' object """
-#        self.assertEqual(2, self.rect.length())
-#
-#    def test_coordinates(self):
-#        """ Testing setCoordinates() and getCoordinates """
-#        self.rect.setCoordinates((5,5,10,10))
-#        self.assertEqual((5,5,10,10), self.rect.getCoordinates())
-#
-#    def test_size(self):
-#        """ Testing getSize() and setSize() """
-#        self.rect.setSize(10)
-#        self.assertEqual(10.0, self.rect.getSize())
-#    
-#    def test_getWeight(self):
-#        """ Tests method that returns size of QRectangle objects"""
-#        self.assertEqual(30.0, self.rect.getWeight())
-#    
-#    def test_addItem(self):
-#        """ Tests method that add QRectangle object in QRectangle list """
-#        self.assertEqual(1, self.rect.addItem(QRectangle(size=10)))
-#        self.assertEqual(0, self.rect.addItem(QRectangle(size=0)))
-#
-#    def test_layout(self):
-#        """ Tests method that forms (x1, y1, x2, y2) for rectangles """
-#        self.rect.layout()
-#        isNumber = lambda x: abs(x - round(x, 1)) < 0.1
-#        self.assertEqual((True, True, True, True),
-#                             tuple(imap(isNumber, self.rect[0].getCoordinates())))
-#        self.assertEqual((True, True, True, True),
-#                             tuple(imap(isNumber, self.rect[1].getCoordinates())))
-
-
-def createTreemap(cls = Treemap):
-    """ Method dedicated to create tests instance """
-    treemap = cls(x=0, y=0, w=100,h=100)
-    treemap.addItems([Treemap(size=50, color='#ad3333', title='admin4'),
-                      Treemap(size=30, color='#4af6a0', title='admin2'),
-                      Treemap(size=20, color='#9c1b9c', title='admin3'),
-                      Treemap(size=10, color='#fde5be', title='admin1')])
-    return treemap
-
-def getCoordinates(treemap, nominal):
-     for i,x in enumerate(treemap):
-          for coord in zip(x.coordinates, nominal[i]):
-              yield coord
-    
-
-class StubSizeByPath:
-    @staticmethod
-    def getTreemapInfo():
-        return [{'size': 10, 'id': 'admin1', 'type': 'Image'},
-                {'size': 30, 'id': 'admin2', 'type': 'File'},
-                {'size': 20, 'id': 'admin3', 'type': 'File'},
-                {'size': 50, 'id': 'admin4', 'type': 'Image'}]
-    
-    
-class TestTreemapBTree(unittest.TestCase):
-    """ Class dedicated to test treemap binary tree """
-    def createTreemap(self):
-        """ Method dedicated to create tests instance """
-        treemap = Treemap(size=100)
-        for x in [10, 20, 30,40]: 
-            treemap.append(Treemap(size=x))
-        treemap[3].addItems([Treemap(size=20), Treemap(size=20)])
-        return treemap
-
-    def setUp(self):
-        self.treemap = self.createTreemap()
-        self.btree = TreemapBTree(data=self.treemap)
-
-    def test_getWeight(self):
-        """ Tests method that returns size of objects """
-        self.assertEqual(100, self.btree.getWeight(self.treemap))
-
-    def test_getHalfSize(self):
-        """ Tests method that returns half size of objects"""
-        self.assertEqual(3, self.btree.getHalfSize(self.treemap))
-    
-    def test_addNodes(self):
-        """ Tests method adds treemap objects into TreemapBTree """
-        def getItems(treemap):
-            if not(treemap.left and treemap.right):
-                return [treemap.data.size]
-            res = [treemap.data.size] + getItems(treemap.left) + \
-                    getItems(treemap.right)
-            return res
-
-        self.btree.addNodes(self.treemap)  
-        self.assertEqual([100.0, 60.0, 30.0, 10.0, 20.0, 30.0, 40.0, 20.0, 20.0], getItems(self.btree))
-
-        treemap = Treemap(title='Root')
-        treemap.append(self.treemap) 
-        btree = TreemapBTree(data=treemap)
-        btree.addNodes(treemap)  
-        self.assertEqual(1,len(btree.data))
-
-class TestTreemapControl(unittest.TestCase):
-    """ Class dedicated to test Treemap objects """
-    def setUp(self):
-        self.control = TreemapControl(None, None, Treemap(), StubSizeByPath())
-        self.treemap = createTreemap()
-
-    def test_setFieldColor(self):   
-        """ Method dedicated to test treemap attributes """
-        self.assertEqual([{'color': '#fde5be', 'type': 'Image', 'id': 'admin1', 'size': 10}, 
-                         {'color': '#4af6a0', 'type': 'File', 'id': 'admin2', 'size': 30}, 
-                         {'color': '#9c1b9c', 'type': 'File', 'id': 'admin3', 'size': 20},
-                         {'color': '#ad3333', 'type': 'Image', 'id': 'admin4', 'size': 50}],
-                         self.control.setFieldColor(StubSizeByPath.getTreemapInfo()))   
-
-    def test_sortItems(self):
-        """ Method dedicated to test fields """
-        self.assertEqual([{'type': 'Image', 'id': 'admin4', 'size': 50}, 
-                          {'type': 'File', 'id': 'admin2', 'size': 30}, 
-                          {'type': 'File', 'id': 'admin3', 'size': 20}, 
-                          {'type': 'Image', 'id': 'admin1', 'size': 10}],
-                          self.control.sortItems(StubSizeByPath.getTreemapInfo()))
-
-    def test_createRectangles(self):
-        """ Method dedicated to test treemap rectangles """
-        self.control.createRectangles(StubSizeByPath.getTreemapInfo())
-        self.assertEqual(self.treemap, self.control.treemap)
-
-    def test_setTreemapData(self):
-        self.control.setTreemapData()
-        self.assertEqual(self.treemap, self.control.treemap)
-        
-class TestTreemap(unittest.TestCase):
-    """ Class dedicated to test rectangles """
-    def setUp(self):
-        self.treemap = createTreemap()
-        self.btree = TreemapBTree(data=self.treemap)
-
-    def test_coordinates(self):
-        """ Method dedicated to test rectangle coordinates (set and get)  """
-        self.treemap.coordinates = (1,2,3,4)
-        self.assertEqual((1,2,3,4), self.treemap.coordinates)
-    
-    def test_addItem(self):
-        """ Method dedicated to test treemap object (adding into root treemap) """ 
-        self.treemap.addItem(Treemap(size=0.0, title = 'test'))
-        self.assertNotEqual('test', self.treemap[-1].title)
-
-        self.treemap.addItem(Treemap(size=1, title='test'))
-        self.assertEqual('test', self.treemap[-1].title)
-
-    def test_addItems(self):
-        """ Method dedicated to test treemap objects (adding into root treemap) """ 
-        self.treemap.addItems([Treemap(size=1, title='test1'), 
-                               Treemap(size=2, title='test2')])    
-        self.assertEqual('test2', self.treemap[-1].title)
-        self.assertEqual('test1', self.treemap[-2].title)
-
-    def test_setCoordinates(self):
-        """ Method dedicated to test recursive method """
-        nominal = [(0, 0, 100, 45.45), 
-                   (0, 45.45, 50.0, 54.54),
-                   (50.0, 45.45, 50.0, 36.36),
-                   (50.0, 81.81, 50.0, 18.18)] 
-
-        self.btree.addNodes(self.treemap)
-        self.treemap.setCoordinates(self.btree)
-        for x in getCoordinates(self.treemap, nominal):
-            self.assertAlmostEqual(x[0], x[1], 1) 
-
-class TestTreemapHtml(unittest.TestCase):
-    """ Class dedicated to test Treemap objects """
-    def setUp(self):
-        self.treemap = createTreemap(cls=TreemapHtml)
-        self.btree = TreemapBTree(data=self.treemap)
-        self.btree.addNodes(self.treemap)
-        self.treemap.setTreemapData(self.btree)
-
-    def test_getClasses(self):
-        """ Method dedicated to test html tag (<div>) """
-        self.treemap.setCoordinates(self.btree)
-        self.assertEqual('horizontal prop100',
-                         self.treemap.getClasses(self.btree))
-        self.assertEqual('', self.treemap.getClasses(self.btree.left))
-        self.assertEqual('vertical prop40', 
-                         self.treemap.getClasses(self.btree.right.right))
-
-    def test_writeHtml(self):
-        """ Method dedicated to test html tag (<div>) """
-        self.assertEqual("", self.treemap._writeHtml(self.btree.left)) 
-        self.assertEqual('<div class="" style="background-color:#4af6a0"></div>' + \
-                          '<div class="horizontal prop70" style="background-color:None">' + \
-                          '<div class="" style="background-color:#9c1b9c"></div>' + \
-                          '<div class="" style="background-color:#fde5be"></div></div>',
-                          self.treemap._writeHtml(self.btree.right)) 
-
-
-    def test_createTreemap(self):
-        """ Method dedicated to test html tag (treemap) """
-        self.assertEqual('<div class="horizontal prop50"><div class="" ' +\
-                         'style="background-color:#ad3333"></div>' +\
-                         '<div class="vertical prop50" style="background-color:None">' +\
-                         '<div class="" style="background-color:#4af6a0"></div>' +\
-                         '<div class="horizontal prop70" style="background-color:None">' +
-                         '<div class="" style="background-color:#9c1b9c"></div>' +\
-                         '<div class="" style="background-color:#fde5be"></div>' +\
-                         '</div></div></div>',
-                         self.treemap.createTreemap(self.btree))
-        
-    def test_setTreemapData(self):
-        """ Method dedicated to test coordinates """
-        nominal = [(None, None, 45.45, 100), 
-                   (None, None, 100, 50.0),
-                   (None, None, 66.66, 100),
-                   (None, None, 33.33, 100)] 
-
-        for x in getCoordinates(self.treemap, nominal):
-            if x[0] and x[1]:
-                self.assertAlmostEqual(x[0], x[1], 1) 
-
-class TestTreemapHtml(unittest.TestCase):
-    """ Class dedicated to test treemap image """
-    def setUp(self):
-        self.treemap = createTreemap(cls=TreemapImage)
-        self.btree = TreemapBTree(data=self.treemap)
-        self.btree.addNodes(self.treemap)
-        self.treemap.setCoordinates(self.btree)
-
-    def test_drawContainer(self):
-        treemap = self.treemap.drawContainer()
-        self.assertEqual(self.treemap.image.getbbox(), treemap.getbbox())
-        self.assertEqual(('R', 'G', 'B'), treemap.getbands())
-        self.assertEqual((249, 241, 241), treemap.getpixel((10,10)))
-    
-    def test_rgbHexToDecimal(self):
-        self.assertEqual((253, 229, 190),
-                          self.treemap.rgbHexToDecimal('#fde5be'))
-        
-    def test_getHlsPIL(self):
-        self.assertEqual('hsl(10,10%,20%)', 
-                          self.treemap.getHlsPIL(10,10,20))
-
-    def test_getFontSize(self):
-        self.assertEqual(15, self.treemap.getFontSize(self.treemap[0]))
-        self.assertEqual(81, self.treemap.getFontSize(Treemap(w=900,h=700)))
-
-    def test_createFont(self):
-        import PIL
-        font = self.treemap.createFont(15)
-        self.assertEqual(True, isinstance(font, PIL.ImageFont.FreeTypeFont))
-
-    def test_setMask(self):
-        rgb =  self.treemap.image.getpixel((10,10))
-
-        treemap = Treemap(w=1,h=1)
-        self.treemap.setMask(treemap)
-        self.assertEqual(rgb, self.treemap.image.getpixel((10,10)))
-
-        self.treemap.setMask(self.treemap)
-        self.assertNotEqual(rgb, self.treemap.setMask(self.treemap))
-       
-    def test_getPilColor(self):
-        self.assertEqual('hsl(37,144%,56%)', 
-                          self.treemap.getPilColor('#fde5be'))
-        
-    def checkImage(self):
-        return len([x for x in self.treemap.image.tostring().split('\xff') 
-                               if x != ''])
-
-    def test_writeText(self):
-        import ImageDraw
-        image = ImageDraw.Draw(self.treemap.image)
-        treemap = TreemapBTree(data=Treemap(w=50, h=50, x=0, y=0, 
-                                            color='#fde5be', title = 'test'))
-        self.treemap.writeText(treemap, image)
-        self.assertEqual(118, self.checkImage()) 
-    
-def test_suite():
-    test_suite = unittest.TestSuite([])
-    test_suite.addTest(makeSuite(TestTreemapControl))
-    test_suite.addTest(makeSuite(TestTreemapBTree))
-    test_suite.addTest(makeSuite(TestTreemap))
-    test_suite.addTest(makeSuite(TestTreemapHtml))
-    return test_suite
- 
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')
-
-#    suite = unittest.TestLoader().loadTestsFromTestCase(TestTreemapControl)
-#    unittest.TextTestRunner(verbosity=2).run(suite)
Index: quintagroup.analytics/branches/treemap/quintagroup/analytics/tests.py
===================================================================
--- quintagroup.analytics/branches/treemap/quintagroup/analytics/tests.py	(revision 3374)
+++ 	(revision )
@@ -1,482 +1,0 @@
-import unittest
-import transaction
-
-from AccessControl.SecurityManagement import newSecurityManager
-from Testing import ZopeTestCase as ztc
-from Products.Five import zcml
-from Products.Five import fiveconfigure
-from zope.component import testing, queryMultiAdapter, getUtility
-
-from Products.PloneTestCase import PloneTestCase as ptc
-from Products.PloneTestCase.version import PLONE40
-from Products.PloneTestCase import setup as ptc_setup
-from Products.PloneTestCase.layer import PloneSite
-from plone.portlets.interfaces import IPortletType
-
-import quintagroup.analytics
-
-ptc.setupPloneSite()
-
-class Installed(PloneSite):
-
-    @classmethod
-    def setUp(cls):
-        fiveconfigure.debug_mode = True
-        zcml.load_config('configure.zcml',
-                         quintagroup.analytics)
-        fiveconfigure.debug_mode = False
-        ztc.installPackage('quintagroup.analytics')
-        app = ztc.app()
-        portal = app[ptc_setup.portal_name]
-
-        # Sets the local site/manager
-        ptc_setup._placefulSetUp(portal)
-
-        qi = getattr(portal, 'portal_quickinstaller', None)
-        qi.installProduct('quintagroup.analytics')
-        transaction.commit()
-
-    @classmethod
-    def tearDown(cls):
-            pass
-
-class SetUpContent(Installed):
-
-    max = 10
-    types_ = ['Document', 'Event', 'Folder']
-    users = [('user%s'%i, 'user%s'%i, 'Member', None)
-             for i in xrange(max)]
-
-    @classmethod
-    def setupUsers(cls, portal):
-        """ Creates users."""
-        acl_users = portal.acl_users
-        mp = portal.portal_membership
-        map(acl_users._doAddUser, *zip(*cls.users))
-        if not mp.memberareaCreationFlag:
-            mp.setMemberareaCreationFlag()
-        map(mp.createMemberArea, [u[0] for u in cls.users])
-
-    @classmethod
-    def setupContent(cls, portal):
-        """ Creates test content."""
-        uf = portal.acl_users
-        pm = portal.portal_membership
-        pc = portal.portal_catalog
-        users = [u[0] for u in cls.users]
-        for u in users:
-            folder = pm.getHomeFolder(u)
-            user = uf.getUserById(u)
-            if not hasattr(user, 'aq_base'):
-                user = user.__of__(uf)
-            newSecurityManager(None, user)
-            for i in xrange(users.index(u)+cls.max):
-                map(folder.invokeFactory, cls.types_, [t+str(i) for t in cls.types_])
-        transaction.commit()
-
-
-    @classmethod
-    def setUp(cls):
-        app = ztc.app()
-        portal = app[ptc_setup.portal_name]
-        cls.setupUsers(portal)
-        cls.setupContent(portal)
-
-    @classmethod
-    def tearDown(cls):
-        pass
-
-class TestCase(ptc.PloneTestCase):
-    layer = Installed
-
-
-class TestQAInstallation(TestCase):
-    """ This class veryfies registrations of all needed views and
-        actions.
-    """
-
-    def test_cp_action_installation(self):
-        """This test validates control panel action. """
-        control_panel = self.portal.portal_controlpanel
-        self.assert_('QAnalytics' in [a.id for a in control_panel.listActions()],
-                     "Configlet for quintagroup.analitycs isn't registered.")
-
-    def test_OwnershipByType(self):
-        """ This test validates registration of
-            ownership_by_type view.
-        """
-        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
-                                 name="ownership_by_type")
-
-        self.assert_(view, "Ownership by type view isn't registered")
-
-    def test_OwnershipByState(self):
-        """ This test validates registration of
-            ownership_by_state view.
-        """
-        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
-                                 name="ownership_by_state")
-
-        self.assert_(view, "Ownership by state view isn't registered")
-
-    def test_TypeByState(self):
-        """ This test validates registration of
-            type_by_state view.
-        """
-        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
-                                 name="type_by_state")
-
-        self.assert_(view, "Type by state view isn't registered")
-
-    def test_LegacyPortlets(self):
-        """ This test validates registration of
-            legacy_portlets view.
-        """
-        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
-                                 name="legacy_portlets")
-
-        self.assert_(view, "Legacy Portlets view isn't registered")
-
-    def test_PropertiesStats(self):
-        """ This test validates registration of
-            properties_stats view.
-        """
-        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
-                                 name="properties_stats")
-
-        self.assert_(view, "Properties Stats view isn't registered")
-
-
-    def test_PortletsStats(self):
-        """ This test validates registration of
-            portlets_stats view.
-        """
-        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
-                                 name="portlets_stats")
-
-        self.assert_(view, "Portlets Stats view isn't registered")
-
-class TestOwnershipByType(TestCase):
-    """Tests all ownership by type view methods."""
-
-    layer = SetUpContent
-
-    def afterSetUp(self):
-        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST),
-                                 name="ownership_by_type")
-        self.pc = self.portal.portal_catalog
-
-    def test_getUsers(self):
-        """ Tests method that returns ordered list of users."""
-        users = [u[0] for u in self.layer.users]
-        users.reverse()
-        self.assert_(False not in map(lambda u1, u2:u1==u2,
-                     users, self.view.getUsers()))
-
-    def test_getTypes(self):
-        """ Tests method that returns ordered list of types."""
-        data = {}
-        index = self.pc._catalog.getIndex('portal_type')
-        for k in index._index.keys():
-            if not k:
-                continue
-            haslen = hasattr(index._index[k], '__len__')
-            if haslen:
-                data[k] = len(index._index[k])
-            else:
-                data[k] = 1
-        data = data.items()
-        data.sort(lambda a, b: a[1] - b[1])
-        data.reverse()
-        types = [i[0] for i in data]
-        self.assert_(False not in map(lambda t1, t2:t1==t2,
-                     self.view.getTypes(), types))
-
-    def test_getContent(self):
-        """ This test verifies method that returns list of numbers.
-            Each number is amount of specified content type objects
-            that owned  by particular user.
-        """
-        # we need to login in to the site as Manager to be able to
-        # see catalog results
-        self.loginAsPortalOwner()
-
-        for type_ in self.layer.types_:
-            self.assert_(False not in \
-            map(lambda i, j:i==j, [len(self.pc(portal_type=type_, Creator=user))
-                                   for user in self.view.getUsers()],
-                                  self.view.getContent(type_)))
-
-    def test_getChart(self):
-        """ This test verifies creation of chart image tag."""
-        plone33chart_tag = \
-          """<imgsrc="http://chart.apis.google.com/chart?chxt=y&amp;chds=0,
-             57&amp;chd=t:19.0,18.0,17.0,16.0,15.0,14.0,13.0,12.0,11.0,
-             10.0|19.0,18.0,17.0,16.0,15.0,14.0,13.0,12.0,11.0,10.0|
-             19.0,18.0,17.0,16.0,15.0,14.0,13.0,12.0,11.0,10.0|0.0,
-             0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0|0.0,0.0,0.0,0.0,
-             0.0,0.0,0.0,0.0,0.0,0.0&amp;chxr=0,0,57&amp;chco=669933,cc9966,
-             993300,ff6633,e8e4e3,a9a486,dcb57e,ffcc99,996633,333300,00ff00&amp;
-             chl=user9|user8|user7|user6|user5|user4|user3|user2|user1|
-             user0&amp;chbh=a,10,0&amp;chs=800x375&amp;cht=bvs&amp;
-             chtt=Content+ownership+by+type&amp;chdl=Folder|Document|Event
-             |Large+Plone+Folder|Topic&amp;chdlp=b"/>"""
-        plone4chart_tag = \
-          """<img src="http://chart.apis.google.com/chart?chxt=y&amp;
-             chds=0,57&amp;chd=t:19.0,18.0,17.0,16.0,15.0,14.0,
-             13.0,12.0,11.0,10.0|19.0,18.0,17.0,16.0,15.0,14.0,13.0,
-             12.0,11.0,10.0|19.0,18.0,17.0,16.0,15.0,14.0,13.0,12.0,
-             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;
-             chxr=0,0,57&amp;chco=669933,cc9966,993300,ff6633,e8e4e3,
-             a9a486,dcb57e,ffcc99,996633,333300,00ff00&amp;chl=user9|
-             user8|user7|user6|user5|user4|user3|user2|user1|user0&amp;
-             chbh=a,10,0&amp;chs=800x375&amp;cht=bvs&amp;
-             chtt=Content+ownership+by+type&amp;chdl=Folder|Document|
-             Event|Topic&amp;chdlp=b" />"""
-        chart_tag = plone4chart_tag
-        if not PLONE40:
-            chart_tag = plone33chart_tag
-
-        self.loginAsPortalOwner()
-        self.assertEqual(*map(lambda s:''.join(s.split()),
-                              [chart_tag, self.view.getChart()]))
-
-class TestOwnershipByState(TestCase):
-    """Tests all ownership by state view methods."""
-
-    layer = SetUpContent
-
-    states = ['private', 'published', 'pending']
-
-    def afterSetUp(self):
-        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST),
-                                 name="ownership_by_state")
-        self.pc = self.portal.portal_catalog
-
-    def test_getUsers(self):
-        """ Tests method that returns ordered list of users."""
-        users = [u[0] for u in self.layer.users]
-        users.reverse()
-        self.assert_(False not in map(lambda u1, u2:u1==u2,
-                     users, self.view.getUsers()))
-
-    def test_getStates(self):
-        """ Tests method that returns ordered list of states."""
-        self.assert_(False not in map(lambda s1, s2:s1==s2,
-                     ['private', 'published'], self.view.getStates()))
-
-    def test_getContent(self):
-        """ This test verifies method that returns list of numbers.
-            Each number is amount of specified content type objects
-            that are in particular workflow state.
-        """
-        # we need to login in to the site as Manager to be able to
-        # see catalog results
-        self.loginAsPortalOwner()
-
-        for state in self.states:
-            self.assert_(False not in \
-            map(lambda i, j:i==j,[len(self.pc(review_state=state, Creator=user))
-                                  for user in self.view.getUsers()],
-                                 self.view.getContent(state)))
-
-    def test_getChart(self):
-        """ This test verifies creation of chart image tag."""
-        chart_tag = """<imgsrc="http://chart.apis.google.com/chart?chxt=y&amp;
-                       chds=0,57&amp;chd=t:57.0,54.0,51.0,48.0,45.0,42.0,39.0,
-                       36.0,33.0,30.0|0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
-                       0.0|0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0&amp;chxr=0,
-                       0,57&amp;chco=669933,cc9966,993300,ff6633,e8e4e3,a9a486,
-                       dcb57e,ffcc99,996633,333300,00ff00&amp;chl=user9|user8|
-                       user7|user6|user5|user4|user3|user2|user1|user0&amp;
-                       chbh=a,10,0&amp;chs=800x375&amp;cht=bvs&amp;
-                       chtt=Content+ownership+by+state&amp;chdl=private|
-                       published|No+workflow&amp;chdlp=b"/>"""
-        self.loginAsPortalOwner()
-        self.assertEqual(*map(lambda s:''.join(s.split()),
-                              [chart_tag, self.view.getChart()]))
-
-class TestTypeByState(TestCase):
-    """Tests all type_by_state view methods."""
-    layer = SetUpContent
-    states = ['private', 'published', 'pending']
-
-    def afterSetUp(self):
-        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST),
-                                 name="type_by_state")
-        self.pc = self.portal.portal_catalog
-
-    def test_getTypes(self):
-        """ Tests method that returns ordered list of types."""
-        index = self.pc._catalog.getIndex('portal_type')
-        data = {}
-        for k in index._index.keys():
-            if not k:
-                continue
-            haslen = hasattr(index._index[k], '__len__')
-            if haslen:
-                data[k] = len(index._index[k])
-            else:
-                data[k] = 1
-        data = data.items()
-        data.sort(lambda a, b: a[1] - b[1])
-        data.reverse()
-        types = [i[0] for i in data]
-        self.assert_(False not in map(lambda t1, t2:t1==t2, types,
-                                      self.view.getTypes()))
-
-    def test_getStates(self):
-        """ Tests method that returns ordered list of states."""
-        self.assert_(False not in map(lambda s1, s2:s1==s2,
-                     ['private', 'published'], self.view.getStates()))
-
-    def test_getContent(self):
-        """ This test verifies method that returns list of numbers.
-            Each number is amount of specified content type objects
-            that owned  by particular user.
-        """
-        # we need to login in to the site as Manager to be able to
-        # see catalog results
-        self.loginAsPortalOwner()
-
-        for state in self.states:
-            self.assert_(False not in \
-            map(lambda i, j:i==j, [len(self.pc(portal_type=type_,
-                                               review_state=state))
-                                   for type_ in self.view.getTypes()],
-                                  self.view.getContent(state)))
-
-    def test_getChart(self):
-        """ This test verifies creation of chart image tag."""
-        plone33chart_tag = \
-          """<imgsrc="http://chart.apis.google.com/chart?chxt=y&amp;chds=0,
-             156&amp;chd=t:156.0,145.0,145.0,0.0,0.0|0.0,1.0,0.0,3.0,3.0|
-             0.0,0.0,0.0,0.0,0.0&amp;chxr=0,0,156&amp;chco=669933,cc9966,
-             993300,ff6633,e8e4e3,a9a486,dcb57e,ffcc99,996633,333300,
-             00ff00&amp;chl=Folder|Document|Event|Large+Plone+Folder|
-             Topic&amp;chbh=a,10,0&amp;chs=800x375&amp;cht=bvs&amp;
-             chtt=Content+type+by+state&amp;chdl=private|published|
-             No+workflow&amp;chdlp=b"/>"""
-        plone4chart_tag = \
-          """<imgsrc="http://chart.apis.google.com/chart?chxt=y&amp;
-             chds=0,159&amp;chd=t:156.0,145.0,145.0,0.0|3.0,1.0,0.0,
-             3.0|0.0,0.0,0.0,0.0&amp;chxr=0,0,159&amp;chco=669933,
-             cc9966,993300,ff6633,e8e4e3,a9a486,dcb57e,ffcc99,996633,
-             333300,00ff00&amp;chl=Folder|Document|Event|Topic&amp;
-             chbh=a,10,0&amp;chs=800x375&amp;cht=bvs&amp;
-             chtt=Content+type+by+state&amp;chdl=private|published|
-             No+workflow&amp;chdlp=b"/>"""
-
-        chart_tag = plone4chart_tag
-        if not PLONE40:
-            chart_tag = plone33chart_tag
-
-        self.loginAsPortalOwner()
-        self.assertEqual(*map(lambda s:''.join(s.split()),
-                              [chart_tag, self.view.getChart()]))
-
-class LegacyPortlets(TestCase):
-    """Test all legasy_portlets view methods."""
-
-
-    def afterSetUp(self):
-        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST),
-                                       name='legacy_portlets')
-
-    def test_getPortlets(self):
-        """Tests method that returns portlets info."""
-
-        # this is true for Plone 4
-        self.assert_(self.view.getPortlets() == [])
-
-    def test_getAllPortletExpressions(self):
-        """Tests method that returns portlets expressions."""
-
-        # this is true for Plone 4
-        self.assert_(self.view.getAllPortletExpressions() == [])
-
-class TestPropertiesStats(TestCase):
-    """Tests all properties_stats view methods."""
-
-    def afterSetUp(self):
-        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST),
-                                       name='properties_stats')
-
-    def test_getPropsList(self):
-        self.view.propname = 'title'
-        result = [u'Plone site', u'Welcome to Plone',
-                  u'News', u'Events', u'Users']
-
-        for title in result:
-            self.assert_(title in [prop_info['slots']
-                     for prop_info in self.view.getPropsList()])
-
-
-class TestPortletsStats(TestCase):
-    """Tests all properties_stats view methods."""
-
-    def afterSetUp(self):
-        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST),
-                                       name='portlets_stats')
-
-    def test_getPropsList(self):
-        """Tests method that collects portlet information from site."""
-
-        self.loginAsPortalOwner()
-        portlet = getUtility(IPortletType, name='portlets.Calendar')
-        mapping = \
-          self.portal.restrictedTraverse('++contextportlets++plone.leftcolumn')
-        mapping.restrictedTraverse('+/' + portlet.addview)()
-
-        plone_portlets_info = filter(lambda info:info['path'] == '/plone',
-                                     self.view.getPropsList())
-        lslots = plone_portlets_info[0]['left_slots']
-        self.assert_(filter(lambda info: info['title'] == 'Calendar', lslots))
-
-
-def test_suite():
-    from unittest import TestSuite, makeSuite
-    from quintagroup.analytics.test_treemap import \
-                                      TestTreemapControl,\
-                                      TestTreemapBTree,\
-                                      TestTreemap,\
-                                      TestTreemapHtml
-
-    test_suite = unittest.TestSuite([
-
-        # Unit tests
-        #doctestunit.DocFileSuite(
-        #    'README.txt', package='quintagroup.contentstats',
-        #    setUp=testing.setUp, tearDown=testing.tearDown),
-
-        #doctestunit.DocTestSuite(
-        #    module='quintagroup.contentstats.mymodule',
-        #    setUp=testing.setUp, tearDown=testing.tearDown),
-
-
-        # Integration tests that use PloneTestCase
-        #ztc.ZopeDocFileSuite(
-        #    'README.txt', package='quintagroup.contentstats',
-        #    test_class=TestCase),
-
-        #ztc.FunctionalDocFileSuite(
-        #    'browser.txt', package='quintagroup.contentstats',
-        #    test_class=TestCase),
-
-        ])
-    test_suite.addTest(makeSuite(TestTreemapControl))
-    test_suite.addTest(makeSuite(TestTreemapBTree))
-    test_suite.addTest(makeSuite(TestTreemap))
-    test_suite.addTest(makeSuite(TestTreemapHtml))
-
-    test_suite.addTest(makeSuite(TestQAInstallation))
-    test_suite.addTest(makeSuite(TestOwnershipByType))
-    test_suite.addTest(makeSuite(TestOwnershipByState))
-    test_suite.addTest(makeSuite(TestTypeByState))
-    test_suite.addTest(makeSuite(LegacyPortlets))
-    test_suite.addTest(makeSuite(TestPropertiesStats))
-    test_suite.addTest(makeSuite(TestPortletsStats))
-    return test_suite
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')
Index: quintagroup.analytics/branches/treemap/quintagroup/analytics/tests/test_treemap.py
===================================================================
--- quintagroup.analytics/branches/treemap/quintagroup/analytics/tests/test_treemap.py	(revision 3404)
+++ quintagroup.analytics/branches/treemap/quintagroup/analytics/tests/test_treemap.py	(revision 3404)
@@ -0,0 +1,311 @@
+import unittest
+from unittest import TestSuite, makeSuite, TestCase
+from itertools import izip
+from PIL import ImageDraw
+
+from quintagroup.analytics.browser.treemap import TreemapBTree, Treemap, \
+                                                  TreemapControl, \
+                                                  TreemapHtml, \
+                                                  TreemapImage
+
+#class TestQRectangle(unittest.TestCase):
+#    def setUp(self):
+#        self.rect = QRectangle(100,100,200,200,1000)
+#        self.rect.append(QRectangle(size=10))
+#        self.rect.append(QRectangle(size=20))
+#    
+#    def test_length(self):
+#        """ Testing lengths 'self' object """
+#        self.assertEqual(2, self.rect.length())
+#
+#    def test_coordinates(self):
+#        """ Testing setCoordinates() and getCoordinates """
+#        self.rect.setCoordinates((5,5,10,10))
+#        self.assertEqual((5,5,10,10), self.rect.getCoordinates())
+#
+#    def test_size(self):
+#        """ Testing getSize() and setSize() """
+#        self.rect.setSize(10)
+#        self.assertEqual(10.0, self.rect.getSize())
+#    
+#    def test_getWeight(self):
+#        """ Tests method that returns size of QRectangle objects"""
+#        self.assertEqual(30.0, self.rect.getWeight())
+#    
+#    def test_addItem(self):
+#        """ Tests method that add QRectangle object in QRectangle list """
+#        self.assertEqual(1, self.rect.addItem(QRectangle(size=10)))
+#        self.assertEqual(0, self.rect.addItem(QRectangle(size=0)))
+#
+#    def test_layout(self):
+#        """ Tests method that forms (x1, y1, x2, y2) for rectangles """
+#        self.rect.layout()
+#        isNumber = lambda x: abs(x - round(x, 1)) < 0.1
+#        self.assertEqual((True, True, True, True),
+#                             tuple(imap(isNumber, self.rect[0].getCoordinates())))
+#        self.assertEqual((True, True, True, True),
+#                             tuple(imap(isNumber, self.rect[1].getCoordinates())))
+
+
+def createTreemap(cls=Treemap):
+    """ Method dedicated to create tests instance """
+    treemap = cls(x=0, y=0, w=100,h=100)
+    treemap.addItems([Treemap(size=50, color='#ad3333', title='admin4'),
+                      Treemap(size=30, color='#4af6a0', title='admin2'),
+                      Treemap(size=20, color='#9c1b9c', title='admin3'),
+                      Treemap(size=10, color='#fde5be', title='admin1')])
+    return treemap
+
+def getCoordinates(treemap, nominal):
+     for i,x in enumerate(treemap):
+          for coord in zip(x.coordinates, nominal[i]):
+              yield coord
+    
+
+class StubSizeByPath:
+    @staticmethod
+    def getTreemapInfo():
+        return [{'size': 10, 'id': 'admin1', 'type': 'Image'},
+                {'size': 30, 'id': 'admin2', 'type': 'File'},
+                {'size': 20, 'id': 'admin3', 'type': 'File'},
+                {'size': 50, 'id': 'admin4', 'type': 'Image'}]
+    
+    
+class TestTreemapBTree(unittest.TestCase):
+    """ Class dedicated to test treemap binary tree """
+    def createTreemap(self):
+        """ Method dedicated to create tests instance """
+        treemap = Treemap(size=100)
+        for x in [10, 20, 30,40]: 
+            treemap.append(Treemap(size=x))
+        treemap[3].addItems([Treemap(size=20), Treemap(size=20)])
+        return treemap
+
+    def setUp(self):
+        self.treemap = self.createTreemap()
+        self.btree = TreemapBTree(data=self.treemap)
+
+    def test_getWeight(self):
+        """ Tests method that returns size of objects """
+        self.assertEqual(100, self.btree.getWeight(self.treemap))
+
+    def test_getHalfSize(self):
+        """ Tests method that returns half size of objects"""
+        self.assertEqual(3, self.btree.getHalfSize(self.treemap))
+    
+    def test_addNodes(self):
+        """ Tests method adds treemap objects into TreemapBTree """
+        def getItems(treemap):
+            if not(treemap.left and treemap.right):
+                return [treemap.data.size]
+            res = [treemap.data.size] + getItems(treemap.left) + \
+                    getItems(treemap.right)
+            return res
+
+        self.btree.addNodes(self.treemap)  
+        self.assertEqual([100.0, 60.0, 30.0, 10.0, 20.0, 30.0, 40.0, 20.0, 20.0], getItems(self.btree))
+
+        treemap = Treemap(title='Root')
+        treemap.append(self.treemap) 
+        btree = TreemapBTree(data=treemap)
+        btree.addNodes(treemap)  
+        self.assertEqual(1,len(btree.data))
+
+class TestTreemapControl(unittest.TestCase):
+    """ Class dedicated to test Treemap objects """
+    def setUp(self):
+        self.control = TreemapControl(None, None, Treemap(), StubSizeByPath())
+        self.treemap = createTreemap()
+
+    def test_setFieldColor(self):   
+        """ Method dedicated to test treemap attributes """
+        self.assertEqual([{'color': '#fde5be', 'type': 'Image', 'id': 'admin1', 'size': 10}, 
+                         {'color': '#4af6a0', 'type': 'File', 'id': 'admin2', 'size': 30}, 
+                         {'color': '#9c1b9c', 'type': 'File', 'id': 'admin3', 'size': 20},
+                         {'color': '#ad3333', 'type': 'Image', 'id': 'admin4', 'size': 50}],
+                         self.control.setFieldColor(StubSizeByPath.getTreemapInfo()))   
+
+    def test_sortItems(self):
+        """ Method dedicated to test fields """
+        self.assertEqual([{'type': 'Image', 'id': 'admin4', 'size': 50}, 
+                          {'type': 'File', 'id': 'admin2', 'size': 30}, 
+                          {'type': 'File', 'id': 'admin3', 'size': 20}, 
+                          {'type': 'Image', 'id': 'admin1', 'size': 10}],
+                          self.control.sortItems(StubSizeByPath.getTreemapInfo()))
+
+    def test_createRectangles(self):
+        """ Method dedicated to test treemap rectangles """
+        self.control.createRectangles(StubSizeByPath.getTreemapInfo())
+        self.assertEqual(self.treemap, self.control.treemap)
+
+    def test_setTreemapData(self):
+        self.control.setTreemapData()
+        self.assertEqual(self.treemap, self.control.treemap)
+        
+class TestTreemap(unittest.TestCase):
+    """ Class dedicated to test rectangles """
+    def setUp(self):
+        self.treemap = createTreemap()
+        self.btree = TreemapBTree(data=self.treemap)
+
+    def test_coordinates(self):
+        """ Method dedicated to test rectangle coordinates (set and get)  """
+        self.treemap.coordinates = (1,2,3,4)
+        self.assertEqual((1,2,3,4), self.treemap.coordinates)
+    
+    def test_addItem(self):
+        """ Method dedicated to test treemap object (adding into root treemap) """ 
+        self.treemap.addItem(Treemap(size=0.0, title = 'test'))
+        self.assertNotEqual('test', self.treemap[-1].title)
+
+        self.treemap.addItem(Treemap(size=1, title='test'))
+        self.assertEqual('test', self.treemap[-1].title)
+
+    def test_addItems(self):
+        """ Method dedicated to test treemap objects (adding into root treemap) """ 
+        self.treemap.addItems([Treemap(size=1, title='test1'), 
+                               Treemap(size=2, title='test2')])    
+        self.assertEqual('test2', self.treemap[-1].title)
+        self.assertEqual('test1', self.treemap[-2].title)
+
+    def test_setCoordinates(self):
+        """ Method dedicated to test recursive method """
+        nominal = [(0, 0, 100, 45.45), 
+                   (0, 45.45, 50.0, 54.54),
+                   (50.0, 45.45, 50.0, 36.36),
+                   (50.0, 81.81, 50.0, 18.18)] 
+
+        self.btree.addNodes(self.treemap)
+        self.treemap.setCoordinates(self.btree)
+        for x in getCoordinates(self.treemap, nominal):
+            self.assertAlmostEqual(x[0], x[1], 1) 
+
+class TestTreemapHtml(unittest.TestCase):
+    """ Class dedicated to test Treemap objects """
+    def setUp(self):
+        self.treemap = createTreemap(cls=TreemapHtml)
+        self.btree = TreemapBTree(data=self.treemap)
+        self.btree.addNodes(self.treemap)
+        self.treemap.setTreemapData(self.btree)
+
+    def test_getClasses(self):
+        """ Method dedicated to test html tag (<div>) """
+        self.treemap.setCoordinates(self.btree)
+        self.assertEqual('horizontal prop100',
+                         self.treemap.getClasses(self.btree))
+        self.assertEqual('', self.treemap.getClasses(self.btree.left))
+        self.assertEqual('vertical prop40', 
+                         self.treemap.getClasses(self.btree.right.right))
+
+    def test_writeHtml(self):
+        """ Method dedicated to test html tag (<div>) """
+        self.assertEqual("", self.treemap._writeHtml(self.btree.left)) 
+        self.assertEqual('<div class="" style="background-color:#4af6a0"></div>' + \
+                          '<div class="horizontal prop70" style="background-color:None">' + \
+                          '<div class="" style="background-color:#9c1b9c"></div>' + \
+                          '<div class="" style="background-color:#fde5be"></div></div>',
+                          self.treemap._writeHtml(self.btree.right)) 
+
+
+    def test_createTreemap(self):
+        """ Method dedicated to test html tag (treemap) """
+        self.assertEqual('<div class="horizontal prop50"><div class="" ' +\
+                         'style="background-color:#ad3333"></div>' +\
+                         '<div class="vertical prop50" style="background-color:None">' +\
+                         '<div class="" style="background-color:#4af6a0"></div>' +\
+                         '<div class="horizontal prop70" style="background-color:None">' +
+                         '<div class="" style="background-color:#9c1b9c"></div>' +\
+                         '<div class="" style="background-color:#fde5be"></div>' +\
+                         '</div></div></div>',
+                         self.treemap.createTreemap(self.btree))
+        
+    def test_setTreemapData(self):
+        """ Method dedicated to test coordinates """
+        nominal = [(None, None, 45.45, 100), 
+                   (None, None, 100, 50.0),
+                   (None, None, 66.66, 100),
+                   (None, None, 33.33, 100)] 
+
+        for x in getCoordinates(self.treemap, nominal):
+            if x[0] and x[1]:
+                self.assertAlmostEqual(x[0], x[1], 1) 
+
+class TestTreemapImage(unittest.TestCase):
+    """ Class dedicated to test treemap image """
+    def setUp(self):
+        self.treemap = createTreemap(cls=TreemapImage)
+        self.btree = TreemapBTree(data=self.treemap)
+        self.btree.addNodes(self.treemap)
+        self.treemap.setCoordinates(self.btree)
+
+    def test_drawContainer(self):
+        treemap = self.treemap.drawContainer()
+        self.assertEqual(self.treemap.image.getbbox(), treemap.getbbox())
+        self.assertEqual(('R', 'G', 'B'), treemap.getbands())
+    
+    def test_rgbHexToDecimal(self):
+        self.assertEqual((253, 229, 190),
+                          self.treemap.rgbHexToDecimal('#fde5be'))
+        
+    def test_getHlsPIL(self):
+        self.assertEqual('hsl(10,10%,20%)', 
+                          self.treemap.getHlsPIL(10,10,20))
+
+    def test_getFontSize(self):
+        self.assertEqual(15, self.treemap.getFontSize(self.treemap[0]))
+        self.assertEqual(81, self.treemap.getFontSize(Treemap(w=900,h=700)))
+
+    def test_createFont(self):
+        import PIL
+        font = self.treemap.createFont(15)
+        self.assertEqual(True, isinstance(font, PIL.ImageFont.FreeTypeFont))
+
+    def test_setMask(self):
+        rgb =  self.treemap.image.getpixel((10,10))
+
+        treemap = Treemap(w=1,h=1)
+        self.treemap.setMask(treemap)
+        self.assertEqual(rgb, self.treemap.image.getpixel((10,10)))
+
+        self.treemap.setMask(self.treemap)
+        self.assertNotEqual(rgb, self.treemap.setMask(self.treemap))
+       
+    def test_getPilColor(self):
+        self.assertEqual('hsl(37,144%,56%)', 
+                          self.treemap.getPilColor('#fde5be'))
+        
+#    def checkImage(self):
+#        return len([x for x in self.treemap.image.tostring().split('\xff') 
+#                               if x != ''])
+
+    def test_writeText(self):
+        def istitle(self, result, width, height):
+            treemap = TreemapBTree(data=Treemap(w=width, h=height, x=0, y=0, 
+                                                color='#fde5be', title = 'test'))
+            self.treemap.writeText(treemap, image)
+            self.assertEqual(result, self.treemap.writeText(treemap, image)) 
+ 
+        image = ImageDraw.Draw(self.treemap.image)
+
+        istitle(self, None, 10, 10)
+        istitle(self, True, 40, 40)
+
+    def test_drawTreemap(self):
+        image = ImageDraw.Draw(self.treemap.image)
+        self.assertEqual(None, self.treemap.drawTreemap(self.btree, image))
+    
+
+def test_suite():
+    test_suite = unittest.TestSuite([])
+    test_suite.addTest(makeSuite(TestTreemapControl))
+    test_suite.addTest(makeSuite(TestTreemapBTree))
+    test_suite.addTest(makeSuite(TestTreemap))
+    test_suite.addTest(makeSuite(TestTreemapHtml))
+    test_suite.addTest(makeSuite(TestTreemapImage))
+    return test_suite
+ 
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+
+#    suite = unittest.TestLoader().loadTestsFromTestCase(TestTreemapControl)
+#    unittest.TextTestRunner(verbosity=2).run(suite)
Index: quintagroup.analytics/branches/treemap/quintagroup/analytics/tests/tests.py
===================================================================
--- quintagroup.analytics/branches/treemap/quintagroup/analytics/tests/tests.py	(revision 3404)
+++ quintagroup.analytics/branches/treemap/quintagroup/analytics/tests/tests.py	(revision 3404)
@@ -0,0 +1,473 @@
+import unittest
+import transaction
+
+from AccessControl.SecurityManagement import newSecurityManager
+from Testing import ZopeTestCase as ztc
+from Products.Five import zcml
+from Products.Five import fiveconfigure
+from zope.component import testing, queryMultiAdapter, getUtility
+
+from Products.PloneTestCase import PloneTestCase as ptc
+from Products.PloneTestCase.version import PLONE40
+from Products.PloneTestCase import setup as ptc_setup
+from Products.PloneTestCase.layer import PloneSite
+from plone.portlets.interfaces import IPortletType
+
+import quintagroup.analytics
+
+ptc.setupPloneSite()
+
+class Installed(PloneSite):
+
+    @classmethod
+    def setUp(cls):
+        fiveconfigure.debug_mode = True
+        zcml.load_config('configure.zcml',
+                         quintagroup.analytics)
+        fiveconfigure.debug_mode = False
+        ztc.installPackage('quintagroup.analytics')
+        app = ztc.app()
+        portal = app[ptc_setup.portal_name]
+
+        # Sets the local site/manager
+        ptc_setup._placefulSetUp(portal)
+
+        qi = getattr(portal, 'portal_quickinstaller', None)
+        qi.installProduct('quintagroup.analytics')
+        transaction.commit()
+
+    @classmethod
+    def tearDown(cls):
+            pass
+
+class SetUpContent(Installed):
+
+    max = 10
+    types_ = ['Document', 'Event', 'Folder']
+    users = [('user%s'%i, 'user%s'%i, 'Member', None)
+             for i in xrange(max)]
+
+    @classmethod
+    def setupUsers(cls, portal):
+        """ Creates users."""
+        acl_users = portal.acl_users
+        mp = portal.portal_membership
+        map(acl_users._doAddUser, *zip(*cls.users))
+        if not mp.memberareaCreationFlag:
+            mp.setMemberareaCreationFlag()
+        map(mp.createMemberArea, [u[0] for u in cls.users])
+
+    @classmethod
+    def setupContent(cls, portal):
+        """ Creates test content."""
+        uf = portal.acl_users
+        pm = portal.portal_membership
+        pc = portal.portal_catalog
+        users = [u[0] for u in cls.users]
+        for u in users:
+            folder = pm.getHomeFolder(u)
+            user = uf.getUserById(u)
+            if not hasattr(user, 'aq_base'):
+                user = user.__of__(uf)
+            newSecurityManager(None, user)
+            for i in xrange(users.index(u)+cls.max):
+                map(folder.invokeFactory, cls.types_, [t+str(i) for t in cls.types_])
+        transaction.commit()
+
+
+    @classmethod
+    def setUp(cls):
+        app = ztc.app()
+        portal = app[ptc_setup.portal_name]
+        cls.setupUsers(portal)
+        cls.setupContent(portal)
+
+    @classmethod
+    def tearDown(cls):
+        pass
+
+class TestCase(ptc.PloneTestCase):
+    layer = Installed
+
+
+class TestQAInstallation(TestCase):
+    """ This class veryfies registrations of all needed views and
+        actions.
+    """
+
+    def test_cp_action_installation(self):
+        """This test validates control panel action. """
+        control_panel = self.portal.portal_controlpanel
+        self.assert_('QAnalytics' in [a.id for a in control_panel.listActions()],
+                     "Configlet for quintagroup.analitycs isn't registered.")
+
+    def test_OwnershipByType(self):
+        """ This test validates registration of
+            ownership_by_type view.
+        """
+        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
+                                 name="ownership_by_type")
+
+        self.assert_(view, "Ownership by type view isn't registered")
+
+    def test_OwnershipByState(self):
+        """ This test validates registration of
+            ownership_by_state view.
+        """
+        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
+                                 name="ownership_by_state")
+
+        self.assert_(view, "Ownership by state view isn't registered")
+
+    def test_TypeByState(self):
+        """ This test validates registration of
+            type_by_state view.
+        """
+        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
+                                 name="type_by_state")
+
+        self.assert_(view, "Type by state view isn't registered")
+
+    def test_LegacyPortlets(self):
+        """ This test validates registration of
+            legacy_portlets view.
+        """
+        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
+                                 name="legacy_portlets")
+
+        self.assert_(view, "Legacy Portlets view isn't registered")
+
+    def test_PropertiesStats(self):
+        """ This test validates registration of
+            properties_stats view.
+        """
+        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
+                                 name="properties_stats")
+
+        self.assert_(view, "Properties Stats view isn't registered")
+
+
+    def test_PortletsStats(self):
+        """ This test validates registration of
+            portlets_stats view.
+        """
+        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
+                                 name="portlets_stats")
+
+        self.assert_(view, "Portlets Stats view isn't registered")
+
+class TestOwnershipByType(TestCase):
+    """Tests all ownership by type view methods."""
+
+    layer = SetUpContent
+
+    def afterSetUp(self):
+        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST),
+                                 name="ownership_by_type")
+        self.pc = self.portal.portal_catalog
+
+    def test_getUsers(self):
+        """ Tests method that returns ordered list of users."""
+        users = [u[0] for u in self.layer.users]
+        users.reverse()
+        self.assert_(False not in map(lambda u1, u2:u1==u2,
+                     users, self.view.getUsers()))
+
+    def test_getTypes(self):
+        """ Tests method that returns ordered list of types."""
+        data = {}
+        index = self.pc._catalog.getIndex('portal_type')
+        for k in index._index.keys():
+            if not k:
+                continue
+            haslen = hasattr(index._index[k], '__len__')
+            if haslen:
+                data[k] = len(index._index[k])
+            else:
+                data[k] = 1
+        data = data.items()
+        data.sort(lambda a, b: a[1] - b[1])
+        data.reverse()
+        types = [i[0] for i in data]
+        self.assert_(False not in map(lambda t1, t2:t1==t2,
+                     self.view.getTypes(), types))
+
+    def test_getContent(self):
+        """ This test verifies method that returns list of numbers.
+            Each number is amount of specified content type objects
+            that owned  by particular user.
+        """
+        # we need to login in to the site as Manager to be able to
+        # see catalog results
+        self.loginAsPortalOwner()
+
+        for type_ in self.layer.types_:
+            self.assert_(False not in \
+            map(lambda i, j:i==j, [len(self.pc(portal_type=type_, Creator=user))
+                                   for user in self.view.getUsers()],
+                                  self.view.getContent(type_)))
+
+    def test_getChart(self):
+        """ This test verifies creation of chart image tag."""
+        plone33chart_tag = \
+          """<imgsrc="http://chart.apis.google.com/chart?chxt=y&amp;chds=0,
+             57&amp;chd=t:19.0,18.0,17.0,16.0,15.0,14.0,13.0,12.0,11.0,
+             10.0|19.0,18.0,17.0,16.0,15.0,14.0,13.0,12.0,11.0,10.0|
+             19.0,18.0,17.0,16.0,15.0,14.0,13.0,12.0,11.0,10.0|0.0,
+             0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0|0.0,0.0,0.0,0.0,
+             0.0,0.0,0.0,0.0,0.0,0.0&amp;chxr=0,0,57&amp;chco=669933,cc9966,
+             993300,ff6633,e8e4e3,a9a486,dcb57e,ffcc99,996633,333300,00ff00&amp;
+             chl=user9|user8|user7|user6|user5|user4|user3|user2|user1|
+             user0&amp;chbh=a,10,0&amp;chs=800x375&amp;cht=bvs&amp;
+             chtt=Content+ownership+by+type&amp;chdl=Folder|Document|Event
+             |Large+Plone+Folder|Topic&amp;chdlp=b"/>"""
+        plone4chart_tag = \
+          """<img src="http://chart.apis.google.com/chart?chxt=y&amp;
+             chds=0,57&amp;chd=t:19.0,18.0,17.0,16.0,15.0,14.0,
+             13.0,12.0,11.0,10.0|19.0,18.0,17.0,16.0,15.0,14.0,13.0,
+             12.0,11.0,10.0|19.0,18.0,17.0,16.0,15.0,14.0,13.0,12.0,
+             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;
+             chxr=0,0,57&amp;chco=669933,cc9966,993300,ff6633,e8e4e3,
+             a9a486,dcb57e,ffcc99,996633,333300,00ff00&amp;chl=user9|
+             user8|user7|user6|user5|user4|user3|user2|user1|user0&amp;
+             chbh=a,10,0&amp;chs=800x375&amp;cht=bvs&amp;
+             chtt=Content+ownership+by+type&amp;chdl=Folder|Document|
+             Event|Topic&amp;chdlp=b" />"""
+        chart_tag = plone4chart_tag
+        if not PLONE40:
+            chart_tag = plone33chart_tag
+
+        self.loginAsPortalOwner()
+        self.assertEqual(*map(lambda s:''.join(s.split()),
+                              [chart_tag, self.view.getChart()]))
+
+class TestOwnershipByState(TestCase):
+    """Tests all ownership by state view methods."""
+
+    layer = SetUpContent
+
+    states = ['private', 'published', 'pending']
+
+    def afterSetUp(self):
+        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST),
+                                 name="ownership_by_state")
+        self.pc = self.portal.portal_catalog
+
+    def test_getUsers(self):
+        """ Tests method that returns ordered list of users."""
+        users = [u[0] for u in self.layer.users]
+        users.reverse()
+        self.assert_(False not in map(lambda u1, u2:u1==u2,
+                     users, self.view.getUsers()))
+
+    def test_getStates(self):
+        """ Tests method that returns ordered list of states."""
+        self.assert_(False not in map(lambda s1, s2:s1==s2,
+                     ['private', 'published'], self.view.getStates()))
+
+    def test_getContent(self):
+        """ This test verifies method that returns list of numbers.
+            Each number is amount of specified content type objects
+            that are in particular workflow state.
+        """
+        # we need to login in to the site as Manager to be able to
+        # see catalog results
+        self.loginAsPortalOwner()
+
+        for state in self.states:
+            self.assert_(False not in \
+            map(lambda i, j:i==j,[len(self.pc(review_state=state, Creator=user))
+                                  for user in self.view.getUsers()],
+                                 self.view.getContent(state)))
+
+    def test_getChart(self):
+        """ This test verifies creation of chart image tag."""
+        chart_tag = """<imgsrc="http://chart.apis.google.com/chart?chxt=y&amp;
+                       chds=0,57&amp;chd=t:57.0,54.0,51.0,48.0,45.0,42.0,39.0,
+                       36.0,33.0,30.0|0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
+                       0.0|0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0&amp;chxr=0,
+                       0,57&amp;chco=669933,cc9966,993300,ff6633,e8e4e3,a9a486,
+                       dcb57e,ffcc99,996633,333300,00ff00&amp;chl=user9|user8|
+                       user7|user6|user5|user4|user3|user2|user1|user0&amp;
+                       chbh=a,10,0&amp;chs=800x375&amp;cht=bvs&amp;
+                       chtt=Content+ownership+by+state&amp;chdl=private|
+                       published|No+workflow&amp;chdlp=b"/>"""
+        self.loginAsPortalOwner()
+        self.assertEqual(*map(lambda s:''.join(s.split()),
+                              [chart_tag, self.view.getChart()]))
+
+class TestTypeByState(TestCase):
+    """Tests all type_by_state view methods."""
+    layer = SetUpContent
+    states = ['private', 'published', 'pending']
+
+    def afterSetUp(self):
+        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST),
+                                 name="type_by_state")
+        self.pc = self.portal.portal_catalog
+
+    def test_getTypes(self):
+        """ Tests method that returns ordered list of types."""
+        index = self.pc._catalog.getIndex('portal_type')
+        data = {}
+        for k in index._index.keys():
+            if not k:
+                continue
+            haslen = hasattr(index._index[k], '__len__')
+            if haslen:
+                data[k] = len(index._index[k])
+            else:
+                data[k] = 1
+        data = data.items()
+        data.sort(lambda a, b: a[1] - b[1])
+        data.reverse()
+        types = [i[0] for i in data]
+        self.assert_(False not in map(lambda t1, t2:t1==t2, types,
+                                      self.view.getTypes()))
+
+    def test_getStates(self):
+        """ Tests method that returns ordered list of states."""
+        self.assert_(False not in map(lambda s1, s2:s1==s2,
+                     ['private', 'published'], self.view.getStates()))
+
+    def test_getContent(self):
+        """ This test verifies method that returns list of numbers.
+            Each number is amount of specified content type objects
+            that owned  by particular user.
+        """
+        # we need to login in to the site as Manager to be able to
+        # see catalog results
+        self.loginAsPortalOwner()
+
+        for state in self.states:
+            self.assert_(False not in \
+            map(lambda i, j:i==j, [len(self.pc(portal_type=type_,
+                                               review_state=state))
+                                   for type_ in self.view.getTypes()],
+                                  self.view.getContent(state)))
+
+    def test_getChart(self):
+        """ This test verifies creation of chart image tag."""
+        plone33chart_tag = \
+          """<imgsrc="http://chart.apis.google.com/chart?chxt=y&amp;chds=0,
+             156&amp;chd=t:156.0,145.0,145.0,0.0,0.0|0.0,1.0,0.0,3.0,3.0|
+             0.0,0.0,0.0,0.0,0.0&amp;chxr=0,0,156&amp;chco=669933,cc9966,
+             993300,ff6633,e8e4e3,a9a486,dcb57e,ffcc99,996633,333300,
+             00ff00&amp;chl=Folder|Document|Event|Large+Plone+Folder|
+             Topic&amp;chbh=a,10,0&amp;chs=800x375&amp;cht=bvs&amp;
+             chtt=Content+type+by+state&amp;chdl=private|published|
+             No+workflow&amp;chdlp=b"/>"""
+        plone4chart_tag = \
+          """<imgsrc="http://chart.apis.google.com/chart?chxt=y&amp;
+             chds=0,159&amp;chd=t:156.0,145.0,145.0,0.0|3.0,1.0,0.0,
+             3.0|0.0,0.0,0.0,0.0&amp;chxr=0,0,159&amp;chco=669933,
+             cc9966,993300,ff6633,e8e4e3,a9a486,dcb57e,ffcc99,996633,
+             333300,00ff00&amp;chl=Folder|Document|Event|Topic&amp;
+             chbh=a,10,0&amp;chs=800x375&amp;cht=bvs&amp;
+             chtt=Content+type+by+state&amp;chdl=private|published|
+             No+workflow&amp;chdlp=b"/>"""
+
+        chart_tag = plone4chart_tag
+        if not PLONE40:
+            chart_tag = plone33chart_tag
+
+        self.loginAsPortalOwner()
+        self.assertEqual(*map(lambda s:''.join(s.split()),
+                              [chart_tag, self.view.getChart()]))
+
+class LegacyPortlets(TestCase):
+    """Test all legasy_portlets view methods."""
+
+
+    def afterSetUp(self):
+        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST),
+                                       name='legacy_portlets')
+
+    def test_getPortlets(self):
+        """Tests method that returns portlets info."""
+
+        # this is true for Plone 4
+        self.assert_(self.view.getPortlets() == [])
+
+    def test_getAllPortletExpressions(self):
+        """Tests method that returns portlets expressions."""
+
+        # this is true for Plone 4
+        self.assert_(self.view.getAllPortletExpressions() == [])
+
+class TestPropertiesStats(TestCase):
+    """Tests all properties_stats view methods."""
+
+    def afterSetUp(self):
+        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST),
+                                       name='properties_stats')
+
+    def test_getPropsList(self):
+        self.view.propname = 'title'
+        result = [u'Plone site', u'Welcome to Plone',
+                  u'News', u'Events', u'Users']
+
+        for title in result:
+            self.assert_(title in [prop_info['slots']
+                     for prop_info in self.view.getPropsList()])
+
+
+class TestPortletsStats(TestCase):
+    """Tests all properties_stats view methods."""
+
+    def afterSetUp(self):
+        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST),
+                                       name='portlets_stats')
+
+    def test_getPropsList(self):
+        """Tests method that collects portlet information from site."""
+
+        self.loginAsPortalOwner()
+        portlet = getUtility(IPortletType, name='portlets.Calendar')
+        mapping = \
+          self.portal.restrictedTraverse('++contextportlets++plone.leftcolumn')
+        mapping.restrictedTraverse('+/' + portlet.addview)()
+
+        plone_portlets_info = filter(lambda info:info['path'] == '/plone',
+                                     self.view.getPropsList())
+        lslots = plone_portlets_info[0]['left_slots']
+        self.assert_(filter(lambda info: info['title'] == 'Calendar', lslots))
+
+
+def test_suite():
+    from unittest import TestSuite, makeSuite
+
+    test_suite = unittest.TestSuite([
+
+        # Unit tests
+        #doctestunit.DocFileSuite(
+        #    'README.txt', package='quintagroup.contentstats',
+        #    setUp=testing.setUp, tearDown=testing.tearDown),
+
+        #doctestunit.DocTestSuite(
+        #    module='quintagroup.contentstats.mymodule',
+        #    setUp=testing.setUp, tearDown=testing.tearDown),
+
+
+        # Integration tests that use PloneTestCase
+        #ztc.ZopeDocFileSuite(
+        #    'README.txt', package='quintagroup.contentstats',
+        #    test_class=TestCase),
+
+        #ztc.FunctionalDocFileSuite(
+        #    'browser.txt', package='quintagroup.contentstats',
+        #    test_class=TestCase),
+
+        ])
+   
+    test_suite.addTest(makeSuite(TestQAInstallation))
+    test_suite.addTest(makeSuite(TestOwnershipByType))
+    test_suite.addTest(makeSuite(TestOwnershipByState))
+    test_suite.addTest(makeSuite(TestTypeByState))
+    test_suite.addTest(makeSuite(LegacyPortlets))
+    test_suite.addTest(makeSuite(TestPropertiesStats))
+    test_suite.addTest(makeSuite(TestPortletsStats))
+    return test_suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
