Skip to content

Commit 100b873

Browse files
committed
Get sqlproxy tests passing with Django
1 parent 231e530 commit 100b873

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

python/django/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ start:
44

55
deps:
66
pip3 install --upgrade setuptools
7-
pip3 install django==3.2.8 django-cockroachdb==3.2.1 psycopg2
7+
pip3 install django==3.2.8 django-cockroachdb==3.2.1 psycopg2 dj-database-url==0.5.0

python/django/cockroach_example/settings.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
https://docs.djangoproject.com/en/2.2/ref/settings/
1111
"""
1212

13+
import dj_database_url
1314
import os
1415

1516
from urllib.parse import urlparse
@@ -76,24 +77,21 @@
7677
# Database
7778
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
7879

79-
port = 26257
80+
DATABASES = {}
8081
addr = os.getenv('ADDR')
8182
if addr is not None:
8283
url = urlparse(addr)
83-
port = url.port
84-
85-
DATABASES = {
86-
'default': {
84+
DATABASES['default'] = dj_database_url.config(default=addr, engine='django_cockroachdb')
85+
DATABASES['default']['DISABLE_COCKROACHDB_TELEMETRY'] = True
86+
else:
87+
DATABASES['default'] = {
8788
'ENGINE' : 'django_cockroachdb',
8889
'NAME' : 'company_django',
8990
'USER' : 'root',
90-
'PASSWORD': '',
9191
'HOST' : 'localhost',
92-
'PORT' : port,
92+
'PORT' : 26257,
9393
'DISABLE_COCKROACHDB_TELEMETRY' : True,
9494
}
95-
}
96-
9795

9896
# Password validation
9997
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

testing/main_test.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -474,20 +474,14 @@ func TestSQLAlchemy(t *testing.T) {
474474
}
475475

476476
func TestDjango(t *testing.T) {
477-
testORMForAuthModesExcept(t, testInfo{
478-
language: "python",
479-
orm: "django",
480-
tableNames: djangoTestTableNames,
481-
columnNames: djangoTestColumnNames,
482-
},
483-
map[authMode]string{
484-
// No support for client certs (at least not via the query string).
485-
// psycopg2.OperationalError: fe_sendauth: no password supplied
486-
//authClientCert: "client certs via query string unsupported",
487-
// Ditto,
488-
// psycopg2.OperationalError: fe_sendauth: no password supplied
489-
//authPassword: "password via query string unsupported",
490-
},
477+
testORMForAuthModesExcept(
478+
t,
479+
testInfo{
480+
language: "python",
481+
orm: "django",
482+
tableNames: djangoTestTableNames,
483+
columnNames: djangoTestColumnNames,
484+
}, nothingSkipped(),
491485
)
492486
}
493487

0 commit comments

Comments
 (0)