File: test_validation.py

package info (click to toggle)
python-django 3%3A3.2.19-1%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 56,696 kB
  • sloc: python: 264,418; javascript: 18,362; xml: 193; makefile: 178; sh: 43
file content (39 lines) | stat: -rw-r--r-- 1,536 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)