Refs #24121 -- Added __repr__() to ChangeList and BaseStorage.

This commit is contained in:
saeedblanchette 2021-05-31 03:56:08 +01:00 committed by Mariusz Felisiak
parent ecf8af7935
commit 7dd502b0e1
4 changed files with 25 additions and 0 deletions

View File

@ -108,6 +108,13 @@ class ChangeList:
self.title = title % self.opts.verbose_name
self.pk_attname = self.lookup_opts.pk.attname
def __repr__(self):
return '<%s: model=%s model_admin=%s>' % (
self.__class__.__qualname__,
self.model.__qualname__,
self.model_admin.__class__.__qualname__,
)
def get_filters_params(self, params=None):
"""
Return all params except IGNORED_PARAMS.

View File

@ -69,6 +69,9 @@ class BaseStorage:
def __contains__(self, item):
return item in self._loaded_messages or item in self._queued_messages
def __repr__(self):
return f'<{self.__class__.__qualname__}: request={self.request!r}>'
@property
def _loaded_messages(self):
"""

View File

@ -67,6 +67,13 @@ class ChangeListTests(TestCase):
request.user = user
return request
def test_repr(self):
m = ChildAdmin(Child, custom_site)
request = self.factory.get('/child/')
request.user = self.superuser
cl = m.get_changelist_instance(request)
self.assertEqual(repr(cl), '<ChangeList: model=Child model_admin=ChildAdmin>')
def test_specified_ordering_by_f_expression(self):
class OrderedByFBandAdmin(admin.ModelAdmin):
list_display = ['name', 'genres', 'nr_of_members']

View File

@ -88,6 +88,14 @@ class BaseTests:
storage._loaded_data = data or []
return storage
def test_repr(self):
request = self.get_request()
storage = self.storage_class(request)
self.assertEqual(
repr(storage),
f'<{self.storage_class.__qualname__}: request=<HttpRequest>>',
)
def test_add(self):
storage = self.get_storage()
self.assertFalse(storage.added_new)