def test_ws_createItemWithOneAnnexRequest(self): """ Test SOAP service behaviour when creating items with one annex """ # by default no item exists self.changeUser('pmCreator1') req = self._prepareCreationData() data = { 'title': 'My annex 1', 'filename': 'smallTestFile.pdf', 'file': 'smallTestFile.pdf' } req._creationData._annexes = [self._prepareAnnexInfo(**data)] annex = req._creationData._annexes[0] # Serialize the request so it can be easily tested request = serializeRequest(req) # This is what the sent enveloppe should looks like expected = """POST /plone/createItemRequest HTTP/1.0 Authorization: Basic %s:%s Content-Length: 102 Content-Type: text/xml SOAPAction: / <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:createItemRequest><meetingConfigId>plonegov-assembly</meetingConfigId>""" \ """<proposingGroupId>developers</proposingGroupId><creationData xsi:type="ns1:CreationData">""" \ """<title>My new item title</title><category>development</category>""" \ """<description><p>Description</p></description>""" \ """<detailedDescription><p>Detailed description</p></detailedDescription>""" \ """<decision><p>Décision</p></decision>""" \ """<annexes xsi:type="ns1:AnnexInfo"><title>%s</title><annexTypeId>%s</annexTypeId><filename>%s</filename><file> %s</file></annexes></creationData><cleanHtml>true</cleanHtml></ns1:createItemRequest>""" \ """</SOAP-ENV:Body></SOAP-ENV:Envelope>""" % ('pmCreator1', 'meeting', annex._title, annex._annexTypeId, annex._filename, base64.encodestring(annex._file)) result = """POST /plone/createItemRequest HTTP/1.0 Authorization: Basic %s:%s Content-Length: 102 Content-Type: text/xml SOAPAction: / %s""" % ('pmCreator1', 'meeting', request) self.assertEqual(expected, result) newItem, response = self._createItem(req) # now check the created item have the annex annexes = get_annexes(newItem) # the annex is actually created self.failUnless(len(annexes) == 1) # the annex mimetype is correct annex = annexes[0] self.failUnless(annex.file.contentType == 'application/pdf') # the annex metadata are ok self.assertEqual(annex.Title(), 'My annex 1') self.assertEqual( annex.content_category, 'plonegov-assembly-annexes_types_-_item_annexes_-_financial-analysis' )
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><p>Description</p></description> <detailedDescription><p>Detailed description</p></detailedDescription> <decision><p>Décision</p></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><p>Description</p></description> <detailedDescription/> <decision><p>Décision</p></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)
def test_ws_createItemRequest(self): """ In the default test configuration, the user 'pmCreator1' can create an item for proposingGroup 'developers' in the MeetingConfig 'plonegov-assembly' """ # by default no item exists self.changeUser('pmCreator1') self.failUnless(len(self.portal.portal_catalog(portal_type='MeetingItemPga')) == 0) req = self._prepareCreationData() # This is what the sent enveloppe should looks like, note that the decision is "Décision<strong>wrongTagd</p>" # instead of '<p>Décision</p>' so we check accents and missing <p></p> req._creationData._decision = 'Décision<strong>wrongTagd</p>' # Serialize the request so it can be easily tested request = serializeRequest(req) expected = """POST /plone/createItemRequest HTTP/1.0 Authorization: Basic %s:%s Content-Length: 102 Content-Type: text/xml SOAPAction: / <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:createItemRequest>""" \ """<meetingConfigId>plonegov-assembly</meetingConfigId><proposingGroupId>developers</proposingGroupId>""" \ """<creationData xsi:type="ns1:CreationData"><title>My new item title</title><category>development</category>""" \ """<description><p>Description</p></description>""" \ """<detailedDescription><p>Detailed description</p></detailedDescription>""" \ """<decision>D\xc3\xa9cision<strong>wrongTagd</p></decision></creationData><cleanHtml>true</cleanHtml>""" \ """</ns1:createItemRequest>""" \ """</SOAP-ENV:Body></SOAP-ENV:Envelope>""" % ('pmCreator1', 'meeting') result = """POST /plone/createItemRequest HTTP/1.0 Authorization: Basic %s:%s Content-Length: 102 Content-Type: text/xml SOAPAction: / %s""" % ('pmCreator1', 'meeting', request) self.assertEqual(expected, result) # now really use the SOAP method to create an item newItem, response = self._createItem(req) newItemUID = newItem.UID() resp = deserialize(response) expected = """<ns1:createItemResponse 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"> <UID>%s</UID> <warnings>%s</warnings> </ns1:createItemResponse> """ % (newItemUID, translate(WRONG_HTML_WARNING, domain='imio.pm.ws', mapping={'item_path': newItem.absolute_url_path(), 'creator': 'pmCreator1'}, context=self.request) ) self.assertEqual(expected, resp) # the item is actually created self.failUnless(len(self.portal.portal_catalog(portal_type='MeetingItemPga', UID=newItemUID)) == 1) # responseHolder for tests here above responseHolder = createItemResponse() # check that we can create an item with a NoneType HTML field req._creationData._decision = None newItemWithEmptyDecisionUID = SOAPView(self.portal, req).createItemRequest(req, responseHolder)._UID self.failUnless(len(self.portal.portal_catalog(portal_type='MeetingItemPga', UID=newItemWithEmptyDecisionUID)) == 1) # No matter how the item is created, with or without a decision, every HTML fields are surrounded by <p></p> obj = self.portal.portal_catalog(portal_type='MeetingItemPga', UID=newItemWithEmptyDecisionUID)[0].getObject() self.failIf(obj.getDecision(keepWithNext=False) != '<p></p>')
def test_ws_createItemWithSeveralAnnexesRequest(self): """ Test SOAP service behaviour when creating items with several annexes of different types """ # by default no item exists self.changeUser('pmCreator1') req = self._prepareCreationData() # add 4 extra annexes # no data give, some default values are used (smallTestFile.pdf) data1 = {'title': 'My annex 1', 'filename': 'smallTestFile.pdf', 'file': 'smallTestFile.pdf'} # other annexTypeId than the default one data2 = {'title': 'My annex 2', 'filename': 'arbitraryFilename.odt', 'file': 'mediumTestFile.odt', 'annexTypeId': 'budget-analysis'} # a wrong annexTypeId and a test with a large msword document data3 = {'title': 'My annex 3', 'filename': 'largeTestFile.doc', 'file': 'largeTestFile.doc', 'annexTypeId': 'wrong-annexTypeId'} # empty file data provided, at the end, the annex is not created but the item is correctly created data4 = {'title': 'My annex 4', 'filename': 'emptyTestFile.txt', 'file': 'emptyTestFile.txt', 'annexTypeId': 'budget-analysis'} # a file that will have several extensions found in mimetypes_registry # is not handled if no valid filename is provided data5 = {'title': 'My annex 5', 'filename': 'notValidFileNameNoExtension', 'file': 'octetStreamTestFile.bin', 'annexTypeId': 'budget-analysis'} # but if the filename is valid, then the annex is handled data6 = {'title': 'My annex 6', 'filename': 'validExtension.bin', 'file': 'octetStreamTestFile.bin', 'annexTypeId': 'budget-analysis'} req._creationData._annexes = [self._prepareAnnexInfo(**data1), self._prepareAnnexInfo(**data2), self._prepareAnnexInfo(**data3), self._prepareAnnexInfo(**data4), self._prepareAnnexInfo(**data5), self._prepareAnnexInfo(**data6)] # serialize the request so it can be easily tested request = serializeRequest(req) # build annexes part of the envelope annexesEnveloppePart = "" for annex in req._creationData._annexes: annexesEnveloppePart = annexesEnveloppePart + """<annexes xsi:type="ns1:AnnexInfo"><title>%s</title>""" \ """<annexTypeId>%s</annexTypeId><filename>%s</filename><file> %s</file></annexes>""" % (annex._title, annex._annexTypeId, annex._filename, base64.encodestring(annex._file)) # This is what the sent enveloppe should looks like expected = """POST /plone/createItemRequest HTTP/1.0 Authorization: Basic %s:%s Content-Length: 102 Content-Type: text/xml SOAPAction: / <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:createItemRequest>""" \ """<meetingConfigId>plonegov-assembly</meetingConfigId><proposingGroupId>developers</proposingGroupId>""" \ """<creationData xsi:type="ns1:CreationData"><title>My new item title</title><category>development</category>""" \ """<description><p>Description</p></description>""" \ """<detailedDescription><p>Detailed description</p></detailedDescription>""" \ """<decision><p>Décision</p></decision>""" \ """%s</creationData><cleanHtml>true</cleanHtml></ns1:createItemRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>""" \ % ('pmCreator1', 'meeting', annexesEnveloppePart) result = """POST /plone/createItemRequest HTTP/1.0 Authorization: Basic %s:%s Content-Length: 102 Content-Type: text/xml SOAPAction: / %s""" % ('pmCreator1', 'meeting', request) self.assertEqual(expected, result) newItem, response = self._createItem(req) annexes = get_annexes(newItem) # 4 annexes are actually created self.failUnless(len(annexes) == 4) # the annexes mimetype are corrects self.failUnless(annexes[0].file.contentType == 'application/pdf') self.failUnless(annexes[1].file.contentType == 'application/vnd.oasis.opendocument.text') self.failUnless(annexes[2].file.contentType == 'application/msword') self.failUnless(annexes[3].file.contentType == 'application/octet-stream') # the annexes metadata are ok self.failUnless( annexes[0].Title() == 'My annex 1' and annexes[0].content_category == 'plonegov-assembly-annexes_types_-_item_annexes_-_financial-analysis') self.failUnless( annexes[1].Title() == 'My annex 2' and annexes[1].content_category == 'plonegov-assembly-annexes_types_-_item_annexes_-_budget-analysis') # meetingFileType is back to default one when a wrong file type is given in the annexInfo self.failUnless( annexes[2].Title() == 'My annex 3' and annexes[2].content_category == 'plonegov-assembly-annexes_types_-_item_annexes_-_financial-analysis') self.failUnless( annexes[3].Title() == 'My annex 6' and annexes[3].content_category == 'plonegov-assembly-annexes_types_-_item_annexes_-_budget-analysis') # annexes filename are the ones defined in the 'filename', either it is generated self.failUnless(annexes[0].file.filename == u'smallTestFile.pdf') self.failUnless(annexes[1].file.filename == u'arbitraryFilename.odt') self.failUnless(annexes[2].file.filename == u'largeTestFile.doc') self.failUnless(annexes[3].file.filename == u'validExtension.bin') # now try to create an item with an annex that has no file # when file attribute is not provided, the annex is not created data = {'title': 'My annex 7', 'filename': 'validExtension.bin', 'annexTypeId': 'budget-analysis'} req._creationData._annexes = [self._prepareAnnexInfo(**data), ] self.assertEqual(req._creationData._annexes[0]._file, None) newItem, response = self._createItem(req) annexes = get_annexes(newItem) # no annexes have been added self.assertEqual(len(annexes), 0)
def test_ws_getConfigInfosRequest(self): """ Test that getting informations about the configuration returns valuable informations """ # any PM user can have these configuration informations self.changeUser('pmCreator1') req = getConfigInfosRequest() # 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:getConfigInfosRequest><showCategories>false</showCategories></ns1:getConfigInfosRequest>""" \ """</SOAP-ENV:Body></SOAP-ENV:Envelope>""" result = """%s""" % request self.assertEquals(expected, result) # now really use the SOAP method to get informations about the configuration responseHolder = getConfigInfosResponse() response = SOAPView(self.portal, req).getConfigInfosRequest(req, responseHolder) resp = deserialize(response) # construct the expected result : header + content + footer # header expected = """<ns1:getConfigInfosResponse 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">""" # _configInfo for cfg in self.tool.getActiveConfigs(): expected += """ <configInfo xsi:type="ns1:ConfigInfo"> <UID>%s</UID> <id>%s</id> <title>%s</title> <description>%s</description>%s </configInfo>""" % (cfg.UID(), cfg.getId(), cfg.Title(), cfg.Description(), self._getItemPositiveDecidedStatesFromConfig(cfg)) # _groupInfo for grp in get_organizations(): expected += """ <groupInfo xsi:type="ns1:GroupInfo"> <UID>%s</UID> <id>%s</id> <title>%s</title> <description>%s</description> </groupInfo>""" % (grp.UID(), grp.getId(), grp.Title(), grp.Description()) # footer. Empty description is represented like <description/> expected = expected.replace('<description></description>', '<description/>') \ + "\n</ns1:getConfigInfosResponse>\n" self.assertEquals(expected, resp) # elements are correctly stored cfg = self.tool.getActiveConfigs()[0] self.assertEqual(response._configInfo[0]._id, cfg.id) self.assertEqual(response._configInfo[0]._title, cfg.Title())
def test_ws_searchItemsRequest(self): """ Test that searching with given parameters returns valuable informations """ # by default no item exists self.changeUser('pmCreator1') self.assertEqual( len(self.portal.portal_catalog(portal_type='MeetingItemPga')), 0) # prepare data for a default item req = self._prepareCreationData() req._creationData._externalIdentifier = 'my_external_app_identifier' # use the SOAP service to create one newItem, response = self._createItem(req) # make sure created enough in the past or sort_on 'created' returns random result newItem.setCreationDate(DateTime() - 5) newItem.reindexObject() newItemUID = newItem.UID() # externalIdentifier is actually set self.assertEqual(newItem.externalIdentifier, 'my_external_app_identifier') # now an item exists, get informations about it req = searchItemsRequest() req._Title = 'item' req._getCategory = 'development' # 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:searchItemsRequest>""" \ """<Title>%s</Title><getCategory>%s</getCategory></ns1:searchItemsRequest>""" \ """</SOAP-ENV:Body></SOAP-ENV:Envelope>""" % (req._Title, req._getCategory) result = """%s""" % request self.assertEqual(expected, result) # now really use the SOAP method to get informations about the item resp = self._searchItems(req) # the item is not in a meeting so the meeting date is 1950-01-01 expected = """<ns1:searchItemsResponse 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><p>Description</p></description> <detailedDescription><p>Detailed description</p></detailedDescription> <decision><p>Décision</p></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>my_external_app_identifier</externalIdentifier> <extraInfos/> </itemInfo> </ns1:searchItemsResponse> """.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 # use the 'plonegov-assembly' MeetingConfig that use real categories, # not useGroupsAsCategories 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') itemInMeeting.reindexObject() req._Title = 'item title' req._getCategory = '' resp = self._searchItems(req) itemInMeetingUID = itemInMeeting.UID() meetingDate = gDateTime.get_formatted_content( gDateTime(), meeting.date.utctimetuple()) # searching for items can returns several items # for example here, searching for 'item title' in existing items title will returns 2 items... expected = """<ns1:searchItemsResponse 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><p>Description</p></description> <detailedDescription><p>Detailed description</p></detailedDescription> <decision><p>Décision</p></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>my_external_app_identifier</externalIdentifier> <extraInfos/> </itemInfo> <itemInfo xsi:type="ns1:ItemInfo"> <UID>{3}</UID> <id>item-2</id> <title>My new item title</title> <creator>pmManager</creator> <creation_date>{4}</creation_date> <modification_date>{5}</modification_date> <category>development</category> <description><p>Description</p></description> <detailedDescription/> <decision><p>Décision</p></decision> <preferredMeeting/> <preferred_meeting_date>1950-01-01T00:00:00.006Z</preferred_meeting_date> <review_state>presented</review_state> <meeting>{6}</meeting> <meeting_date>{7}</meeting_date> <absolute_url>http://nohost/plone/Members/pmManager/mymeetings/plonegov-assembly/item-2</absolute_url> <externalIdentifier/> <extraInfos/> </itemInfo> </ns1:searchItemsResponse> """.format(newItemUID, gDateTime.get_formatted_content(gDateTime(), localtime(newItem.created())), gDateTime.get_formatted_content(gDateTime(), localtime(newItem.modified())), itemInMeetingUID, 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 search params do not return an existing UID, the response is empty req._Title = 'aWrongTitle' resp = self._searchItems(req) expected = """<ns1:searchItemsResponse 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(resp, expected) # if not search params is pass, a ZSI.Fault is raised req._Title = '' responseHolder = searchItemsResponse() with self.assertRaises(ZSI.Fault) as cm: SOAPView(self.portal, req).searchItemsRequest(req, responseHolder) self.assertEqual(cm.exception.string, 'Define at least one search parameter!') # if a 'meetingConfigId' is passed, items of this meetingConfig are taken into account # create an item for 'plonemeeting-assembly' with same data as one created for 'plonegov-assembly' here above req = self._prepareCreationData() req._meetingConfigId = 'plonemeeting-assembly' # in 'plonemeeting-assembly', the category is not used, useGroupsAsCategories is True req._creationData._category = '' newItem, response = self._createItem(req) pmItem = self.portal.portal_catalog(UID=response._UID)[0].getObject() pmItemUID = pmItem.UID() # searching items with Title like 'item title' returns the 3 created elements req = searchItemsRequest() req._Title = 'item title' responseHolder = searchItemsResponse() response = SOAPView(self.portal, req).searchItemsRequest(req, responseHolder) resp = deserialize(response) self.failUnless(itemInMeetingUID in resp and newItemUID in resp and pmItemUID in resp) req._meetingConfigId = 'plonemeeting-assembly' response = SOAPView(self.portal, req).searchItemsRequest(req, responseHolder) resp = deserialize(response) self.failUnless(itemInMeetingUID not in resp and newItemUID not in resp and pmItemUID in resp) # passing a wrong meetingConfigId will raise a ZSI.Fault req._meetingConfigId = 'wrongMeetingConfigId' with self.assertRaises(ZSI.Fault) as cm: SOAPView(self.portal, req).searchItemsRequest(req, responseHolder) self.assertEqual(cm.exception.string, "Unknown meetingConfigId : 'wrongMeetingConfigId'!")