File: test_features.py

package info (click to toggle)
python-django 3%3A6.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 62,208 kB
  • sloc: python: 371,136; javascript: 19,376; xml: 211; makefile: 187; sh: 28
file content (42 lines) | stat: -rw-r--r-- 1,689 bytes parent folder | download
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
40
41
42
import copy
import sqlite3
from unittest import mock, skipUnless

from django.db import OperationalError, connection
from django.test import TestCase


@skipUnless(connection.vendor == "sqlite", "SQLite tests.")
class FeaturesTests(TestCase):
    def test_supports_json_field_operational_error(self):
        if hasattr(connection.features, "supports_json_field"):
            del connection.features.supports_json_field
        msg = "unable to open database file"
        with mock.patch.object(
            connection,
            "cursor",
            side_effect=OperationalError(msg),
        ):
            with self.assertRaisesMessage(OperationalError, msg):
                connection.features.supports_json_field

    def test_max_query_params_respects_variable_limit(self):
        limit_name = sqlite3.SQLITE_LIMIT_VARIABLE_NUMBER
        current_limit = connection.features.max_query_params
        new_limit = min(42, current_limit)
        try:
            connection.connection.setlimit(limit_name, new_limit)
            self.assertEqual(connection.features.max_query_params, new_limit)
        finally:
            connection.connection.setlimit(limit_name, current_limit)
        self.assertEqual(connection.features.max_query_params, current_limit)

    def test_max_query_params_without_established_connection(self):
        new_connection = connection.copy()
        new_connection.settings_dict = copy.deepcopy(connection.settings_dict)
        self.assertIsNone(new_connection.connection)
        try:
            result = new_connection.features.max_query_params
            self.assertIsInstance(result, int)
        finally:
            new_connection._close()