Exemple #1
0
 def testRender(self):
     from euphorie.content.surveygroup import SurveyGroup
     from euphorie.content.survey import Survey
     from zope.publisher.browser import TestRequest
     surveygroup = SurveyGroup()
     surveygroup.id = "mysector"
     surveygroup.title = u"Generic sector"
     surveygroup["standard"] = Survey()
     survey = surveygroup["standard"]  # Acquisition wrap
     survey.id = "dummy"
     survey.title = u"Standard"
     survey.introduction = None
     survey.classification_code = None
     survey.evaluation_optional = False
     survey.language = "en-GB"
     view = ExportSurvey(survey, TestRequest())
     output = view()
     response = view.request.response
     self.assertEqual(response.getHeader("Content-Type"), "text/xml")
     self.assertEqual(
             response.getHeader("Content-Disposition"),
             'attachment; filename="mysector.xml"')
     self.assertEqual(output,
             '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n'
             '<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">\n'
             '  <survey>\n'
             '    <title>Generic sector</title>\n'
             '    <language>en-GB</language>\n'
             '    <evaluation-algorithm>kinney</evaluation-algorithm>\n'
             '    <evaluation-optional>false</evaluation-optional>\n'
             '  </survey>\n'
             '</sector>\n')
Exemple #2
0
 def testSurvey_IntroductionNoText(self):
     surveygroup = SurveyGroup()
     surveygroup.title = "Generic sector"
     surveygroup._setOb("standard", Survey())
     survey = surveygroup["standard"]  # Acquisition wrap
     survey.title = "Standard"
     survey.introduction = "<p><br/></p>"
     survey.classification_code = None
     survey.evaluation_optional = False
     survey.language = "en-GB"
     root = self.root()
     view = ExportSurvey(None, None)
     view.exportSurvey(root, survey)
     self.assertEqual(
         safe_nativestring(etree.tostring(root, pretty_print=True)),
         '<root xmlns="http://xml.simplon.biz/euphorie/survey/1.0">\n'
         "  <survey>\n"
         "    <title>Generic sector</title>\n"
         "    <language>en-GB</language>\n"
         "    <tool_type>classic</tool_type>\n"
         "    <measures_text_handling>full</measures_text_handling>\n"
         "    <integrated_action_plan>false</integrated_action_plan>\n"
         "    <evaluation-algorithm>kinney</evaluation-algorithm>\n"
         "    <evaluation-optional>false</evaluation-optional>\n"
         "  </survey>\n"
         "</root>\n",
     )
Exemple #3
0
 def testSurvey_Minimal(self):
     from euphorie.content.surveygroup import SurveyGroup
     from euphorie.content.survey import Survey
     surveygroup = SurveyGroup()
     surveygroup.title = u"Generic sector"
     surveygroup.evaluation_algorithm = u"french"
     surveygroup["standard"] = Survey()
     survey = surveygroup["standard"]  # Acquisition wrap
     survey.title = u"Standard"
     survey.introduction = None
     survey.classification_code = None
     survey.evaluation_optional = False
     survey.language = "en-GB"
     root = self.root()
     view = ExportSurvey(None, None)
     node = view.exportSurvey(root, survey)
     self.assertTrue(node in root)
     self.assertEqual(etree.tostring(root, pretty_print=True),
             '<root xmlns="http://xml.simplon.biz/euphorie/survey/1.0">\n'
             '  <survey>\n'
             '    <title>Generic sector</title>\n'
             '    <language>en-GB</language>\n'
             '    <evaluation-algorithm>french</evaluation-algorithm>\n'
             '    <evaluation-optional>false</evaluation-optional>\n'
             '  </survey>\n'
             '</root>\n')
Exemple #4
0
 def testRender(self):
     from euphorie.content.surveygroup import SurveyGroup
     from euphorie.content.survey import Survey
     from zope.publisher.browser import TestRequest
     surveygroup = SurveyGroup()
     surveygroup.id = "mysector"
     surveygroup.title = u"Generic sector"
     surveygroup["standard"] = Survey()
     survey = surveygroup["standard"]  # Acquisition wrap
     survey.id = "dummy"
     survey.title = u"Standard"
     survey.introduction = None
     survey.classification_code = None
     survey.evaluation_optional = False
     survey.language = "en-GB"
     view = ExportSurvey(survey, TestRequest())
     output = view()
     response = view.request.response
     self.assertEqual(response.getHeader("Content-Type"), "text/xml")
     self.assertEqual(response.getHeader("Content-Disposition"),
                      'attachment; filename="mysector.xml"')
     self.assertEqual(
         output, '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n'
         '<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">\n'
         '  <survey>\n'
         '    <title>Generic sector</title>\n'
         '    <language>en-GB</language>\n'
         '    <evaluation-algorithm>kinney</evaluation-algorithm>\n'
         '    <evaluation-optional>false</evaluation-optional>\n'
         '  </survey>\n'
         '</sector>\n')
