test_window.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from django.db.models.functions import Lag, Lead, NthValue, Ntile
  2. from django.test import SimpleTestCase
  3. class ValidationTests(SimpleTestCase):
  4. def test_nth_negative_nth_value(self):
  5. msg = 'NthValue requires a positive integer as for nth'
  6. with self.assertRaisesMessage(ValueError, msg):
  7. NthValue(expression='salary', nth=-1)
  8. def test_nth_null_expression(self):
  9. msg = 'NthValue requires a non-null source expression'
  10. with self.assertRaisesMessage(ValueError, msg):
  11. NthValue(expression=None)
  12. def test_lag_negative_offset(self):
  13. msg = 'Lag requires a positive integer for the offset'
  14. with self.assertRaisesMessage(ValueError, msg):
  15. Lag(expression='salary', offset=-1)
  16. def test_lead_negative_offset(self):
  17. msg = 'Lead requires a positive integer for the offset'
  18. with self.assertRaisesMessage(ValueError, msg):
  19. Lead(expression='salary', offset=-1)
  20. def test_null_source_lead(self):
  21. msg = 'Lead requires a non-null source expression'
  22. with self.assertRaisesMessage(ValueError, msg):
  23. Lead(expression=None)
  24. def test_null_source_lag(self):
  25. msg = 'Lag requires a non-null source expression'
  26. with self.assertRaisesMessage(ValueError, msg):
  27. Lag(expression=None)
  28. def test_negative_num_buckets_ntile(self):
  29. msg = 'num_buckets must be greater than 0'
  30. with self.assertRaisesMessage(ValueError, msg):
  31. Ntile(num_buckets=-1)