test_deprecation.py 722 B

123456789101112131415161718192021222324
  1. from django.db.models import Count, Func
  2. from django.test import SimpleTestCase
  3. from django.utils.deprecation import RemovedInDjango40Warning
  4. from .models import Employee
  5. class MissingAliasFunc(Func):
  6. template = '1'
  7. def get_group_by_cols(self):
  8. return []
  9. class GetGroupByColsTest(SimpleTestCase):
  10. def test_missing_alias(self):
  11. msg = (
  12. '`alias=None` must be added to the signature of '
  13. 'expressions.test_deprecation.MissingAliasFunc.get_group_by_cols().'
  14. )
  15. with self.assertRaisesMessage(RemovedInDjango40Warning, msg):
  16. Employee.objects.values(
  17. one=MissingAliasFunc(),
  18. ).annotate(cnt=Count('company_ceo_set'))