コード例 #1
0
 def setUp(self):
     TestManagement.setUp(self)
     self.conf = Configuration(self.test_conf_path)
     self.default = Configuration()
     self.ts_conf = self.conf.get(survey_name="Test survëy")
     self.qts_conf = self.conf.get(
         survey_name="Test survëy", question_text="Dolor sit amët, consectetur<strong>  adipiscing</strong>  elit."
     )
     self.qts_expected_conf = {"min_cardinality": 0, "type": "cloud", "radius": 1, "text": "inside"}
コード例 #2
0
 def handle(self, *args, **options):
     super(Command, self).handle(*args, **options)
     translation.activate(options.get("language"))
     for survey in self.surveys:
         LOGGER.info("Generating results for '%s'", survey)
         exporters = []
         if options["csv"]:
             exporters.append(Survey2Csv(survey))
         if options["tex"] or options["pdf"]:
             configuration_file = options.get("configuration_file")
             if configuration_file is None:
                 msg = "No configuration file given, using default values for '{}'.".format(survey)
                 LOGGER.info(msg)
             configuration = Configuration(configuration_file)
             exporters.append(Survey2Tex(survey, configuration))
         for exporter in exporters:
             if options["force"] or exporter.need_update():
                 exporter.generate_file()
                 if options["pdf"] and isinstance(exporter, Survey2Tex):
                     exporter.generate_pdf()
             else:
                 LOGGER.warning(
                     "\t- %s's %s were already generated use the --force (-f) option to generate anyway.",
                     survey,
                     exporter._get_x(),
                 )
コード例 #3
0
    def handle(self, *args, **options):
        super(Command, self).handle(*args, **options)
        translation.activate(options.get("language"))
        if not options["csv"] and not options["tex"] and not options["pdf"]:
            exit("Nothing to do : add option --tex or --pdf, --csv,  or both.")
        if self.survey is None:
            surveys = Survey.objects.all()
        else:
            surveys = [self.survey]
        for survey in surveys:
            LOGGER.info("Generating results for '%s'", survey)
            exporters = []
            if options["csv"]:
                exporters.append(Survey2Csv(survey))
            if options["tex"] or options["pdf"]:
                configuration_file = options.get("configuration_file")
                if configuration_file is None:
                    msg = "No configuration file given, using default values."
                    LOGGER.warning(msg)
                configuration = Configuration(configuration_file)
                exporters.append(Survey2Tex(survey, configuration))
            for exporter in exporters:
                if options["force"] or exporter.need_update():
                    exporter.generate_file()
                    if options["pdf"] and type(exporter) is Survey2Tex:
                        exporter.generate_pdf()
                else:
                    LOGGER.info("\t- %s's %s were already generated use the\
 --force (-f) option to generate anyway.", survey, exporter._get_X())
コード例 #4
0
 def test_custom_class_fail_import(self):
     """ We have an error message if the type is impossible to import. """
     conf = Configuration(
         os.path.join(self.conf_dir, "custom_class_doesnt_exists.yaml"))
     self.test_survey = Survey.objects.get(name="Test survëy")
     fail_import = Survey2Tex(self.test_survey, conf).survey_to_x()
     should_contain = [
         "could not render", "not a standard type",
         "importable valid Question2Tex child class", "'raw'", "'sankey'",
         "'pie'", "'cloud'", "'square'", "'polar'"
     ]
     for text in should_contain:
         self.assertIn(text, fail_import)
コード例 #5
0
 def test_name_doesnt_exists(self):
     """ Value error raised when the name does not exists. """
     name = "This survey does not exists"
     path = Path(self.conf_dir, "name_doesnt_exists.yaml")
     conf = Configuration(path)
     self.assertIsNotNone(conf.get(survey_name=name))
     Survey.objects.create(name=name, is_published=True, need_logged_user=True, display_method=Survey.BY_QUESTION)
     conf = Configuration(path)
     self.assertIsNotNone(conf.get(survey_name=name))
コード例 #6
0
 def test_name_doesnt_exists(self):
     """ Value error raised when the name does not exists. """
     name = "This survey does not exists"
     path = os.path.join(self.conf_dir, "name_doesnt_exists.yaml")
     conf = Configuration(path)
     self.assertIsNotNone(conf.get(survey_name=name))
     Survey.objects.create(name=name,
                           status='Active',
                           need_logged_user=True,
                           display_by_question=True)
     conf = Configuration(path)
     self.assertIsNotNone(conf.get(survey_name=name))
