summaryrefslogtreecommitdiff
path: root/tests/db_functions/test_window.py
diff options
context:
space:
mode:
authorMads Jensen <mje@inducks.org>2017-09-18 15:42:29 +0200
committerTim Graham <timograham@gmail.com>2017-09-18 09:42:29 -0400
commitd549b8805053d4b064bf492ba90e90db5d7e2a6b (patch)
tree2beee237ae541804ba18367d81e82840745d6e47 /tests/db_functions/test_window.py
parentda1ba03f1dfb303df9bfb5c76d36216e45d05edc (diff)
Fixed #26608 -- Added support for window expressions (OVER clause).
Thanks Josh Smeaton, Mariusz Felisiak, Sergey Fedoseev, Simon Charettes, Adam Chainz/Johnson and Tim Graham for comments and reviews and Jamie Cockburn for initial patch.
Diffstat (limited to 'tests/db_functions/test_window.py')
-rw-r--r--tests/db_functions/test_window.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/db_functions/test_window.py b/tests/db_functions/test_window.py
new file mode 100644
index 0000000000..2efc88fdfa
--- /dev/null
+++ b/tests/db_functions/test_window.py
@@ -0,0 +1,39 @@
+from django.db.models.functions import Lag, Lead, NthValue, Ntile
+from django.test import SimpleTestCase
+
+
+class ValidationTests(SimpleTestCase):
+ def test_nth_negative_nth_value(self):
+ msg = 'NthValue requires a positive integer as for nth'
+ with self.assertRaisesMessage(ValueError, msg):
+ NthValue(expression='salary', nth=-1)
+
+ def test_nth_null_expression(self):
+ msg = 'NthValue requires a non-null source expression'
+ with self.assertRaisesMessage(ValueError, msg):
+ NthValue(expression=None)
+
+ def test_lag_negative_offset(self):
+ msg = 'Lag requires a positive integer for the offset'
+ with self.assertRaisesMessage(ValueError, msg):
+ Lag(expression='salary', offset=-1)
+
+ def test_lead_negative_offset(self):
+ msg = 'Lead requires a positive integer for the offset'
+ with self.assertRaisesMessage(ValueError, msg):
+ Lead(expression='salary', offset=-1)
+
+ def test_null_source_lead(self):
+ msg = 'Lead requires a non-null source expression'
+ with self.assertRaisesMessage(ValueError, msg):
+ Lead(expression=None)
+
+ def test_null_source_lag(self):
+ msg = 'Lag requires a non-null source expression'
+ with self.assertRaisesMessage(ValueError, msg):
+ Lag(expression=None)
+
+ def test_negative_num_buckets_ntile(self):
+ msg = 'num_buckets must be greater than 0'
+ with self.assertRaisesMessage(ValueError, msg):
+ Ntile(num_buckets=-1)