def ImportSector(plone, options, filename): input = open(filename, "r") dom = lxml.objectify.parse(input) xml_sector = dom.getroot() country = GetCountry(plone, options) if not hasattr(xml_sector, "survey"): return sector = GetSector(country, xml_sector, options) if sector is None: raise Abort("No sector specified and no account information found.") # Login as the sector sup = UserProvider(sector) sectoruser = plone.acl_users.getUserById(sup.getUserId()) sm = getSecurityManager() try: newSecurityManager(None, sectoruser) name = options.name or six.text_type(xml_sector.survey.title.text) if hasattr(sector, name): raise Abort("There is already a survey named '%s'" % name) log.info("Importing survey '%s' with version '%s'", name, options.version) importer = SurveyImporter(sector) survey = importer(xml_sector, name, options.version) if options.publish: log.info("Publishing survey") publisher = publish.PublishSurvey(survey, None) publisher.publish() finally: setSecurityManager(sm)
def addSurvey(portal, xml_survey): """Add a survey to the portal. This function requires that you are already loggin in as portal owner.""" from euphorie.content import upload from euphorie.client import publish importer = upload.SectorImporter(portal.sectors.nl) sector = importer(xml_survey, None, None, None, u"test import") survey = sector.values()[0]["test-import"] publisher = publish.PublishSurvey(survey, portal.REQUEST) publisher.publish()
def XtestUpdateShowsRepeatableProfileItems(self): # Tests http://code.simplon.biz/tracker/tno-euphorie/ticket/85 survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0"> <title>Sector title</title> <survey> <title>Survey title</title> <language>nl</language> <profile-question> <title>Multiple profile question</title> <question>Profile titles</question> <description><p>Profile description.</p></description> <risk type="policy"> <title>Profile risk</title> <description><p>Risk description.</p></description> <evaluation-method>direct</evaluation-method> </risk> </profile-question> </survey> </sector>""" # noqa: E501 self.loginAsPortalOwner() addSurvey(self.portal, survey) browser = self.get_browser() browser.open(self.portal.client.nl["sector-title"] ["survey-title"].absolute_url()) registerUserInClient(browser) # Create a new survey session browser.getControl(name="title:utf8:ustring").value = "Test session" browser.getControl(name="next", index=1).click() # Start the survey browser.getForm().submit() # Enter the profile information browser.getControl(name="1:utext:list", index=0).value = "Profile 1" browser.getControl(name="1:utext:list", index=1).value = "Profile 2" browser.getForm().submit() # Change the survey and publish again from euphorie.client import publish survey = self.portal.sectors["nl"]["sector-title"]["survey-title"][ "test-import"] survey.invokeFactory("euphorie.module", "test module") publisher = publish.PublishSurvey(survey, self.portal.REQUEST) publisher.publish() # We should get an update notification now browser.getLink("Start Risk Identification").click() self.assertEqual( browser.url, "http://nohost/plone/client/nl/sector-title/survey-title/update", ) # And our current profile should be listed self.assertEqual( browser.getControl(name="1:utext:list", index=0).value, "Profile 1") self.assertEqual( browser.getControl(name="1:utext:list", index=1).value, "Profile 2") # Confirm the profile browser.getForm().submit() self.assertEqual( browser.url, "http://nohost/plone/client/nl/sector-title/" "survey-title/identification", ) # Make sure the profile is correct browser.getLink("Start Risk Identification").click() self.assertTrue("Profile 1" in browser.contents) self.assertTrue("Profile 2" in browser.contents)
def XtestSkipChildrenFalseForMandatoryModules(self): """Mandatory modules must have skip_children=False. It's possible that the module was optional with skip_children=True and now after the update must be mandatory. """ survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0"> <title>Sector title</title> <survey> <title>Survey title</title> <language>nl</language> <module optional="true"> <title>Module Title</title> <description><p>Testing ticket #3860</p></description> <question>What is the sound of one hand clapping?</question> <risk type="risk"> <title>This risk exists</title> <problem-description>This risk doesn't exist</problem-description> <description><p>asdg</p></description> <show-not-applicable>false</show-not-applicable> <evaluation-method>direct</evaluation-method> </risk> </module> </survey> </sector>""" # noqa: E501 self.loginAsPortalOwner() addSurvey(self.portal, survey) browser = self.get_browser() client_survey = self.portal.client.nl["sector-title"]["survey-title"] browser.open(client_survey.absolute_url()) registerUserInClient(browser) # Create a new survey session browser.getControl(name="title:utf8:ustring").value = "Test session" browser.getControl(name="next", index=1).click() # Start the survey browser.getForm().submit() # Enter the profile information browser.getLink("Start Risk Identification").click() # Set Skip-children to True module_identification_url = browser.url browser.handleErrors = False # XXX: The following breaks when testing with sqlite but not with # postgres. browser.getControl(name="skip_children:boolean").controls[1].click() browser.getControl(name="next", index=1).click() # Change the survey to make the module required and publish again from euphorie.client import publish survey = self.portal.sectors["nl"]["sector-title"]["survey-title"][ "test-import"] module = survey["1"] module.optional = False publisher = publish.PublishSurvey(survey, self.portal.REQUEST) publisher.publish() # We should get an update notification now browser.open(client_survey.absolute_url()) browser.getLink("Start Risk Identification").click() # We should now be on the module self.assertEqual(browser.url, module_identification_url) # But this time, the module's "optional" question (i.e to skip the # children) should not be there self.assertRaises(LookupError, browser.getControl, name="skip_children:boolean") browser.getControl(name="next", index=1).click() # Now we must see the risk, i.e skip_children=False so we *must* answer # the risk self.assertEqual( "<legend>This risk exists</legend>" in browser.contents, True) # There are 2 inputs (2 radio, 1 hidden), for yes, no and postponed. self.assertEqual(len(browser.getControl(name="answer").controls), 3) self.assertEqual( browser.getControl(name="answer:default").value, "postponed")