Add tests for snippet edit handler form classes

pull/2405/merge
Tim Heap 2016-03-29 06:34:25 +02:00 zatwierdzone przez Karl Hobley
rodzic c823ace6a1
commit 8b6f84d899
4 zmienionych plików z 65 dodań i 1 usunięć

Wyświetl plik

@ -0,0 +1,7 @@
from wagtail.wagtailadmin.forms import WagtailAdminModelForm
class FancySnippetForm(WagtailAdminModelForm):
"""
A custom form class for FancySnippets in the admin
"""

Wyświetl plik

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-29 04:28
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('snippetstests', '0002_searchablesnippet'),
]
operations = [
migrations.CreateModel(
name='FancySnippet',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.CreateModel(
name='StandardSnippet',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.CharField(max_length=255)),
],
),
]

Wyświetl plik

@ -4,6 +4,8 @@ from django.utils.encoding import python_2_unicode_compatible
from wagtail.wagtailsearch import index
from wagtail.wagtailsnippets.models import register_snippet
from .forms import FancySnippetForm
# AlphaSnippet and ZuluSnippet are for testing ordering of
# snippets when registering. They are named as such to ensure
@ -52,3 +54,13 @@ class SearchableSnippet(models.Model, index.Indexed):
def __str__(self):
return self.text
@register_snippet
class StandardSnippet(models.Model):
text = models.CharField(max_length=255)
@register_snippet
class FancySnippet(models.Model):
base_form_class = FancySnippetForm

Wyświetl plik

@ -6,10 +6,13 @@ from django.test import TestCase
from django.test.utils import override_settings
from taggit.models import Tag
from wagtail.tests.snippets.forms import FancySnippetForm
from wagtail.tests.snippets.models import (
AlphaSnippet, RegisterDecorator, RegisterFunction, SearchableSnippet, ZuluSnippet)
AlphaSnippet, FancySnippet, RegisterDecorator, RegisterFunction, SearchableSnippet,
StandardSnippet, ZuluSnippet)
from wagtail.tests.testapp.models import Advert, AdvertWithTabbedInterface, SnippetChooserModel
from wagtail.tests.utils import WagtailTestUtils
from wagtail.wagtailadmin.forms import WagtailAdminModelForm
from wagtail.wagtailcore.models import Page
from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel
from wagtail.wagtailsnippets.models import SNIPPET_MODELS, register_snippet
@ -628,3 +631,17 @@ class TestDeleteOnlyPermissions(TestCase, WagtailTestUtils):
response = self.client.get(reverse('wagtailsnippets:delete', args=('tests', 'advert', self.test_snippet.id, )))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailsnippets/snippets/confirm_delete.html')
class TestSnippetEditHandlers(TestCase, WagtailTestUtils):
def test_standard_edit_handler(self):
edit_handler_class = get_snippet_edit_handler(StandardSnippet)
form_class = edit_handler_class.get_form_class(StandardSnippet)
self.assertTrue(issubclass(form_class, WagtailAdminModelForm))
self.assertFalse(issubclass(form_class, FancySnippetForm))
def test_fancy_edit_handler(self):
edit_handler_class = get_snippet_edit_handler(FancySnippet)
form_class = edit_handler_class.get_form_class(FancySnippet)
self.assertTrue(issubclass(form_class, WagtailAdminModelForm))
self.assertTrue(issubclass(form_class, FancySnippetForm))