Exemple #5
0
 def testSurvey_IntroductionNoText(self):
     from euphorie.content.surveygroup import SurveyGroup
     from euphorie.content.survey import Survey
     surveygroup = SurveyGroup()
     surveygroup.title = u"Generic sector"
     surveygroup["standard"] = Survey()
     survey = surveygroup["standard"]  # Acquisition wrap
     survey.title = u"Standard"
     survey.introduction = u"<p><br/></p>"
     survey.classification_code = None
     survey.evaluation_optional = False
     survey.language = "en-GB"
     root = self.root()
     view = ExportSurvey(None, None)
     view.exportSurvey(root, survey)
     self.assertEqual(
         etree.tostring(root, pretty_print=True),
         '<root xmlns="http://xml.simplon.biz/euphorie/survey/1.0">\n'
         '  <survey>\n'
         '    <title>Generic sector</title>\n'
         '    <language>en-GB</language>\n'
         '    <evaluation-algorithm>kinney</evaluation-algorithm>\n'
         '    <evaluation-optional>false</evaluation-optional>\n'
         '  </survey>\n'
         '</root>\n')
Exemple #6
0
 def testSurvey_WithProfileQuestion(self):
     surveygroup = SurveyGroup()
     surveygroup.title = "Generic sector"
     surveygroup._setOb("standard", Survey())
     survey = surveygroup["standard"]  # Acquisition wrap
     survey.title = "Generic sector"
     survey.introduction = None
     survey.classification_code = None
     survey.evaluation_optional = False
     survey.language = "en-GB"
     profile = ProfileQuestion()
     profile.title = "Office buildings"
     profile.question = "Do you have an office buildings?"
     profile.description = "<p>Owning property brings risks.</p>"
     profile.type = "optional"
     survey._setOb("1", profile)
     root = self.root()
     view = ExportSurvey(None, None)
     view.exportSurvey(root, survey)
     self.assertEqual(
         safe_nativestring(etree.tostring(root, pretty_print=True)),
         '<root xmlns="http://xml.simplon.biz/euphorie/survey/1.0">\n'
         "  <survey>\n"
         "    <title>Generic sector</title>\n"
         "    <language>en-GB</language>\n"
         "    <tool_type>classic</tool_type>\n"
         "    <measures_text_handling>full</measures_text_handling>\n"
         "    <integrated_action_plan>false</integrated_action_plan>\n"
         "    <evaluation-algorithm>kinney</evaluation-algorithm>\n"
         "    <evaluation-optional>false</evaluation-optional>\n"
         "    <profile-question>\n"
         "      <title>Office buildings</title>\n"
         "      <question>Do you have an office buildings?</question>\n"
         "      <description>&lt;p&gt;Owning property brings "
         "risks.&lt;/p&gt;</description>\n"
         "      <use-location-question>true</use-location-question>\n"
         "    </profile-question>\n"
         "  </survey>\n"
         "</root>\n",
     )
Exemple #7
0
 def testSurvey_WithProfileQuestion(self):
     from euphorie.content.surveygroup import SurveyGroup
     from euphorie.content.survey import Survey
     from euphorie.content.profilequestion import ProfileQuestion
     surveygroup = SurveyGroup()
     surveygroup.title = u"Generic sector"
     surveygroup["standard"] = Survey()
     survey = surveygroup["standard"]  # Acquisition wrap
     survey.title = u"Generic sector"
     survey.introduction = None
     survey.classification_code = None
     survey.evaluation_optional = False
     survey.language = "en-GB"
     profile = ProfileQuestion()
     profile.title = u"Office buildings"
     profile.question = u"Do you have an office buildings?"
     profile.description = u"<p>Owning property brings risks.</p>"
     profile.type = "optional"
     survey["1"] = profile
     root = self.root()
     view = ExportSurvey(None, None)
     view.exportSurvey(root, survey)
     self.assertEqual(
         etree.tostring(root, pretty_print=True),
         '<root xmlns="http://xml.simplon.biz/euphorie/survey/1.0">\n'
         '  <survey>\n'
         '    <title>Generic sector</title>\n'
         '    <language>en-GB</language>\n'
         '    <evaluation-algorithm>kinney</evaluation-algorithm>\n'
         '    <evaluation-optional>false</evaluation-optional>\n'
         '    <profile-question>\n'
         '      <title>Office buildings</title>\n'
         '      <question>Do you have an office buildings?</question>\n'
         '      <description>&lt;p&gt;Owning property brings '
         'risks.&lt;/p&gt;</description>\n'
         '      <use-location-question>true</use-location-question>\n'
         '    </profile-question>\n'
         '  </survey>\n'
         '</root>\n')
