source: products/qPloneGoogleMaps/tags/0.1.0/tests/testMarker.py @ 1591

Last change on this file since 1591 was 1, checked in by myroslav, 15 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 6.6 KB
Line 
1
2""" This module contains class that tests Marker content type """
3
4import os, sys, string
5if __name__ == '__main__':
6    execfile(os.path.join(sys.path[0], 'framework.py'))
7
8from commonTestingStuff import *
9
10class TestMarker(PloneTestCase.FunctionalTestCase):
11    """ Test Marker content type"""
12
13    def afterSetUp(self):
14        """ AfterSetUp features """
15        self.loginAsPortalOwner()
16        self.folder.invokeFactory("Map", "test_map")
17        self.test_map = self.folder.test_map
18        self.test_map.update(location=FIELD_VALUE)
19        self.test_map.invokeFactory("Marker", id="test_marker", title="Test Marker", description="Test Marker Description")
20        self.test_marker = self.test_map.test_marker
21        self.test_marker.update(location=FIELD_VALUE)
22        self.fields = ['title' ,'description' ,'location' ,'color']
23        self.membership = getToolByName(self.portal, 'portal_membership', None)
24        self.membership.addMember('another_member', user_password , ['Member'], [])
25        maps_login(self, user_name)
26        self.auth = user_name + ':' + user_password
27
28    def testTypeInformation(self):
29        """ Test Marker factory type information """
30        type_info = getToolByName(self.portal, 'portal_types').getTypeInfo("Marker")
31        self.assertEqual(type_info.global_allow, True)
32        self.assertEqual(type_info.content_meta_type, "Marker")
33
34        ## actions
35        actions = [a.id for a in type_info._actions]
36        self.assertEqual(actions, ['view', 'edit', 'metadata', 'references', 'history', 'external_edit', 'local_roles'])
37
38    def testMarkerInvoking(self):
39        """ Test Marker creating """
40        test_marker = self.test_marker
41        self.assertEqual(test_marker.getId(), "test_marker")
42        self.assertEqual(test_marker.Title(), "Test Marker")
43        self.assertEqual(test_marker.Description(), "Test Marker Description")
44
45    def testUpdateMarkerForMember(self):
46        """ Test possibility to update Marker type for member with owner permissions """
47        maps_login(self, 'member')
48        object_id = self.test_map.invokeFactory('Marker', 'test')
49        object = getattr(self.test_map, object_id)
50        object.update(title='test title')
51        self.failUnless(object.Title() == 'test title', "Member can't update Map with owner permissions.")
52
53    def testAuthenticatedUserAddMarkerContentType(self):
54        """ Test possibility of adding Marker content type by authenticated user """
55        for user in ['member', 'manager']:
56            maps_login(self, user)
57            folder = self.folder
58            if user == 'manager':
59                folder = self.portal
60            try:
61                example_id = folder.invokeFactory('Marker', 'test_%s' % user)
62            except Unauthorized: self.fail("%s could not create Marker type" % user)
63            self.failUnless(example_id in folder.objectIds(), "%s failed to add Marker type to portal" % user)
64
65    def testAnonymAddMarkerContentType(self):
66        """Check impossibility of adding Marker content type by anonymous user """
67        maps_login(self, 'anonym')
68        self.assertRaises(Unauthorized, self.folder.invokeFactory, 'Marker', 'test_example')
69
70    def testAllFieldsPresence(self):
71        """ Test for all fields presence in Marker """
72        missing_fields = [f for f in self.fields if not self.test_marker.Schema().has_key(f)]
73        self.failIf(missing_fields, "Following object's fields are missed: %s" % str(missing_fields) )
74
75    def testFieldsAccessibilityView(self):
76        """ Test fields accessibility for viewing """
77        result = {'anonym':[], 'another_member':[], 'member':[], 'manager':[]}
78        for user in ['anonym', 'another_member', 'member', 'manager']:
79            maps_login(self, user)
80            for f in self.fields:
81                field = self.test_marker.getField(f)
82                if not field.checkPermission('view', self.test_marker):
83                    result[user].append(f)
84            self.failIf(result[user], "%s - can't view fields: %s" % (user, str(result[user])))
85
86    def testFieldsAllowedEditing(self):
87        """ Test fields accessibility for editing owner and manager """
88        result = {'anonym':[], 'another_member':[], 'member':[], 'manager':[]}
89        # Allowed editing
90        for user in ['member', 'manager']:
91            maps_login(self, user)
92            for f in self.fields:
93                field = self.test_marker.getField(f)
94                if not field.checkPermission('edit', self.test_marker):
95                    result[user].append(f)
96            self.failIf(result[user], "%s - can't edit fields: %s" % (user, str(result[user])))
97
98    def testFieldsDisallowedEditing(self):
99        """ Test fields accessibility for editing for member (not owner) and anonymous """
100        result = {'anonym':[], 'another_member':[], 'member':[], 'manager':[]}
101        # Disallowed editing
102        for user in ['anonym', 'another_member']:
103            maps_login(self, user)
104            for f in self.fields:
105                field = self.test_marker.getField(f)
106                if field.checkPermission('edit', self.test_marker):
107                    result[user].append(f)
108            self.failIf(result[user], "%s - can edit fields: %s" % (user, str(result[user])) )
109
110    def testGeoLocation(self):
111        """ Test geoLocation Markers' method """
112        maps_login(self, 'member')
113        self.failUnless(self.test_marker.geoLocation() == FIELD_VALUE,
114                        "geoLocation method return incorrect result")
115
116    def testGeneratedJavaScript(self):
117        """ Test generated javascript for marker_view template """
118        data = {'longlat'          : self.portal.portal_catalog(path=self.test_marker.absolute_url_path()),
119                'color'            : self.test_marker.getColor(),
120                'loc'              : self.test_marker.geoLocation(),
121                'controls'         : 'large',
122                'typeControls'     : True,
123                'overviewControls' : True,
124                'node'             : 'mapView',
125                'events'           : True,
126                'zoom'             : 6,
127                'auto'             : 'None'
128               }
129        path = '%s/maps_markers' % self.test_marker.absolute_url_path()
130        response = self.publish(path, self.auth, extra=data, request_method="POST")
131        self.failUnless(response.body == MARKER_VIEW_JAVASCRIPT,
132                        "Incorrect javascript tag returned by maps_markers script")
133
134def test_suite():
135    from unittest import TestSuite, makeSuite
136    suite = TestSuite()
137    suite.addTest(makeSuite(TestMarker))
138    return suite
139
140if __name__ == '__main__':
141    framework()
Note: See TracBrowser for help on using the repository browser.