Пример #1
0
    def test_setting_reserved_words(self):
        """Test setting any of the existing attribute names."""

        with self.assertRaises(ValueError):
            cad = models.CustomAttributeDefinition()
            cad.definition_type = "section"
            cad.title = "title"

        with self.assertRaises(ValueError):
            cad = models.CustomAttributeDefinition()
            cad.title = "title"
            cad.definition_type = "section"

        with self.assertRaises(ValueError):
            models.CustomAttributeDefinition(
                title="title",
                definition_type="Assessment",
            )

        with self.assertRaises(ValueError):
            models.CustomAttributeDefinition(
                title="TITLE",
                definition_type="program",
            )

        cad = models.CustomAttributeDefinition(
            title="non existing title",
            definition_type="program",
        )
        self.assertEqual(cad.title, "non existing title")
Пример #2
0
 def test_different_models(self):
     """Test unique names over on different models."""
     db.session.add(
         models.CustomAttributeDefinition(
             title="my custom attribute title",
             definition_type="section",
             attribute_type="Text",
         ))
     db.session.commit()
     cad = models.CustomAttributeDefinition(
         title="my custom attribute title",
         definition_type="program",
         attribute_type="Text",
     )
     self.assertEqual(cad.title, "my custom attribute title")
Пример #3
0
    def test_setting_global_cad_names(self):
        """Test duplicates with global attribute names."""

        db.session.add(
            models.CustomAttributeDefinition(
                title="global cad",
                definition_type="section",
                attribute_type="Text",
            ))
        db.session.add(
            models.CustomAttributeDefinition(
                title="non existing title",
                definition_type="section",
                definition_id=1,
                attribute_type="Text",
            ))
        db.session.add(
            models.CustomAttributeDefinition(
                title="non existing title",
                definition_type="section",
                definition_id=2,
                attribute_type="Text",
            ))
        db.session.commit()

        with self.assertRaises(IntegrityError):
            db.session.add(
                models.CustomAttributeDefinition(
                    title="non existing title",
                    definition_type="section",
                    definition_id=2,
                    attribute_type="Text",
                ))
            db.session.commit()
        db.session.rollback()

        with self.assertRaises(ValueError):
            db.session.add(
                models.CustomAttributeDefinition(
                    title="global cad",
                    definition_type="section",
                    definition_id=2,
                    attribute_type="Text",
                ))
            db.session.commit()
Пример #4
0
    def test_export_assessments_with_filters_and_conflicting_ca_names(self):
        """Test exporting assessments with conflicting custom attribute names."""
        self.import_file(u"assessment_template_no_warnings.csv")
        self.import_file(u"assessment_with_templates.csv")

        # also create an object level custom attribute with a name that clashes
        # with a name of a "regular" attribute
        assessment = models.Assessment.query.filter(
            models.Assessment.slug == u"A 2").first()
        cad = models.CustomAttributeDefinition(attribute_type=u"Text",
                                               title=u"ca title",
                                               definition_type=u"assessment",
                                               definition_id=assessment.id)
        db.session.add(cad)
        db.session.commit()

        data = [{
            "object_name": "Assessment",
            "fields": ["slug", "title", "description", "status"],
            "filters": {
                "expression": {
                    "left": {
                        "left": "code",
                        "op": {
                            "name": "~"
                        },
                        "right": "A 2"
                    },
                    "op": {
                        "name": "AND"
                    },
                    "right": {
                        "left": "title",
                        "op": {
                            "name": "~"
                        },
                        "right": "no template Assessment"
                    }
                },
                "keys": ["code", "title", "status"],
                "order_by": {
                    "keys": [],
                    "order": "",
                    "compare": None
                }
            }
        }]

        response = self.export_csv(data)
        self.assertIn(u"No template Assessment 2", response.data)
Пример #5
0
    def test_setting_same_name(self):
        """Setting an already existing title should pass the validator."""

        db.session.add(
            models.CustomAttributeDefinition(
                title="my custom attribute title",
                definition_type="section",
                attribute_type="Text",
            ))
        db.session.commit()
        cad = models.CustomAttributeDefinition.query.first()
        cad.title = "my custom attribute title"
        cad.attribute_type = "Rich Text"
        db.session.commit()
        cad = models.CustomAttributeDefinition.query.first()
        self.assertEqual(cad.title, "my custom attribute title")
        self.assertEqual(cad.attribute_type, "Rich Text")