summaryrefslogtreecommitdiff
path: root/tests/backends/postgresql
diff options
context:
space:
mode:
authorkingbuzzman <buzzi.javier@gmail.com>2019-04-25 16:09:27 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-04-29 14:20:17 +0200
commit673fe2e3ec63614259e86e7a370b9d1e91fcc1e1 (patch)
tree19eb301459c0295a5cb0b5a8bb6abdeed8128ad0 /tests/backends/postgresql
parentf7408b49a54d746db252ebc7176a67506d183a58 (diff)
Fixed #30148 -- Logged COPY ... TO statements in connection.queries on PostgreSQL.
Diffstat (limited to 'tests/backends/postgresql')
-rw-r--r--tests/backends/postgresql/tests.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/backends/postgresql/tests.py b/tests/backends/postgresql/tests.py
index 96a1501693..4e51c1c7b5 100644
--- a/tests/backends/postgresql/tests.py
+++ b/tests/backends/postgresql/tests.py
@@ -1,9 +1,10 @@
import unittest
+from io import StringIO
from unittest import mock
from django.core.exceptions import ImproperlyConfigured
from django.db import DatabaseError, connection, connections
-from django.test import TestCase
+from django.test import TestCase, override_settings
@unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL tests')
@@ -176,3 +177,15 @@ class Tests(TestCase):
self.assertEqual(psycopg2_version(), (4, 2, 1))
with mock.patch('psycopg2.__version__', '4.2b0.dev1 (dt dec pq3 ext lo64)'):
self.assertEqual(psycopg2_version(), (4, 2))
+
+ @override_settings(DEBUG=True)
+ def test_copy_cursors(self):
+ out = StringIO()
+ copy_expert_sql = 'COPY django_session TO STDOUT (FORMAT CSV, HEADER)'
+ with connection.cursor() as cursor:
+ cursor.copy_expert(copy_expert_sql, out)
+ cursor.copy_to(out, 'django_session')
+ self.assertEqual(
+ [q['sql'] for q in connection.queries],
+ [copy_expert_sql, 'COPY django_session TO STDOUT'],
+ )