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