def test_ws_getItemInfosInTheNameOf(self):
     """
       Test that getting an item inTheNameOf antother user works
       Create an item by 'pmCreator1', member of the 'developers' group
       Item will be viewable :
       - by 'pmManager'
       - while getting informations in the name of 'pmCreator1'
       Item will NOT be viewable :
       - while getting informations in the name of 'pmCreator2'
         that is not in the 'developers' group
     """
     # create an item by 'pmCreator1'
     self.changeUser('pmCreator1')
     item = self.create('MeetingItem')
     # check first a working example the degrades it...
     req = getItemInfosRequest()
     req._inTheNameOf = None
     req._UID = item.UID()
     responseHolder = getItemInfosResponse()
     # 'pmCreator1' can get infos about the item
     result = SOAPView(self.portal,
                       req).getItemInfosRequest(req, responseHolder)
     self.assertTrue(result._itemInfo[0].UID == item.UID())
     # now begin, we need to be a 'MeetingManager' or 'Manager' to
     # getItemInfos(inTheNameOf)
     req._inTheNameOf = 'pmCreator1'
     cleanRamCacheFor('Products.PloneMeeting.ToolPloneMeeting.userIsAmong')
     with self.assertRaises(ZSI.Fault) as cm:
         SOAPView(self.portal, req).getItemInfosRequest(req, responseHolder)
     self.assertEqual(
         cm.exception.string,
         "You need to be 'Manager' or 'MeetingManager' to get item informations 'inTheNameOf'!"
     )
     # now has a 'MeetingManager'
     self.changeUser('pmManager')
     # a MeetingManager can get informations inTheNameOf 'pmCreator1'
     # and it will return relevant result as 'pmCreator1' can see the item
     cleanRamCacheFor('Products.PloneMeeting.ToolPloneMeeting.userIsAmong')
     result = SOAPView(self.portal,
                       req).getItemInfosRequest(req, responseHolder)
     self.assertTrue(result._itemInfo[0].UID == item.UID())
     # as we switch user while using inTheNameOf, make sure we have
     # falled back to original user
     self.assertTrue(self.portal.portal_membership.getAuthenticatedMember().
                     getId() == 'pmManager')
     # as 'pmCreator2', we can not get item informations
     req._inTheNameOf = 'pmCreator2'
     cleanRamCacheFor('Products.PloneMeeting.ToolPloneMeeting.userIsAmong')
     result = SOAPView(self.portal,
                       req).getItemInfosRequest(req, responseHolder)
     self.assertTrue(result._itemInfo == [])
     # now for an unexisting inTheNameOf userid
     req._inTheNameOf = 'unexistingUserId'
     cleanRamCacheFor('Products.PloneMeeting.ToolPloneMeeting.userIsAmong')
     with self.assertRaises(ZSI.Fault) as cm:
         SOAPView(self.portal, req).getItemInfosRequest(req, responseHolder)
     self.assertEqual(
         cm.exception.string,
         "Trying to get item informations 'inTheNameOf' an unexisting user 'unexistingUserId'!"
     )
