pull/6273/merge
Robert Rollins 2020-09-02 22:12:59 +01:00 zatwierdzone przez Andy Babic
rodzic e404f83cd1
commit 2ceefcf7bc
5 zmienionych plików z 191 dodań i 16 usunięć

Wyświetl plik

@ -36,11 +36,31 @@ class TestCollectionsIndexView(TestCase, WagtailTestUtils):
root_collection = Collection.get_first_root_node()
root_collection.add_child(name="Milk")
root_collection.add_child(name="Bread")
root_collection.add_child(name="Avacado")
root_collection.add_child(name="Avocado")
response = self.get()
# Note that the Collections have been automatically sorted by name.
self.assertEqual(
[collection.name for collection in response.context['object_list']],
['Avacado', 'Bread', 'Milk'])
['Avocado', 'Bread', 'Milk'])
def test_nested_ordering(self):
root_collection = Collection.get_first_root_node()
vegetables = root_collection.add_child(name="Vegetable")
vegetables.add_child(name="Spinach")
vegetables.add_child(name="Cucumber")
animals = root_collection.add_child(name="Animal")
animals.add_child(name="Dog")
animals.add_child(name="Cat")
response = self.get()
# Note that while we added the collections at level 1 in reverse-alpha order, they come back out in alpha order.
# And we added the Collections at level 2 in reverse-alpha order as well, but they were also alphabetized
# within their respective trees. This is the result of setting Collection.node_order_by = ['name'].
self.assertEqual(
[collection.name for collection in response.context['object_list']],
['Animal', 'Cat', 'Dog', 'Vegetable', 'Cucumber', 'Spinach'])
class TestAddCollection(TestCase, WagtailTestUtils):
@ -80,6 +100,9 @@ class TestEditCollection(TestCase, WagtailTestUtils):
self.login()
self.root_collection = Collection.get_first_root_node()
self.collection = self.root_collection.add_child(name="Holiday snaps")
self.l1 = self.root_collection.add_child(name="Level 1")
self.l2 = self.l1.add_child(name="Level 2")
self.l3 = self.l2.add_child(name="Level 3")
def get(self, params={}, collection_id=None):
return self.client.get(
@ -105,10 +128,22 @@ class TestEditCollection(TestCase, WagtailTestUtils):
response = self.get(collection_id=100000)
self.assertEqual(response.status_code, 404)
def test_move_collection(self):
self.post({'name': "Level 2", 'parent': self.root_collection.pk}, self.l2.pk)
self.assertEqual(
Collection.objects.get(pk=self.l2.pk).get_parent().pk,
self.root_collection.pk,
)
def test_cannot_move_parent_collection_to_descendant(self):
self.post({'name': "Level 2", 'parent': self.l3.pk}, self.l2.pk)
self.assertEqual(
Collection.objects.get(pk=self.l2.pk).get_parent().pk,
self.l1.pk
)
def test_post(self):
response = self.post({
'name': "Skiing photos",
})
response = self.post({'name': "Skiing photos"}, self.collection.pk)
# Should redirect back to index
self.assertRedirects(response, reverse('wagtailadmin_collections:index'))
@ -160,6 +195,13 @@ class TestDeleteCollection(TestCase, WagtailTestUtils):
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/collections/delete_not_empty.html')
def test_get_collection_with_descendent(self):
self.collection.add_child(instance=Collection(name='Test collection'))
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/collections/delete_not_empty.html')
def test_post(self):
response = self.post()
@ -180,3 +222,12 @@ class TestDeleteCollection(TestCase, WagtailTestUtils):
# Check that the collection was not deleted
self.assertTrue(Collection.objects.get(id=self.collection.id))
def test_post_collection_with_descendant(self):
self.collection.add_child(instance=Collection(name='Test collection'))
response = self.post()
self.assertEqual(response.status_code, 403)
# Check that the collection was not deleted
self.assertTrue(Collection.objects.get(id=self.collection.id))

Wyświetl plik

@ -12,6 +12,28 @@ class TestCollectionTreeOperations(TestCase):
self.evil_plans_collection = self.root_collection.add_child(
name="Evil plans"
)
# self.holiday_photos_collection's path has been updated out from under it by the addition of a sibling with
# an alphabetically earlier name (due to Collection.node_order_by = ['name']), so we need to refresh it from
# the DB to get the new path.
self.holiday_photos_collection.refresh_from_db()
def test_alphabetic_sorting(self):
old_evil_path = self.evil_plans_collection.path
old_holiday_path = self.holiday_photos_collection.path
# Add a child to Root that has an earlier name than "Evil plans" and "Holiday Photos".
alpha_collection = self.root_collection.add_child(name="Alpha")
# Take note that self.evil_plans_collection and self.holiday_photos_collection have not yet changed.
self.assertEqual(old_evil_path, self.evil_plans_collection.path)
self.assertEqual(old_holiday_path, self.holiday_photos_collection.path)
# Update the two Collections from the database.
self.evil_plans_collection.refresh_from_db()
self.holiday_photos_collection.refresh_from_db()
# Confirm that the "Evil plans" and "Holiday photos" paths have changed in the DB due to adding "Alpha".
self.assertNotEqual(old_evil_path, self.evil_plans_collection.path)
self.assertNotEqual(old_holiday_path, self.holiday_photos_collection.path)
# Confirm that Alpha is before Evil Plans and Holiday Photos, due to Collection.node_order_by = ['name'].
self.assertLess(alpha_collection.path, self.evil_plans_collection.path)
self.assertLess(alpha_collection.path, self.holiday_photos_collection.path)
def test_get_ancestors(self):
self.assertEqual(
@ -26,21 +48,21 @@ class TestCollectionTreeOperations(TestCase):
def test_get_descendants(self):
self.assertEqual(
list(self.root_collection.get_descendants().order_by('path')),
[self.holiday_photos_collection, self.evil_plans_collection]
[self.evil_plans_collection, self.holiday_photos_collection]
)
self.assertEqual(
list(self.root_collection.get_descendants(inclusive=True).order_by('path')),
[
self.root_collection,
self.holiday_photos_collection,
self.evil_plans_collection
self.evil_plans_collection,
self.holiday_photos_collection
]
)
def test_get_siblings(self):
self.assertEqual(
list(self.holiday_photos_collection.get_siblings().order_by('path')),
[self.holiday_photos_collection, self.evil_plans_collection]
[self.evil_plans_collection, self.holiday_photos_collection]
)
self.assertEqual(
list(self.holiday_photos_collection.get_siblings(inclusive=False).order_by('path')),
@ -50,19 +72,19 @@ class TestCollectionTreeOperations(TestCase):
def test_get_next_siblings(self):
self.assertEqual(
list(
self.holiday_photos_collection.get_next_siblings().order_by('path')
self.evil_plans_collection.get_next_siblings().order_by('path')
),
[self.evil_plans_collection]
[self.holiday_photos_collection]
)
self.assertEqual(
list(
self.holiday_photos_collection.get_next_siblings(inclusive=True).order_by('path')
),
[self.holiday_photos_collection, self.evil_plans_collection]
[self.holiday_photos_collection]
)
self.assertEqual(
list(
self.evil_plans_collection.get_next_siblings().order_by('path')
self.holiday_photos_collection.get_next_siblings().order_by('path')
),
[]
)
@ -72,17 +94,17 @@ class TestCollectionTreeOperations(TestCase):
list(
self.holiday_photos_collection.get_prev_siblings().order_by('path')
),
[]
[self.evil_plans_collection]
)
self.assertEqual(
list(
self.evil_plans_collection.get_prev_siblings().order_by('path')
),
[self.holiday_photos_collection]
[]
)
self.assertEqual(
list(
self.evil_plans_collection.get_prev_siblings(inclusive=True).order_by('path')
),
[self.holiday_photos_collection, self.evil_plans_collection]
[self.evil_plans_collection]
)

Wyświetl plik

@ -97,6 +97,15 @@ class TestDocumentIndexView(TestCase, WagtailTestUtils):
[collection.name for collection in response.context['collections']],
['Root', 'Evil plans', 'Good plans'])
def test_collection_nesting(self):
root_collection = Collection.get_first_root_node()
evil_plans = root_collection.add_child(name="Evil plans")
evil_plans.add_child(name="Eviler plans")
response = self.client.get(reverse('wagtaildocs:index'))
# "Eviler Plans" should be prefixed with &#x21b3 (↳) and 4 non-breaking spaces.
self.assertContains(response, '    &#x21b3 Eviler plans')
class TestDocumentAddView(TestCase, WagtailTestUtils):
def setUp(self):
@ -128,6 +137,15 @@ class TestDocumentAddView(TestCase, WagtailTestUtils):
self.assertContains(response, '<label for="id_collection">')
self.assertContains(response, "Evil plans")
def test_get_with_collection_nesting(self):
root_collection = Collection.get_first_root_node()
evil_plans = root_collection.add_child(name="Evil plans")
evil_plans.add_child(name="Eviler plans")
response = self.client.get(reverse('wagtaildocs:add'))
# "Eviler Plans" should be prefixed with &#x21b3 (↳) and 4 non-breaking spaces.
self.assertContains(response, '&nbsp;&nbsp;&nbsp;&nbsp;&#x21b3 Eviler plans')
@override_settings(WAGTAILDOCS_DOCUMENT_MODEL='tests.CustomDocument')
def test_get_with_custom_document_model(self):
response = self.client.get(reverse('wagtaildocs:add'))
@ -260,6 +278,16 @@ class TestDocumentAddViewWithLimitedCollectionPermissions(TestCase, WagtailTestU
# is displayed on the form
self.assertNotContains(response, '<label for="id_collection">')
def test_get_with_collection_nesting(self):
self.evil_plans_collection.add_child(name="Eviler plans")
response = self.client.get(reverse('wagtaildocs:add'))
self.assertEqual(response.status_code, 200)
# Unlike the above test, the user should have access to multiple Collections.
self.assertContains(response, '<label for="id_collection">')
# "Eviler Plans" should be prefixed with &#x21b3 (↳) and 4 non-breaking spaces.
self.assertContains(response, '&nbsp;&nbsp;&nbsp;&nbsp;&#x21b3 Eviler plans')
def test_post(self):
# Build a fake file
fake_file = get_test_document_file()
@ -307,6 +335,15 @@ class TestDocumentEditView(TestCase, WagtailTestUtils):
# definitions are being respected)
self.assertNotContains(response, 'wagtailadmin/js/draftail.js')
def test_simple_with_collection_nesting(self):
root_collection = Collection.get_first_root_node()
evil_plans = root_collection.add_child(name="Evil plans")
evil_plans.add_child(name="Eviler plans")
response = self.client.get(reverse('wagtaildocs:edit', args=(self.document.id,)))
# "Eviler Plans" should be prefixed with &#x21b3 (↳) and 4 non-breaking spaces.
self.assertContains(response, '&nbsp;&nbsp;&nbsp;&nbsp;&#x21b3 Eviler plans')
def test_post(self):
# Build a fake file
fake_file = get_test_document_file()
@ -825,6 +862,15 @@ class TestDocumentChooserView(TestCase, WagtailTestUtils):
# draftail should NOT be a standard JS include on this page
self.assertNotIn('wagtailadmin/js/draftail.js', response_json['html'])
def test_simple_with_collection_nesting(self):
root_collection = Collection.get_first_root_node()
evil_plans = root_collection.add_child(name="Evil plans")
evil_plans.add_child(name="Eviler plans")
response = self.client.get(reverse('wagtaildocs:chooser'))
# "Eviler Plans" should be prefixed with &#x21b3 (↳) and 4 non-breaking spaces.
self.assertContains(response, '&nbsp;&nbsp;&nbsp;&nbsp;&#x21b3 Eviler plans')
@override_settings(WAGTAILDOCS_DOCUMENT_MODEL='tests.CustomDocument')
def test_with_custom_document_model(self):
response = self.client.get(reverse('wagtaildocs:chooser'))

Wyświetl plik

@ -86,6 +86,15 @@ class TestImageIndexView(TestCase, WagtailTestUtils):
[collection.name for collection in response.context['collections']],
['Root', 'Evil plans', 'Good plans'])
def test_collection_nesting(self):
root_collection = Collection.get_first_root_node()
evil_plans = root_collection.add_child(name="Evil plans")
evil_plans.add_child(name="Eviler plans")
response = self.get()
# "Eviler Plans" should be prefixed with &#x21b3 (↳) and 4 non-breaking spaces.
self.assertContains(response, '&nbsp;&nbsp;&nbsp;&nbsp;&#x21b3 Eviler plans')
def test_tags(self):
image_two_tags = Image.objects.create(
title="Test image with two tags",
@ -198,6 +207,15 @@ class TestImageAddView(TestCase, WagtailTestUtils):
self.assertContains(response, '<label for="id_collection">')
self.assertContains(response, "Evil plans")
def test_get_with_collection_nesting(self):
root_collection = Collection.get_first_root_node()
evil_plans = root_collection.add_child(name="Evil plans")
evil_plans.add_child(name="Eviler plans")
response = self.get()
# "Eviler Plans" should be prefixed with &#x21b3 (↳) and 4 non-breaking spaces.
self.assertContains(response, '&nbsp;&nbsp;&nbsp;&nbsp;&#x21b3 Eviler plans')
@override_settings(WAGTAILIMAGES_IMAGE_MODEL='tests.CustomImage')
def test_get_with_custom_image_model(self):
response = self.get()
@ -396,6 +414,16 @@ class TestImageAddViewWithLimitedCollectionPermissions(TestCase, WagtailTestUtil
# is displayed on the form
self.assertNotContains(response, '<label for="id_collection">')
def test_get_with_collection_nesting(self):
self.evil_plans_collection.add_child(name="Eviler plans")
response = self.get()
self.assertEqual(response.status_code, 200)
# Unlike the above test, the user should have access to multiple Collections.
self.assertContains(response, '<label for="id_collection">')
# "Eviler Plans" should be prefixed with &#x21b3 (↳) and 4 non-breaking spaces.
self.assertContains(response, '&nbsp;&nbsp;&nbsp;&nbsp;&#x21b3 Eviler plans')
def test_add(self):
response = self.post({
'title': "Test image",
@ -449,6 +477,15 @@ class TestImageEditView(TestCase, WagtailTestUtils):
# definitions are being respected)
self.assertNotContains(response, 'wagtailadmin/js/draftail.js')
def test_simple_with_collection_nesting(self):
root_collection = Collection.get_first_root_node()
evil_plans = root_collection.add_child(name="Evil plans")
evil_plans.add_child(name="Eviler plans")
response = self.get()
# "Eviler Plans" should be prefixed with &#x21b3 (↳) and 4 non-breaking spaces.
self.assertContains(response, '&nbsp;&nbsp;&nbsp;&nbsp;&#x21b3 Eviler plans')
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_with_usage_count(self):
response = self.get()
@ -755,6 +792,15 @@ class TestImageChooserView(TestCase, WagtailTestUtils):
# draftail should NOT be a standard JS include on this page
self.assertNotIn('wagtailadmin/js/draftail.js', response_json['html'])
def test_simple_with_collection_nesting(self):
root_collection = Collection.get_first_root_node()
evil_plans = root_collection.add_child(name="Evil plans")
evil_plans.add_child(name="Eviler plans")
response = self.get()
# "Eviler Plans" should be prefixed with &#x21b3 (↳) and 4 non-breaking spaces.
self.assertContains(response, '&nbsp;&nbsp;&nbsp;&nbsp;&#x21b3 Eviler plans')
@override_settings(WAGTAILIMAGES_IMAGE_MODEL='tests.CustomImage')
def test_with_custom_image_model(self):
response = self.get()

Wyświetl plik

@ -1424,6 +1424,16 @@ class TestGroupEditView(TestCase, WagtailTestUtils):
str(response.content),
allow_extra_attrs=True)
def test_group_edit_displays_collection_nesting(self):
# Add a child collection to Evil Plans.
self.evil_plans_collection.add_child(instance=Collection(name='Eviler Plans'))
response = self.get()
# "Eviler Plans" should be prefixed with &#x21b3 (↳) and exactly 4 non-breaking spaces
# after the <option> tag.
# There are 3 instances because it appears twice in the form template javascript.
self.assertContains(response, '>&nbsp;&nbsp;&nbsp;&nbsp;&#x21b3 Eviler Plans', count=3)
def test_group_edit_loads_with_page_permissions_shown(self):
# The test group has one page permission to begin with
self.assertEqual(self.test_group.page_permissions.count(), 1)