File: test_deprecation.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 (30 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download | duplicates (2)
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
from contextlib import contextmanager

from django.core.exceptions import FieldDoesNotExist, FieldError
from django.db.models.query_utils import InvalidQuery
from django.test import SimpleTestCase
from django.utils.deprecation import RemovedInDjango40Warning


class InvalidQueryTests(SimpleTestCase):
    @contextmanager
    def assert_warns(self):
        msg = (
            'The InvalidQuery exception class is deprecated. Use '
            'FieldDoesNotExist or FieldError instead.'
        )
        with self.assertWarnsMessage(RemovedInDjango40Warning, msg):
            yield

    def test_type(self):
        self.assertIsInstance(InvalidQuery(), InvalidQuery)

    def test_isinstance(self):
        for exception in (FieldError, FieldDoesNotExist):
            with self.assert_warns(), self.subTest(exception.__name__):
                self.assertIsInstance(exception(), InvalidQuery)

    def test_issubclass(self):
        for exception in (FieldError, FieldDoesNotExist, InvalidQuery):
            with self.assert_warns(), self.subTest(exception.__name__):
                self.assertIs(issubclass(exception, InvalidQuery), True)