예제 #2
0
    def _getItemInfos(self,
                      itemUID,
                      showAnnexes=False,
                      allowed_annexes_types=[],
                      include_annex_binary=True,
                      showAssembly=False,
                      showExtraInfos=False,
                      showTemplates=False,
                      showEmptyValues=True,
                      toBeDeserialized=True,
                      useSingleItemInfos=False):
        """
          Call getItemInfos SOAP method with given itemUID parameter
        """
        if useSingleItemInfos:
            req = getSingleItemInfosRequest()
        else:
            req = getItemInfosRequest()
        req._UID = itemUID
        if showAnnexes:
            req._showAnnexes = True
        if allowed_annexes_types:
            req._allowed_annexes_types = allowed_annexes_types
        if not include_annex_binary:
            req._include_annex_binary = False
        if showExtraInfos:
            req._showExtraInfos = True
        if showAssembly:
            req._showAssembly = True
        if showTemplates:
            req._showTemplates = True
        req._showEmptyValues = showEmptyValues

        if useSingleItemInfos:
            responseHolder = getSingleItemInfosResponse()
            response = SOAPView(self.portal, req).getSingleItemInfosRequest(
                req, responseHolder)
        else:
            responseHolder = getItemInfosResponse()
            response = SOAPView(self.portal,
                                req).getItemInfosRequest(req, responseHolder)

        if toBeDeserialized:
            return deserialize(response)
        else:
            return response
    def test_ws_getItemInfosRequest(self):
        """
          Test that getting an item with a given UID returns valuable informations
        """
        # by default no item exists
        self.changeUser('pmCreator1')
        self.failUnless(
            len(self.portal.portal_catalog(portal_type='MeetingItemPga')) == 0)
        # use the SOAP service to create one
        req = self._prepareCreationData()
        newItem, response = self._createItem(req)
        newItemUID = newItem.UID()
        # now an item exists, get informations about it
        req = getItemInfosRequest()
        req._UID = newItemUID
        # Serialize the request so it can be easily tested
        request = serializeRequest(req)
        # This is what the sent enveloppe should looks like
        expected = """<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" """ \
            """xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" """ \
            """xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" """ \
            """xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">""" \
            """<SOAP-ENV:Header></SOAP-ENV:Header>""" \
            """<SOAP-ENV:Body xmlns:ns1="http://ws4pm.imio.be"><ns1:getItemInfosRequest>""" \
            """<UID>%s</UID><showExtraInfos>false</showExtraInfos><showAnnexes>false</showAnnexes>""" \
            """<include_annex_binary>true</include_annex_binary>""" \
            """<showAssembly>false</showAssembly><showTemplates>false</showTemplates>""" \
            """<showEmptyValues>true</showEmptyValues></ns1:getItemInfosRequest>""" \
            """</SOAP-ENV:Body></SOAP-ENV:Envelope>""" % newItemUID
        result = """%s""" % request
        self.assertEqual(expected, result)
        # now really use the SOAP method to get informations about the item
        resp = self._getItemInfos(newItemUID)
        # the item is not in a meeting so the meeting date is 1950-01-01
        expected = """<ns1:getItemInfosResponse xmlns:ns1="http://ws4pm.imio.be" """ \
            """xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" """ \
            """xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" """ \
            """xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" """ \
            """xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <itemInfo xsi:type="ns1:ItemInfo">
    <UID>{0}</UID>
    <id>my-new-item-title</id>
    <title>My new item title</title>
    <creator>pmCreator1</creator>
    <creation_date>{1}</creation_date>
    <modification_date>{2}</modification_date>
    <category>development</category>
    <description>&lt;p&gt;Description&lt;/p&gt;</description>
    <detailedDescription>&lt;p&gt;Detailed description&lt;/p&gt;</detailedDescription>
    <decision>&lt;p&gt;Décision&lt;/p&gt;</decision>
    <preferredMeeting/>
    <preferred_meeting_date>1950-01-01T00:00:00.006Z</preferred_meeting_date>
    <review_state>itemcreated</review_state>
    <meeting_date>1950-01-01T00:00:00.006Z</meeting_date>
    <absolute_url>http://nohost/plone/Members/pmCreator1/mymeetings/plonegov-assembly/my-new-item-title</absolute_url>
    <externalIdentifier/>
    <extraInfos/>
  </itemInfo>
</ns1:getItemInfosResponse>
""".format(newItemUID,
                gDateTime.get_formatted_content(gDateTime(), localtime(newItem.created())),
                gDateTime.get_formatted_content(gDateTime(), localtime(newItem.modified())))
        self.assertEqual(expected, resp)
        # if the item is in a meeting, the result is a bit different because
        # we have valid informations about the meeting_date
        self.changeUser('pmManager')
        meeting = self._createMeetingWithItems()
        itemInMeeting = meeting.get_items(ordered=True)[0]
        # by default, PloneMeeting creates item without title/description/decision...
        itemInMeeting.setTitle('My new item title')
        itemInMeeting.setDescription('<p>Description</p>',
                                     mimetype='text/x-html-safe')
        itemInMeeting.setDecision('<p>Décision</p>',
                                  mimetype='text/x-html-safe')
        resp = self._getItemInfos(itemInMeeting.UID())
        meetingDate = gDateTime.get_formatted_content(
            gDateTime(), meeting.date.utctimetuple())
        expected = """<ns1:getItemInfosResponse xmlns:ns1="http://ws4pm.imio.be" """ \
            """xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" """ \
            """xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" """ \
            """xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" """ \
            """xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <itemInfo xsi:type="ns1:ItemInfo">
    <UID>{0}</UID>
    <id>item-2</id>
    <title>My new item title</title>
    <creator>pmManager</creator>
    <creation_date>{1}</creation_date>
    <modification_date>{2}</modification_date>
    <category>development</category>
    <description>&lt;p&gt;Description&lt;/p&gt;</description>
    <detailedDescription/>
    <decision>&lt;p&gt;Décision&lt;/p&gt;</decision>
    <preferredMeeting/>
    <preferred_meeting_date>1950-01-01T00:00:00.006Z</preferred_meeting_date>
    <review_state>presented</review_state>
    <meeting>{3}</meeting>
    <meeting_date>{4}</meeting_date>
    <absolute_url>http://nohost/plone/Members/pmManager/mymeetings/plonegov-assembly/item-2</absolute_url>
    <externalIdentifier/>
    <extraInfos/>
  </itemInfo>
</ns1:getItemInfosResponse>
""".format(itemInMeeting.UID(),
                gDateTime.get_formatted_content(gDateTime(), localtime(itemInMeeting.created())),
                gDateTime.get_formatted_content(gDateTime(), localtime(itemInMeeting.modified())),
                meeting.UID(),
                meetingDate)
        self.assertEqual(expected, resp)
        # if the item with this UID has not been found (user can not access or item does not exists),
        # an empty response is returned
        # unexisting item UID
        resp = self._getItemInfos('aWrongUID')
        expected = """<ns1:getItemInfosResponse xmlns:ns1="http://ws4pm.imio.be" """ \
            """xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" """ \
            """xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" """ \
            """xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" """ \
            """xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
"""
        self.assertEqual(expected, resp)
        # item UID the logged in user can not access
        self.changeUser('pmReviewer2')
        resp = self._getItemInfos(newItemUID)
        self.assertEqual(expected, resp)