当前位置: 首页>>代码示例>>Python>>正文


Python Course.full_clean方法代码示例

本文整理汇总了Python中models.Course.full_clean方法的典型用法代码示例。如果您正苦于以下问题:Python Course.full_clean方法的具体用法?Python Course.full_clean怎么用?Python Course.full_clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Course的用法示例。


在下文中一共展示了Course.full_clean方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_id_syntax

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import full_clean [as 别名]
    def test_id_syntax(self):
        with self.assertRaises(DataError):
            with transaction.atomic():
                tis_cc0 = CourseCategory(id='123456789', description='too long')
                tis_cc0.save()

        with self.assertRaises(ValidationError):
            with transaction.atomic():
                tis_cc1 = CourseCategory(id='has spc', description='will not work')
                tis_cc1.full_clean()

        with self.assertRaises(ValidationError):
            with transaction.atomic():
                tis_c0 = Course(id='has space', cat=self.cc0, description='who cares')
                tis_c0.full_clean()

        with self.assertRaises(ValidationError):
            with transaction.atomic():
                tis_lo0 = LearningObjective(id='has space', course=self.c0, description='foobar')
                tis_lo0.full_clean()
开发者ID:trawick,项目名称:edurepo,代码行数:22,代码来源:tests.py

示例2: BasicTests

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import full_clean [as 别名]
class BasicTests(TestCase):

    def setUp(self):
        self.cc0 = CourseCategory(id=dummy_category_id, description=dummy_category_description)
        self.cc0.full_clean()
        self.cc0.save()
        self.c0 = Course(id=dummy_course_id, cat=self.cc0, description=dummy_course_description)
        self.c0.full_clean()
        self.c0.save()
        self.lo0 = LearningObjective(id=dummy_objective_id, course=self.c0, description=dummy_objective_description)
        self.lo0.full_clean()
        self.lo0.save()
        self.ref0 = ReferenceText(learning_objective=self.lo0, text=dummy_reference_text)
        self.ref0.full_clean()
        self.ref0.save()
        self.lo1 = LearningObjective(id=dummy_objective_id_2, course=self.c0, description=dummy_objective_description_2)
        self.lo1.full_clean()
        self.lo1.save()

    def test_import(self):
        for fn in ['00cat.xml', 'M/grade4.xml', 'M/mg4-mc.xml', 'M/mg4-tf.xml']:
            start_import('../../samples/' + fn, 'check', spew=False)
            start_import('../../samples/' + fn, 'import', spew=False)

        objects = CourseCategory.objects.filter(id='K12-SS')
        self.assertEquals(len(objects), 1)
        objects = Course.objects.filter(id='MG4')
        self.assertEquals(len(objects), 1)

        delete_course('MG4', delete=True, noisy=False)
        objects = Course.objects.filter(id='MG4')
        self.assertEquals(len(objects), 0)

    def test_1(self):
        """Basic creation/update of Course and default language"""
        course_id = dummy_course_id_2
        c1 = Course(id=course_id, cat=self.cc0, description=dummy_course_description_2)
        self.assertEquals(c1.language, 'en')
        c1.save()

        desc2 = 'desc2'
        c2 = Course(id=course_id, cat=self.cc0, description=desc2)
        c2.save()

        obj = Course.objects.get(id=course_id)
        self.assertEquals(obj.description, desc2)

        self.assertEquals(obj.language, 'en')

    def test_duplicate_glossary_item(self):
        gi1 = GlossaryItem(term='term01', learning_objective=self.lo0)
        gi1.save()

        gi2 = GlossaryItem(term='term01', learning_objective=self.lo0)
        self.assertRaises(IntegrityError, lambda: gi2.save())

    def test_id_syntax(self):
        with self.assertRaises(DataError):
            with transaction.atomic():
                tis_cc0 = CourseCategory(id='123456789', description='too long')
                tis_cc0.save()

        with self.assertRaises(ValidationError):
            with transaction.atomic():
                tis_cc1 = CourseCategory(id='has spc', description='will not work')
                tis_cc1.full_clean()

        with self.assertRaises(ValidationError):
            with transaction.atomic():
                tis_c0 = Course(id='has space', cat=self.cc0, description='who cares')
                tis_c0.full_clean()

        with self.assertRaises(ValidationError):
            with transaction.atomic():
                tis_lo0 = LearningObjective(id='has space', course=self.c0, description='foobar')
                tis_lo0.full_clean()

    def test_multiple_choice_constraints(self):
        tmcc_1 = MultipleChoiceItem(learning_objective=self.lo0,
                                    question='ABC?',
                                    choice1='xxx',
                                    choice2='yyy',
                                    type=1,
                                    ans=1)
        tmcc_1.full_clean()
        self.assertEqual(tmcc_1.language, 'en', 'Language did not default to "en"')

        # bad value for type
        with self.assertRaises(ValidationError):
            with transaction.atomic():
                tmcc_2 = MultipleChoiceItem(learning_objective=self.lo0,
                                            question='ABC?',
                                            choice1='xxx',
                                            choice2='yyy',
                                            type=7,
                                            ans=1)
                tmcc_2.full_clean()

        # question too long
        with self.assertRaises(ValidationError):
#.........这里部分代码省略.........
开发者ID:trawick,项目名称:edurepo,代码行数:103,代码来源:tests.py


注:本文中的models.Course.full_clean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。