Ejemplo n.º 1
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",
     )
Ejemplo n.º 2
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",
         )
Ejemplo n.º 3
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",
     )
Ejemplo n.º 4
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",
     )