Add tests for creating/editing pages with parental M2M relations

pull/3332/head
Matt Westcott 2017-01-27 16:05:31 +00:00
rodzic 3ba5675bf3
commit c63f6d7922
1 zmienionych plików z 147 dodań i 1 usunięć

Wyświetl plik

@ -21,7 +21,7 @@ from django.utils.dateparse import parse_date
from wagtail.tests.testapp.models import (
EVENT_AUDIENCE_CHOICES, Advert, AdvertPlacement, BusinessChild, BusinessIndex, BusinessSubIndex,
DefaultStreamPage,
DefaultStreamPage, EventCategory,
EventPage, EventPageCarouselItem, FilePage, SimplePage, SingleEventPage, SingletonPage,
StandardChild, StandardIndex, TaggedPage)
from wagtail.tests.utils import WagtailTestUtils
@ -3727,3 +3727,149 @@ class TestIssue2994(TestCase, WagtailTestUtils):
new_page = DefaultStreamPage.objects.get(slug='issue-2994-test')
self.assertEqual(1, len(new_page.body))
self.assertEqual('hello world', new_page.body[0].value)
class TestParentalM2M(TestCase, WagtailTestUtils):
fixtures = ['test.json']
def setUp(self):
self.events_index = Page.objects.get(url_path='/home/events/')
self.christmas_page = Page.objects.get(url_path='/home/events/christmas/')
self.user = self.login()
self.holiday_category = EventCategory.objects.create(name='Holiday')
self.men_with_beards_category = EventCategory.objects.create(name='Men with beards')
def test_create_and_save(self):
post_data = {
'title': "Presidents' Day",
'date_from': "2017-02-20",
'slug': "presidents-day",
'audience': "public",
'location': "America",
'cost': "$1",
'carousel_items-TOTAL_FORMS': 0,
'carousel_items-INITIAL_FORMS': 0,
'carousel_items-MIN_NUM_FORMS': 0,
'carousel_items-MAX_NUM_FORMS': 0,
'speakers-TOTAL_FORMS': 0,
'speakers-INITIAL_FORMS': 0,
'speakers-MIN_NUM_FORMS': 0,
'speakers-MAX_NUM_FORMS': 0,
'related_links-TOTAL_FORMS': 0,
'related_links-INITIAL_FORMS': 0,
'related_links-MIN_NUM_FORMS': 0,
'related_links-MAX_NUM_FORMS': 0,
'categories': [self.holiday_category.id, self.men_with_beards_category.id]
}
response = self.client.post(
reverse('wagtailadmin_pages:add', args=('tests', 'eventpage', self.events_index.id)),
post_data
)
created_page = EventPage.objects.get(url_path='/home/events/presidents-day/')
self.assertRedirects(response, reverse('wagtailadmin_pages:edit', args=(created_page.id, )))
created_revision = created_page.get_latest_revision_as_page()
self.assertIn(self.holiday_category, created_revision.categories.all())
self.assertIn(self.men_with_beards_category, created_revision.categories.all())
def test_create_and_publish(self):
post_data = {
'action-publish': "Publish",
'title': "Presidents' Day",
'date_from': "2017-02-20",
'slug': "presidents-day",
'audience': "public",
'location': "America",
'cost': "$1",
'carousel_items-TOTAL_FORMS': 0,
'carousel_items-INITIAL_FORMS': 0,
'carousel_items-MIN_NUM_FORMS': 0,
'carousel_items-MAX_NUM_FORMS': 0,
'speakers-TOTAL_FORMS': 0,
'speakers-INITIAL_FORMS': 0,
'speakers-MIN_NUM_FORMS': 0,
'speakers-MAX_NUM_FORMS': 0,
'related_links-TOTAL_FORMS': 0,
'related_links-INITIAL_FORMS': 0,
'related_links-MIN_NUM_FORMS': 0,
'related_links-MAX_NUM_FORMS': 0,
'categories': [self.holiday_category.id, self.men_with_beards_category.id]
}
response = self.client.post(
reverse('wagtailadmin_pages:add', args=('tests', 'eventpage', self.events_index.id)),
post_data
)
self.assertRedirects(response, reverse('wagtailadmin_explore', args=(self.events_index.id, )))
created_page = EventPage.objects.get(url_path='/home/events/presidents-day/')
self.assertIn(self.holiday_category, created_page.categories.all())
self.assertIn(self.men_with_beards_category, created_page.categories.all())
def test_edit_and_save(self):
post_data = {
'title': "Christmas",
'date_from': "2017-12-25",
'slug': "christmas",
'audience': "public",
'location': "The North Pole",
'cost': "Free",
'carousel_items-TOTAL_FORMS': 0,
'carousel_items-INITIAL_FORMS': 0,
'carousel_items-MIN_NUM_FORMS': 0,
'carousel_items-MAX_NUM_FORMS': 0,
'speakers-TOTAL_FORMS': 0,
'speakers-INITIAL_FORMS': 0,
'speakers-MIN_NUM_FORMS': 0,
'speakers-MAX_NUM_FORMS': 0,
'related_links-TOTAL_FORMS': 0,
'related_links-INITIAL_FORMS': 0,
'related_links-MIN_NUM_FORMS': 0,
'related_links-MAX_NUM_FORMS': 0,
'categories': [self.holiday_category.id, self.men_with_beards_category.id]
}
response = self.client.post(
reverse('wagtailadmin_pages:edit', args=(self.christmas_page.id, )),
post_data
)
self.assertRedirects(response, reverse('wagtailadmin_pages:edit', args=(self.christmas_page.id, )))
updated_page = EventPage.objects.get(id=self.christmas_page.id)
created_revision = updated_page.get_latest_revision_as_page()
self.assertIn(self.holiday_category, created_revision.categories.all())
self.assertIn(self.men_with_beards_category, created_revision.categories.all())
# no change to live page record yet
self.assertEqual(0, updated_page.categories.count())
def test_edit_and_publish(self):
post_data = {
'action-publish': "Publish",
'title': "Christmas",
'date_from': "2017-12-25",
'slug': "christmas",
'audience': "public",
'location': "The North Pole",
'cost': "Free",
'carousel_items-TOTAL_FORMS': 0,
'carousel_items-INITIAL_FORMS': 0,
'carousel_items-MIN_NUM_FORMS': 0,
'carousel_items-MAX_NUM_FORMS': 0,
'speakers-TOTAL_FORMS': 0,
'speakers-INITIAL_FORMS': 0,
'speakers-MIN_NUM_FORMS': 0,
'speakers-MAX_NUM_FORMS': 0,
'related_links-TOTAL_FORMS': 0,
'related_links-INITIAL_FORMS': 0,
'related_links-MIN_NUM_FORMS': 0,
'related_links-MAX_NUM_FORMS': 0,
'categories': [self.holiday_category.id, self.men_with_beards_category.id]
}
response = self.client.post(
reverse('wagtailadmin_pages:edit', args=(self.christmas_page.id, )),
post_data
)
self.assertRedirects(response, reverse('wagtailadmin_explore', args=(self.events_index.id, )))
updated_page = EventPage.objects.get(id=self.christmas_page.id)
self.assertEqual(2, updated_page.categories.count())
self.assertIn(self.holiday_category, updated_page.categories.all())
self.assertIn(self.men_with_beards_category, updated_page.categories.all())