'Regression tests for #14206: dynamic list_display support.'

def test_dynamic_list_display(self):

    parent = Parent.objects.create(name=u'parent')
    for i in range(10):
        Child.objects.create(name=(u'child    %s' % i), parent=parent)
    user_noparents = self._create_superuser(u'noparents')
    user_parents = self._create_superuser(u'parents')
    m = custom_site._registry[Child]
    request = self._mocked_authenticated_request(u'/child/', user_noparents)
    response = m.changelist_view(request)
    self.assertNotContains(response, u'Parent    object')
    list_display = m.get_list_display(request)
    list_display_links = m.get_list_display_links(request, list_display)
    self.assertEqual(list_display, [u'name', u'age'])
    self.assertEqual(list_display_links, [u'name'])
    m = DynamicListDisplayChildAdmin(Child, admin.site)
    request = self._mocked_authenticated_request(u'/child/', user_parents)
    response = m.changelist_view(request)
    self.assertContains(response, u'Parent    object')
    custom_site.unregister(Child)
    list_display = m.get_list_display(request)
    list_display_links = m.get_list_display_links(request, list_display)
    self.assertEqual(list_display, (u'parent', u'name', u'age'))
    self.assertEqual(list_display_links, [u'parent'])
    custom_site.register(Child, ChildAdmin)
    m = custom_site._registry[Child]
    request = self._mocked_authenticated_request(u'/child/', user_noparents)
    response = m.changelist_view(request)
    self.assertContains(response, u'Parent    object')