コード例 #7
0
class TestConfiguration(TestManagement):
    def setUp(self):
        TestManagement.setUp(self)
        self.conf = Configuration(self.test_conf_path)
        self.default = Configuration()
        self.ts_conf = self.conf.get(survey_name="Test survëy")
        self.qts_conf = self.conf.get(
            survey_name="Test survëy",
            question_text="Dolor sit amët, consectetur<strong>  adipiscing"
            "</strong>  elit.")
        self.qts_expected_conf = {
            "min_cardinality": 0,
            "type": "cloud",
            "radius": 1,
            "text": "inside"
        }

    def test_name_doesnt_exists(self):
        """ Value error raised when the name does not exists. """
        name = "This survey does not exists"
        path = os.path.join(self.conf_dir, "name_doesnt_exists.yaml")
        conf = Configuration(path)
        self.assertIsNotNone(conf.get(survey_name=name))
        Survey.objects.create(name=name,
                              is_published=True,
                              need_logged_user=True,
                              display_by_question=True)
        conf = Configuration(path)
        self.assertIsNotNone(conf.get(survey_name=name))

    def test_str(self):
        """ No error for str """
        self.assertIsNotNone(str(self.conf))

    def test_wrong_type(self):
        """ If we give the wrong type for survey_name we get a TypeError. """
        self.assertRaises(TypeError, self.conf.get, survey_name=self.survey)

    def test_no_value_defined(self):
        """ We raise a value error if there is nothing at all for a Survey."""
        path = os.path.join(self.conf_dir, "no_value_defined.yaml")
        self.assertRaises(ValueError, Configuration, path)

    def test_use_default(self):
        """ If the value is undefined for a survey we use default. """
        short_survey_conf = self.conf.get(survey_name="Short Survëy")
        self.assertEqual(short_survey_conf.get("document_class"), "article")

    def test_change_default(self):
        """ If a value is set in a survey, the default is changed. """
        ss_conf = self.conf["Short Survëy"]
        self.assertEqual(ss_conf.get("footer"), "Short survey footer.")
        self.assertEqual(ss_conf.get("document_class"), "article")
        # Test Management Survëy conf
        tm_survey = Survey.objects.get(name="Test Management Survëy")
        tm_conf = self.conf.get(survey_name=tm_survey.name)
        self.assertEqual(tm_conf.get("footer"), "Test management footer.")
        self.assertEqual(tm_conf.get("document_class"), "article")
        self.assertEqual(self.conf.get("footer", "Test survëy"),
                         "This is the footer.")
        self.assertEqual(
            self.conf.get(key="document_class", survey_name="Test survëy"),
            "report")
        self.assertEqual(self.conf.get("footer"), "This is the footer.")
        self.assertEqual(self.conf.get("document_class"), "article")

    def test_get_questions(self):
        """ We have something coherent when we get by question_text. """
        self.assertEqual(self.ts_conf["chart"]["min_cardinality"], 0)
        self.assertEqual(self.ts_conf["chart"]["type"], "pie")
        self.assertEqual(self.ts_conf["chart"]["radius"], 3)
        self.assertEqual(self.ts_conf["chart"]["text"], "legend")
        for key, value in self.qts_expected_conf.items():
            self.assertEqual(self.qts_conf["chart"][key], value)

    def test_get_question_multiple_charts(self):
        """ We have set multiple charts when we get by question text. """
        self.assertEqual(self.ts_conf["multiple_charts"], None)
        self.assertEqual(self.ts_conf["multiple_chart_type"], "subsubsection")
        self.assertEqual(self.qts_conf["multiple_chart_type"], "subsubsection")
        qts_charts = [
            'Sub Sub Section with radius=3', 'Sub Sub Section with text=pin'
        ]
        qts_charts.sort()
        qts_mc_results = list(self.qts_conf["multiple_charts"].keys())
        qts_mc_results.sort()
        self.assertEqual(qts_mc_results, qts_charts)
        for chart in qts_charts:
            for key, expected_value in self.qts_expected_conf.items():
                value = self.qts_conf["multiple_charts"][chart][key]
                if chart == "Sub Sub Section with radius=3" and key == "radius":
                    expected_value = 3
                elif chart == 'Sub Sub Section with text=pin' and key == "text":
                    expected_value = "pin"
                self.assertEqual(
                    value, expected_value,
                    "Expected '{}' for '{}' in '{}' and got '{}'".format(
                        expected_value, key, chart, value))

    def test_value_doesnt_exists(self):
        """ Get when a value does not exists. """
        self.assertRaises(ValueError, self.conf.get, key="noexists")
        self.assertRaises(ValueError,
                          self.conf.get,
                          survey_name="Test survëy",
                          key="noexists")
        self.assertRaises(
            ValueError,
            self.conf.get,
            survey_name="Test survëy",
            question_text="Dolor sit amët, consectetur<strong>  adipiscing"
            "</strong>  elit.",
            key="noexists")
コード例 #8
0
 def setUp(self):
     TestManagement.setUp(self)
     conf = Configuration(os.path.join(self.conf_dir, "test_conf.yaml"))
     self.generic = Survey2Tex(self.survey, conf)
     self.test_survey = Survey.objects.get(name="Test survëy")
     self.specific = Survey2Tex(self.test_survey, conf)
コード例 #9
0
 def __init__(self, survey, configuration=None):
     Survey2X.__init__(self, survey)
     if configuration is None:
         configuration = Configuration()
     self.tconf = configuration