From b2b962610aedeb3f67c4f5a00b5a3f45e4a41625 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Wed, 3 Aug 2016 09:19:45 +0200 Subject: [PATCH] Add tests for category parent filtering --- tests/test_models.py | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index 81e169d..b4d25f7 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -120,11 +120,47 @@ class AdminTest(BaseTest): # Changeview is 'normal', with a few preselected items response = post_admin.change_view(request, str(self.category_1.pk)) - # response.render() - # print(response.content.decode('utf-8')) self.assertContains(response, '') self.assertContains(response, '' % self.app_config_1.pk) + def test_admin_category_parents(self): + category1 = BlogCategory.objects.create(name='tree category 1', app_config=self.app_config_1) + category2 = BlogCategory.objects.create(name='tree category 2', parent=category1, app_config=self.app_config_1) + category3 = BlogCategory.objects.create(name='tree category 3', parent=category2, app_config=self.app_config_1) + BlogCategory.objects.create(name='tree category 4', parent=category3, app_config=self.app_config_1) + BlogCategory.objects.create(name='category different branch', app_config=self.app_config_2) + + post_admin = admin.site._registry[BlogCategory] + request = self.get_page_request('/', self.user, r'/en/blog/?app_config=%s' % self.app_config_1.pk, edit=False) + + # Add view shows all the exising categories + response = post_admin.add_view(request) + self.assertContains(response, '') + self.assertContains(response, '') + self.assertContains(response, '') + self.assertContains(response, '') + self.assertContains(response, '') + self.assertNotContains(response, 'category different branch') + + # Changeview hides the children of the current category + response = post_admin.change_view(request, str(category2.pk)) + self.assertContains(response, '') + self.assertContains(response, '') + self.assertNotContains(response, '') + self.assertNotContains(response, '') + self.assertNotContains(response, '') + self.assertNotContains(response, 'category different branch') + + # Test second apphook categories + request = self.get_page_request('/', self.user, r'/en/blog/?app_config=%s' % self.app_config_2.pk, edit=False) + response = post_admin.add_view(request) + self.assertNotContains(response, '') + self.assertNotContains(response, '') + self.assertNotContains(response, '') + self.assertNotContains(response, '') + self.assertNotContains(response, '') + self.assertContains(response, 'category different branch') + def test_admin_fieldsets(self): post_admin = admin.site._registry[Post] request = self.get_page_request('/', self.user_staff, r'/en/blog/?app_config=%s' % self.app_config_1.pk, edit=False)