Skip to content

Commit e7824b6

Browse files
authored
Merge pull request #93 from rafiss/enable-django
Enable testing against Django
2 parents 0433b39 + 3faa0ab commit e7824b6

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM openjdk:8
1+
FROM openjdk:8-slim-buster
22

33
RUN apt-get update -y
44

5-
RUN apt-get install -y zlib1g zlib1g-dev
5+
RUN apt-get install -y zlib1g zlib1g-dev curl wget apt-utils
66

77
# installations for django
88
RUN apt-get install -y python3 python3-dev python3-pip
@@ -17,7 +17,7 @@ RUN apt-get install -y nodejs
1717

1818
# RUN apt-get install -y ruby-full
1919

20-
RUN apt-get install -y postgresql postgresql-contrib libpq-dev git wget build-essential curl openssl
20+
RUN apt-get install -y postgresql postgresql-contrib libpq-dev git build-essential openssl
2121

2222
# Installations for gradle and gradlew
2323
RUN apt-get install gradle -y

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,4 @@ deps:
4242
$(MAKE) deps -C ./python/sqlalchemy
4343
$(MAKE) deps -C ./ruby/activerecord
4444
$(MAKE) deps -C ./ruby/ar4
45-
# Django test is disabled for now.
46-
# $(MAKE) deps -C ./python/django
45+
$(MAKE) deps -C ./python/django

docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
set -euo pipefail
2323

24-
image=cockroachdb/example-orms-builder:latest
24+
image=cockroachdb/example-orms-builder:20200129-1444
2525

2626
gopath=$(go env GOPATH)
2727
gopath0=${gopath%%:*}

python/django/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ start:
33
python3 manage.py migrate cockroach_example && python3 manage.py runserver 6543
44

55
deps:
6-
git clone https://github.com/cockroachlabs/cockroach-django || true
7-
cd cockroach-django && pip3 install .
6+
git clone https://github.com/cockroachdb/django-cockroachdb || true
7+
pip3 install --upgrade setuptools
88
pip3 install django
9+
cd django-cockroachdb && pip3 install .

ruby/activerecord/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ start:
2424

2525
.PHONY: deps
2626
deps:
27-
@gem install bundler
27+
@gem install bundler:1.15.1
2828
@bin/bundle

testing/main_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/url"
88
"os"
99
"os/exec"
10+
"strings"
1011
"syscall"
1112
"testing"
1213
"time"
@@ -42,7 +43,7 @@ var customURLSchemes = map[application]string{
4243
}
4344

4445
// initTestDatabase launches a test database as a subprocess.
45-
func initTestDatabase(t *testing.T, app application) (*sql.DB, *url.URL, func()) {
46+
func initTestDatabase(t *testing.T, app application) (*sql.DB, *url.URL, string, func()) {
4647
ts, err := testserver.NewTestServer()
4748
if err != nil {
4849
t.Fatal(err)
@@ -70,10 +71,16 @@ func initTestDatabase(t *testing.T, app application) (*sql.DB, *url.URL, func())
7071
t.Fatal(err)
7172
}
7273

74+
var version string
75+
if err := db.QueryRow(`SELECT value FROM crdb_internal.node_build_info where field = 'Version'`,
76+
).Scan(&version); err != nil {
77+
t.Fatal(err)
78+
}
79+
7380
if scheme, ok := customURLSchemes[app]; ok {
7481
url.Scheme = scheme
7582
}
76-
return db, url, func() {
83+
return db, url, version, func() {
7784
_ = db.Close()
7885
ts.Stop()
7986
}
@@ -147,9 +154,13 @@ func testORM(
147154
orm: orm,
148155
}
149156

150-
db, dbURL, stopDB := initTestDatabase(t, app)
157+
db, dbURL, version, stopDB := initTestDatabase(t, app)
151158
defer stopDB()
152159

160+
if orm == "django" && (strings.HasPrefix(version, "v2.0") || strings.HasPrefix(version, "v2.1")) {
161+
t.Skip("TestDjango fails on CRDB <=v2.1 due to missing foreign key support.")
162+
}
163+
153164
td := testDriver{
154165
db: db,
155166
dbName: app.dbName(),
@@ -250,7 +261,6 @@ func TestSQLAlchemy(t *testing.T) {
250261
}
251262

252263
func TestDjango(t *testing.T) {
253-
t.Skip("TestDjango fails on CRDB v2.1; github.com/cockroachdb/cockroach/issues/42083")
254264
testORM(t, "python", "django", djangoTestTableNames, djangoTestColumnNames)
255265
}
256266

0 commit comments

Comments
 (0)