1 | import unittest |
---|
2 | import transaction |
---|
3 | |
---|
4 | from AccessControl.SecurityManagement import newSecurityManager |
---|
5 | from zope.component import testing, queryMultiAdapter |
---|
6 | from Testing import ZopeTestCase as ztc |
---|
7 | |
---|
8 | from Products.Five import zcml |
---|
9 | from Products.Five import fiveconfigure |
---|
10 | from Products.PloneTestCase import PloneTestCase as ptc |
---|
11 | from Products.PloneTestCase import setup as ptc_setup |
---|
12 | from Products.PloneTestCase.layer import PloneSite |
---|
13 | import quintagroup.analytics |
---|
14 | ptc.setupPloneSite() |
---|
15 | |
---|
16 | class Installed(PloneSite): |
---|
17 | |
---|
18 | @classmethod |
---|
19 | def setUp(cls): |
---|
20 | fiveconfigure.debug_mode = True |
---|
21 | zcml.load_config('configure.zcml', |
---|
22 | quintagroup.analytics) |
---|
23 | fiveconfigure.debug_mode = False |
---|
24 | ztc.installPackage('quintagroup.analytics') |
---|
25 | app = ztc.app() |
---|
26 | portal = app[ptc_setup.portal_name] |
---|
27 | |
---|
28 | # Sets the local site/manager |
---|
29 | ptc_setup._placefulSetUp(portal) |
---|
30 | |
---|
31 | qi = getattr(portal, 'portal_quickinstaller', None) |
---|
32 | qi.installProduct('quintagroup.analytics') |
---|
33 | transaction.commit() |
---|
34 | |
---|
35 | @classmethod |
---|
36 | def tearDown(cls): |
---|
37 | pass |
---|
38 | |
---|
39 | class SetUpContent(Installed): |
---|
40 | |
---|
41 | max = 10 |
---|
42 | types_ = ['Document', 'Event', 'Folder'] |
---|
43 | users = [('user%s'%i, 'user%s'%i, 'Member', None) |
---|
44 | for i in xrange(max)] |
---|
45 | |
---|
46 | @classmethod |
---|
47 | def setupUsers(cls, portal): |
---|
48 | """ Creates users.""" |
---|
49 | acl_users = portal.acl_users |
---|
50 | mp = portal.portal_membership |
---|
51 | map(acl_users._doAddUser, *zip(*cls.users)) |
---|
52 | if not mp.memberareaCreationFlag: |
---|
53 | mp.setMemberareaCreationFlag() |
---|
54 | map(mp.createMemberArea, [u[0] for u in cls.users]) |
---|
55 | |
---|
56 | @classmethod |
---|
57 | def setupContent(cls, portal): |
---|
58 | """ Creates users""" |
---|
59 | uf = portal.acl_users |
---|
60 | pm = portal.portal_membership |
---|
61 | pc = portal.portal_catalog |
---|
62 | users = [u[0] for u in cls.users] |
---|
63 | for u in users: |
---|
64 | folder = pm.getHomeFolder(u) |
---|
65 | user = uf.getUserById(u) |
---|
66 | if not hasattr(user, 'aq_base'): |
---|
67 | user = user.__of__(uf) |
---|
68 | newSecurityManager(None, user) |
---|
69 | for i in xrange(users.index(u)+cls.max): |
---|
70 | map(folder.invokeFactory, cls.types_, [t+str(i) for t in cls.types_]) |
---|
71 | transaction.commit() |
---|
72 | |
---|
73 | |
---|
74 | @classmethod |
---|
75 | def setUp(cls): |
---|
76 | app = ztc.app() |
---|
77 | portal = app[ptc_setup.portal_name] |
---|
78 | cls.setupUsers(portal) |
---|
79 | cls.setupContent(portal) |
---|
80 | |
---|
81 | @classmethod |
---|
82 | def tearDown(cls): |
---|
83 | pass |
---|
84 | |
---|
85 | class TestCase(ptc.PloneTestCase): |
---|
86 | layer = Installed |
---|
87 | |
---|
88 | #TO DO:===================================================================== |
---|
89 | # add tests for every views methods; |
---|
90 | # add doc tests to validate if all needed elements are present on page; |
---|
91 | |
---|
92 | class TestQAInstallation(TestCase): |
---|
93 | """ This class veryfies registrations of all needed views and |
---|
94 | actions. |
---|
95 | """ |
---|
96 | |
---|
97 | def test_cp_action_installation(self): |
---|
98 | """This test validates control panel action. """ |
---|
99 | control_panel = self.portal.portal_controlpanel |
---|
100 | self.assert_('QAnalytics' in [a.id for a in control_panel.listActions()], |
---|
101 | "Configlet for quintagroup.analitycs isn't registered.") |
---|
102 | |
---|
103 | def test_OwnershipByType(self): |
---|
104 | """ This test validates registration of |
---|
105 | ownership_by_type view. |
---|
106 | """ |
---|
107 | view = queryMultiAdapter((self.portal, self.portal.REQUEST), |
---|
108 | name="ownership_by_type") |
---|
109 | |
---|
110 | self.assert_(view, "Ownership by type view isn't registered") |
---|
111 | |
---|
112 | def test_OwnershipByState(self): |
---|
113 | """ This test validates registration of |
---|
114 | ownership_by_state view. |
---|
115 | """ |
---|
116 | view = queryMultiAdapter((self.portal, self.portal.REQUEST), |
---|
117 | name="ownership_by_state") |
---|
118 | |
---|
119 | self.assert_(view, "Ownership by state view isn't registered") |
---|
120 | |
---|
121 | def test_TypeByState(self): |
---|
122 | """ This test validates registration of |
---|
123 | type_by_state view. |
---|
124 | """ |
---|
125 | view = queryMultiAdapter((self.portal, self.portal.REQUEST), |
---|
126 | name="type_by_state") |
---|
127 | |
---|
128 | self.assert_(view, "Type by state view isn't registered") |
---|
129 | |
---|
130 | def test_LegacyPortlets(self): |
---|
131 | """ This test validates registration of |
---|
132 | legacy_portlets view. |
---|
133 | """ |
---|
134 | view = queryMultiAdapter((self.portal, self.portal.REQUEST), |
---|
135 | name="legacy_portlets") |
---|
136 | |
---|
137 | self.assert_(view, "Legacy Portlets view isn't registered") |
---|
138 | |
---|
139 | def test_PropertiesStats(self): |
---|
140 | """ This test validates registration of |
---|
141 | properties_stats view. |
---|
142 | """ |
---|
143 | view = queryMultiAdapter((self.portal, self.portal.REQUEST), |
---|
144 | name="properties_stats") |
---|
145 | |
---|
146 | self.assert_(view, "Properties Stats view isn't registered") |
---|
147 | |
---|
148 | |
---|
149 | def test_PortletsStats(self): |
---|
150 | """ This test validates registration of |
---|
151 | portlets_stats view. |
---|
152 | """ |
---|
153 | view = queryMultiAdapter((self.portal, self.portal.REQUEST), |
---|
154 | name="portlets_stats") |
---|
155 | |
---|
156 | self.assert_(view, "Portlets Stats view isn't registered") |
---|
157 | |
---|
158 | class TestOwnershipByType(TestCase): |
---|
159 | """Tests all ownership by type view methods.""" |
---|
160 | |
---|
161 | layer = SetUpContent |
---|
162 | |
---|
163 | 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 | |
---|
172 | |
---|
173 | |
---|
174 | def test_suite(): |
---|
175 | from unittest import TestSuite, makeSuite |
---|
176 | |
---|
177 | test_suite = unittest.TestSuite([ |
---|
178 | |
---|
179 | # Unit tests |
---|
180 | #doctestunit.DocFileSuite( |
---|
181 | # 'README.txt', package='quintagroup.contentstats', |
---|
182 | # setUp=testing.setUp, tearDown=testing.tearDown), |
---|
183 | |
---|
184 | #doctestunit.DocTestSuite( |
---|
185 | # module='quintagroup.contentstats.mymodule', |
---|
186 | # setUp=testing.setUp, tearDown=testing.tearDown), |
---|
187 | |
---|
188 | |
---|
189 | # Integration tests that use PloneTestCase |
---|
190 | #ztc.ZopeDocFileSuite( |
---|
191 | # 'README.txt', package='quintagroup.contentstats', |
---|
192 | # test_class=TestCase), |
---|
193 | |
---|
194 | #ztc.FunctionalDocFileSuite( |
---|
195 | # 'browser.txt', package='quintagroup.contentstats', |
---|
196 | # test_class=TestCase), |
---|
197 | |
---|
198 | ]) |
---|
199 | |
---|
200 | test_suite.addTest(makeSuite(TestQAInstallation)) |
---|
201 | test_suite.addTest(makeSuite(TestOwnershipByType)) |
---|
202 | return test_suite |
---|
203 | |
---|
204 | if __name__ == '__main__': |
---|
205 | unittest.main(defaultTest='test_suite') |
---|