Exemple #8
0
 def testSurvey_WithProfileQuestion(self):
     from euphorie.content.surveygroup import SurveyGroup
     from euphorie.content.survey import Survey
     from euphorie.content.profilequestion import ProfileQuestion
     surveygroup = SurveyGroup()
     surveygroup.title = u"Generic sector"
     surveygroup["standard"] = Survey()
     survey = surveygroup["standard"]  # Acquisition wrap
     survey.title = u"Generic sector"
     survey.introduction = None
     survey.classification_code = None
     survey.evaluation_optional = False
     survey.language = "en-GB"
     profile = ProfileQuestion()
     profile.title = u"Office buildings"
     profile.question = u"Do you have an office buildings?"
     profile.description = u"<p>Owning property brings risks.</p>"
     profile.type = "optional"
     survey["1"] = profile
     root = self.root()
     view = ExportSurvey(None, None)
     view.exportSurvey(root, survey)
     self.assertEqual(etree.tostring(root, pretty_print=True),
             '<root xmlns="http://xml.simplon.biz/euphorie/survey/1.0">\n'
             '  <survey>\n'
             '    <title>Generic sector</title>\n'
             '    <language>en-GB</language>\n'
             '    <evaluation-algorithm>kinney</evaluation-algorithm>\n'
             '    <evaluation-optional>false</evaluation-optional>\n'
             '    <profile-question>\n'
             '      <title>Office buildings</title>\n'
             '      <question>Do you have an office buildings?</question>\n'
             '      <description>&lt;p&gt;Owning property brings '
             'risks.&lt;/p&gt;</description>\n'
             '    </profile-question>\n'
             '  </survey>\n'
             '</root>\n')
Exemple #9
0
 def testSurvey_WithModule(self):
     from euphorie.content.surveygroup import SurveyGroup
     from euphorie.content.survey import Survey
     from euphorie.content.module import Module
     surveygroup = SurveyGroup()
     surveygroup.title = u"Generic sector"
     surveygroup["standard"] = Survey()
     survey = surveygroup["standard"]  # Acquisition wrap
     survey.title = u"Generic sector"
     survey.introduction = None
     survey.classification_code = None
     survey.evaluation_optional = False
     survey.language = "en-GB"
     module = Module()
     module.title = u"Office buildings"
     module.description = u"<p>Owning property brings risks.</p>"
     module.optional = False
     module.solution_direction = None
     survey["1"] = module
     root = self.root()
     view = ExportSurvey(None, None)
     view.exportSurvey(root, survey)
     self.assertEqual(
         etree.tostring(root, pretty_print=True),
         '<root xmlns="http://xml.simplon.biz/euphorie/survey/1.0">\n'
         '  <survey>\n'
         '    <title>Generic sector</title>\n'
         '    <language>en-GB</language>\n'
         '    <evaluation-algorithm>kinney</evaluation-algorithm>\n'
         '    <evaluation-optional>false</evaluation-optional>\n'
         '    <module optional="false">\n'
         '      <title>Office buildings</title>\n'
         '      <description>&lt;p&gt;Owning property brings '
         'risks.&lt;/p&gt;</description>\n'
         '    </module>\n'
         '  </survey>\n'
         '</root>\n')
