Allow nested collections
This commit is contained in:
@@ -341,6 +341,53 @@ class CollectionTests(TestCase):
|
||||
self.assertContains(response, '>Section</')
|
||||
self.assertNotContains(response, '>## Section</')
|
||||
|
||||
def test_collection_can_include_collection(self):
|
||||
parent = Collection.objects.create(owner=self.user, title='Parent')
|
||||
child = Collection.objects.create(owner=self.user, title='Child')
|
||||
note = Item.objects.create(owner=self.user, kind=Item.Kind.NOTE, content='## Child note #internal')
|
||||
CollectionSection.objects.create(collection=child, item=note, position=0)
|
||||
manage_url = reverse('collection_manage', args=[parent.id])
|
||||
|
||||
response = self.client.post(manage_url, {'action': 'add_collection', 'collection_id': child.id})
|
||||
|
||||
self.assertRedirects(response, manage_url)
|
||||
self.assertTrue(parent.sections.filter(sub_collection=child).exists())
|
||||
response = self.client.get(parent.get_absolute_url())
|
||||
self.assertContains(response, '<h2>Child</h2>', html=True)
|
||||
self.assertContains(response, '<h3>Child note</h3>', html=True)
|
||||
self.assertNotContains(response, '#internal')
|
||||
|
||||
def test_collection_loop_is_rejected(self):
|
||||
parent = Collection.objects.create(owner=self.user, title='Parent')
|
||||
child = Collection.objects.create(owner=self.user, title='Child')
|
||||
CollectionSection.objects.create(collection=parent, sub_collection=child, position=0)
|
||||
manage_url = reverse('collection_manage', args=[child.id])
|
||||
|
||||
response = self.client.post(manage_url, {'action': 'add_collection', 'collection_id': parent.id}, follow=True)
|
||||
|
||||
self.assertContains(response, 'collection loop')
|
||||
self.assertFalse(child.sections.filter(sub_collection=parent).exists())
|
||||
|
||||
def test_public_collection_cannot_include_private_collection(self):
|
||||
parent = Collection.objects.create(owner=self.user, title='Parent', visibility=Item.Visibility.PUBLIC)
|
||||
child = Collection.objects.create(owner=self.user, title='Child', visibility=Item.Visibility.PRIVATE)
|
||||
manage_url = reverse('collection_manage', args=[parent.id])
|
||||
|
||||
response = self.client.post(manage_url, {'action': 'add_collection', 'collection_id': child.id}, follow=True)
|
||||
|
||||
self.assertContains(response, 'incompatible visibility')
|
||||
self.assertFalse(parent.sections.filter(sub_collection=child).exists())
|
||||
|
||||
def test_private_collection_can_include_public_collection(self):
|
||||
parent = Collection.objects.create(owner=self.user, title='Parent', visibility=Item.Visibility.PRIVATE)
|
||||
child = Collection.objects.create(owner=self.user, title='Child', visibility=Item.Visibility.PUBLIC)
|
||||
manage_url = reverse('collection_manage', args=[parent.id])
|
||||
|
||||
response = self.client.post(manage_url, {'action': 'add_collection', 'collection_id': child.id})
|
||||
|
||||
self.assertRedirects(response, manage_url)
|
||||
self.assertTrue(parent.sections.filter(sub_collection=child).exists())
|
||||
|
||||
def test_public_collection_is_visible_without_login(self):
|
||||
collection = Collection.objects.create(owner=self.user, title='Public', visibility=Item.Visibility.PUBLIC)
|
||||
self.client.logout()
|
||||
|
||||
Reference in New Issue
Block a user