source: products/quintagroup.analytics/trunk/quintagroup/analytics/tests.py @ 3004

Last change on this file since 3004 was 3004, checked in by fenix, 13 years ago

added tests for views registrations.

File size: 4.6 KB
Line 
1import unittest
2import transaction
3
4from zope.component import testing, queryMultiAdapter
5from Testing import ZopeTestCase as ztc
6
7from Products.Five import zcml
8from Products.Five import fiveconfigure
9from Products.PloneTestCase import PloneTestCase as ptc
10from Products.PloneTestCase import setup as ptc_setup
11from Products.PloneTestCase.layer import PloneSite
12import quintagroup.analytics
13ptc.setupPloneSite()
14
15class TestCase(ptc.PloneTestCase):
16    class layer(PloneSite):
17        @classmethod
18        def setUp(cls):
19            fiveconfigure.debug_mode = True
20            zcml.load_config('configure.zcml',
21                             quintagroup.analytics)
22            fiveconfigure.debug_mode = False
23            ztc.installPackage('quintagroup.analytics')
24            app = ztc.app()
25            portal = app[ptc_setup.portal_name]
26
27            # Sets the local site/manager
28            ptc_setup._placefulSetUp(portal)
29
30            qi = getattr(portal, 'portal_quickinstaller', None)
31            qi.installProduct('quintagroup.analytics')
32            transaction.commit()
33
34        @classmethod
35        def tearDown(cls):
36            pass
37
38
39#TO DO:=====================================================================
40#      add tests for every views methods;
41#      add doc tests to validate if all needed elements are present on page;
42
43
44
45class TestQAInstallation(TestCase):
46    """ This class veryfies registrations of all needed views and
47        actions.
48    """
49
50    def test_cp_action_installation(self):
51        """This test validates control panel action. """
52        control_panel = self.portal.portal_controlpanel
53        self.assert_('QAnalytics' in [a.id for a in control_panel.listActions()],
54                     "Configlet for quintagroup.analitycs isn't registered.")
55
56    def test_OwnershipByType(self):
57        """ This test validates registration of
58            ownership_by_type view.
59        """
60        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
61                                 name="ownership_by_type")
62
63        self.assert_(view, "Ownership by type view isn't registered")
64
65    def test_OwnershipByState(self):
66        """ This test validates registration of
67            ownership_by_state view.
68        """
69        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
70                                 name="ownership_by_state")
71
72        self.assert_(view, "Ownership by state view isn't registered")
73
74    def test_TypeByState(self):
75        """ This test validates registration of
76            type_by_state view.
77        """
78        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
79                                 name="type_by_state")
80
81        self.assert_(view, "Type by state view isn't registered")
82
83    def test_LegacyPortlets(self):
84        """ This test validates registration of
85            legacy_portlets view.
86        """
87        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
88                                 name="legacy_portlets")
89
90        self.assert_(view, "Legacy Portlets view isn't registered")
91
92    def test_PropertiesStats(self):
93        """ This test validates registration of
94            properties_stats view.
95        """
96        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
97                                 name="properties_stats")
98
99        self.assert_(view, "Properties Stats view isn't registered")
100
101
102    def test_PortletsStats(self):
103        """ This test validates registration of
104            portlets_stats view.
105        """
106        view = queryMultiAdapter((self.portal, self.portal.REQUEST),
107                                 name="portlets_stats")
108
109        self.assert_(view, "Portlets Stats view isn't registered")
110
111def test_suite():
112    from unittest import TestSuite, makeSuite
113
114    test_suite = unittest.TestSuite([
115
116        # Unit tests
117        #doctestunit.DocFileSuite(
118        #    'README.txt', package='quintagroup.contentstats',
119        #    setUp=testing.setUp, tearDown=testing.tearDown),
120
121        #doctestunit.DocTestSuite(
122        #    module='quintagroup.contentstats.mymodule',
123        #    setUp=testing.setUp, tearDown=testing.tearDown),
124
125
126        # Integration tests that use PloneTestCase
127        #ztc.ZopeDocFileSuite(
128        #    'README.txt', package='quintagroup.contentstats',
129        #    test_class=TestCase),
130
131        #ztc.FunctionalDocFileSuite(
132        #    'browser.txt', package='quintagroup.contentstats',
133        #    test_class=TestCase),
134
135        ])
136
137    test_suite.addTest(makeSuite(TestQAInstallation))
138    return test_suite
139
140if __name__ == '__main__':
141    unittest.main(defaultTest='test_suite')
Note: See TracBrowser for help on using the repository browser.