def test_record_count(self): case = CaseFactory() LetterFactory.create_batch(size=25, case=case) admin_obj = CaseAdmin(Case, AdminSite()) request = RequestFactory().get(reverse_lazy('admin:cases_case_changelist')) request.user = UserFactory(is_staff=True, is_superuser=True) qs = admin_obj.get_queryset(request) obj = qs.get(pk=case.pk) self.assertTrue(hasattr(obj, 'record_count')) self.assertEqual(admin_obj.record_count(obj), 25)
class CaseAdminTestCase(AdminTestCaseMixin, TestCase): user_factory_cls = UserFactory factory_cls = CaseFactory model = Case def setUp(self): self.site = AdminSite() super().setUp() def assertIsValid(self, model_admin, model): # See django/tests/modeladmin/tests.py#L602 admin_obj = model_admin(model, self.site) if django.VERSION > (1, 9): errors = admin_obj.check() else: errors = admin_obj.check(model) expected = [] self.assertEqual(errors, expected) def test_is_valid(self): self.assertIsValid(CaseAdmin, Case) def test_record_count(self): case = CaseFactory() LetterFactory.create_batch(size=25, case=case) admin_obj = CaseAdmin(Case, AdminSite()) request = RequestFactory().get( reverse_lazy("admin:cases_case_changelist")) request.user = UserFactory(is_staff=True, is_superuser=True) qs = admin_obj.get_queryset(request) obj = qs.get(pk=case.pk) self.assertTrue(hasattr(obj, "record_count")) self.assertEqual(admin_obj.record_count(obj), 25)
def test_with_record_count(self): obj = CaseFactory() LetterFactory.create_batch(size=25, case=obj) self.assertEqual( Case.objects.filter( pk=obj.pk).with_record_count().get().record_count, 25)
def test_with_record_count(self): obj = CaseFactory() LetterFactory.create_batch(size=25, case=obj) self.assertEqual(Case.objects.filter(pk=obj.pk).with_record_count().get().record_count, 25)