コード例 #1
0
    def test_lazy_model(self):
        class InlineModelAdmin(LazyChoiceInlineModelAdminMixin, BaseInlineModelAdmin):
            lazy_model = Book
            model = Chapter

        errors = run_model_admin_check(InlineModelAdmin, model=Book)
        self.assertEqual(errors, [])
コード例 #2
0
    def test_missing_lazy_model(self):
        class InlineModelAdmin(LazyChoiceInlineModelAdminMixin, BaseInlineModelAdmin):
            model = Chapter

        errors = run_model_admin_check(InlineModelAdmin, model=Book)
        expected = [
            checks.Error(
                "The value of 'lazy_model' must be defined.",
                hint=None,
                obj=InlineModelAdmin,
                id='lazychoices.E101',
            ),
        ]
        self.assertEqual(errors, expected)
コード例 #3
0
    def test_invalid_lazy_model(self):
        class InlineModelAdmin(LazyChoiceInlineModelAdminMixin, BaseInlineModelAdmin):
            lazy_model = Chapter
            model = Chapter

        errors = run_model_admin_check(InlineModelAdmin, model=Book)
        expected = [
            checks.Error(
                "The value of 'lazy_model' must inherit from 'LazyChoiceModelMixin'.",
                hint=None,
                obj=InlineModelAdmin,
                id='lazychoices.E102',
            ),
        ]
        self.assertEqual(errors, expected)