Exemple #10
0
 def testSurvey_WithModule(self):
     from euphorie.content.surveygroup import SurveyGroup
     from euphorie.content.survey import Survey
     from euphorie.content.module import Module
     surveygroup = SurveyGroup()
     surveygroup.title = u"Generic sector"
     surveygroup["standard"] = Survey()
     survey = surveygroup["standard"]  # Acquisition wrap
     survey.title = u"Generic sector"
     survey.introduction = None
     survey.classification_code = None
     survey.evaluation_optional = False
     survey.language = "en-GB"
     module = Module()
     module.title = u"Office buildings"
     module.description = u"<p>Owning property brings risks.</p>"
     module.optional = False
     module.solution_direction = None
     survey["1"] = module
     root = self.root()
     view = ExportSurvey(None, None)
     view.exportSurvey(root, survey)
     self.assertEqual(etree.tostring(root, pretty_print=True),
             '<root xmlns="http://xml.simplon.biz/euphorie/survey/1.0">\n'
             '  <survey>\n'
             '    <title>Generic sector</title>\n'
             '    <language>en-GB</language>\n'
             '    <evaluation-algorithm>kinney</evaluation-algorithm>\n'
             '    <evaluation-optional>false</evaluation-optional>\n'
             '    <module optional="false">\n'
             '      <title>Office buildings</title>\n'
             '      <description>&lt;p&gt;Owning property brings '
             'risks.&lt;/p&gt;</description>\n'
             '    </module>\n'
             '  </survey>\n'
             '</root>\n')
Exemple #11
0
 def testRenderZip(self):
     surveygroup = SurveyGroup()
     surveygroup.id = "mysector"
     surveygroup.title = "Generic sector"
     surveygroup._setOb("standard", Survey())
     survey = surveygroup["standard"]  # Acquisition wrap
     survey.id = "dummy"
     survey.title = "Standard"
     survey.introduction = "Wie grün sind deine Blätter?"
     survey.classification_code = None
     survey.evaluation_optional = False
     survey.integrated_action_plan = True
     survey.language = "en-GB"
     survey.tool_type = "existing_measures"
     view = ExportSurvey(survey, TestRequest())
     view.export_as_plain_text = True
     output = view.render_output()
     zip_file = ZipFile(BytesIO(output), mode="r")
     response = view.request.response
     self.assertEqual(response.getHeader("Content-Type"), "application/zip")
     self.assertEqual(
         response.getHeader("Content-Disposition"),
         'attachment; filename="mysector.zip"',
     )
     self.assertEqual(zip_file.namelist(),
                      ["mysector_word_count.txt", "mysector.xml"])
     with zip_file.open("mysector_word_count.txt") as txt_file:
         txt = txt_file.read().decode("utf-8").strip()
         self.assertEqual(txt,
                          "Generic sector Wie grün sind deine Blätter?")
     with zip_file.open("mysector.xml") as xml_file:
         xml = xml_file.read().decode("utf-8")
         self.assertEqual(
             xml,
             "<?xml version='1.0' encoding='utf-8'?>\n"
             '<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">\n'
             "  <survey>\n"
             "    <title>Generic sector</title>\n"
             "    <introduction>Wie grün sind deine Blätter?</introduction>\n"
             "    <language>en-GB</language>\n"
             "    <tool_type>existing_measures</tool_type>\n"
             "    <measures_text_handling>full</measures_text_handling>\n"
             "    <integrated_action_plan>true</integrated_action_plan>\n"
             "    <evaluation-algorithm>kinney</evaluation-algorithm>\n"
             "    <evaluation-optional>false</evaluation-optional>\n"
             "  </survey>\n"
             "</sector>\n",
         )
Exemple #12
0
 def testRender(self):
     surveygroup = SurveyGroup()
     surveygroup.id = "mysector"
     surveygroup.title = "Generic sector"
     surveygroup._setOb("standard", Survey())
     survey = surveygroup["standard"]  # Acquisition wrap
     survey.id = "dummy"
     survey.title = "Standard"
     survey.introduction = None
     survey.classification_code = None
     survey.evaluation_optional = False
     survey.integrated_action_plan = True
     survey.language = "en-GB"
     survey.tool_type = "existing_measures"
     view = ExportSurvey(survey, TestRequest())
     output = view.render_output().decode("utf-8")
     response = view.request.response
     self.assertEqual(response.getHeader("Content-Type"), "text/xml")
     self.assertEqual(
         response.getHeader("Content-Disposition"),
         'attachment; filename="mysector.xml"',
     )
     self.assertEqual(
         output,
         "<?xml version='1.0' encoding='utf-8'?>\n"
         '<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">\n'
         "  <survey>\n"
         "    <title>Generic sector</title>\n"
         "    <language>en-GB</language>\n"
         "    <tool_type>existing_measures</tool_type>\n"
         "    <measures_text_handling>full</measures_text_handling>\n"
         "    <integrated_action_plan>true</integrated_action_plan>\n"
         "    <evaluation-algorithm>kinney</evaluation-algorithm>\n"
         "    <evaluation-optional>false</evaluation-optional>\n"
         "  </survey>\n"
         "</sector>\n",
     )