mirror of
https://github.com/jazzband/dj-database-url.git
synced 2026-03-16 22:20:24 +00:00
Support Django 4.1 and remove compatibility code (#183)
* Support Django 4.1 and remove compatibility code * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
723788a71f
commit
742d74d091
5 changed files with 25 additions and 45 deletions
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
|
|
@ -18,7 +18,7 @@ jobs:
|
|||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.9
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
|
|
|
|||
16
.github/workflows/test.yml
vendored
16
.github/workflows/test.yml
vendored
|
|
@ -6,14 +6,20 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.7", "3.8", "3.9", "3.10"]
|
||||
django-version: ["3.2", "4.0"]
|
||||
django-version: ["3.2", "4.0", "4.1"]
|
||||
exclude:
|
||||
# Python 3.6 is not compatible with 4.0
|
||||
- python-version: 3.6
|
||||
django-version: 4.0
|
||||
- python-version: "3.6"
|
||||
django-version: "4.0"
|
||||
# Python 3.6 is not compatible with 4.1
|
||||
- python-version: "3.6"
|
||||
django-version: "4.1"
|
||||
# Python 3.7 is not compatible with 4.0
|
||||
- python-version: 3.7
|
||||
django-version: 4.0
|
||||
- python-version: "3.7"
|
||||
django-version: "4.0"
|
||||
# Python 3.7 is not compatible with 4.1
|
||||
- python-version: "3.7"
|
||||
django-version: "4.1"
|
||||
fail-fast: false
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
|
|
|||
|
|
@ -1,14 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import urllib.parse as urlparse
|
||||
|
||||
try:
|
||||
from django import VERSION as DJANGO_VERSION
|
||||
except ImportError:
|
||||
DJANGO_VERSION = None
|
||||
|
||||
|
||||
# Register database schemes in URLs.
|
||||
urlparse.uses_netloc.append("postgres")
|
||||
urlparse.uses_netloc.append("postgresql")
|
||||
|
|
@ -32,6 +24,9 @@ urlparse.uses_netloc.append("timescalegis")
|
|||
DEFAULT_ENV = "DATABASE_URL"
|
||||
|
||||
SCHEMES = {
|
||||
"postgres": "django.db.backends.postgresql",
|
||||
"postgresql": "django.db.backends.postgresql",
|
||||
"pgsql": "django.db.backends.postgresql",
|
||||
"postgis": "django.contrib.gis.db.backends.postgis",
|
||||
"mysql": "django.db.backends.mysql",
|
||||
"mysql2": "django.db.backends.mysql",
|
||||
|
|
@ -49,16 +44,6 @@ SCHEMES = {
|
|||
"timescalegis": "timescale.db.backends.postgis",
|
||||
}
|
||||
|
||||
# https://docs.djangoproject.com/en/2.0/releases/2.0/#id1
|
||||
if DJANGO_VERSION and DJANGO_VERSION < (2, 0):
|
||||
SCHEMES["postgres"] = "django.db.backends.postgresql_psycopg2"
|
||||
SCHEMES["postgresql"] = "django.db.backends.postgresql_psycopg2"
|
||||
SCHEMES["pgsql"] = "django.db.backends.postgresql_psycopg2"
|
||||
else:
|
||||
SCHEMES["postgres"] = "django.db.backends.postgresql"
|
||||
SCHEMES["postgresql"] = "django.db.backends.postgresql"
|
||||
SCHEMES["pgsql"] = "django.db.backends.postgresql"
|
||||
|
||||
|
||||
def config(
|
||||
env=DEFAULT_ENV, default=None, engine=None, conn_max_age=0, ssl_require=False
|
||||
|
|
|
|||
4
setup.py
4
setup.py
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from setuptools import setup
|
||||
|
||||
with open("README.rst") as readme_rst:
|
||||
|
|
@ -14,7 +13,7 @@ setup(
|
|||
long_description=readme,
|
||||
long_description_content_type="text/x-rst",
|
||||
py_modules=["dj_database_url"],
|
||||
install_requires=["Django>3.2"],
|
||||
install_requires=["Django>=3.2"],
|
||||
zip_safe=False,
|
||||
include_package_data=True,
|
||||
platforms="any",
|
||||
|
|
@ -29,6 +28,7 @@ setup(
|
|||
"Framework :: Django",
|
||||
"Framework :: Django :: 3.2",
|
||||
"Framework :: Django :: 4.0",
|
||||
"Framework :: Django :: 4.1",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: BSD License",
|
||||
"Operating System :: OS Independent",
|
||||
|
|
|
|||
|
|
@ -1,28 +1,17 @@
|
|||
import os
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from django import VERSION as DJANGO_VERSION
|
||||
except ImportError:
|
||||
DJANGO_VERSION = None
|
||||
|
||||
import dj_database_url
|
||||
|
||||
POSTGIS_URL = "postgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
|
||||
|
||||
# Django deprecated the `django.db.backends.postgresql_psycopg2` in 2.0.
|
||||
# https://docs.djangoproject.com/en/2.0/releases/2.0/#id1
|
||||
EXPECTED_POSTGRES_ENGINE = "django.db.backends.postgresql"
|
||||
if DJANGO_VERSION and DJANGO_VERSION < (2, 0):
|
||||
EXPECTED_POSTGRES_ENGINE = "django.db.backends.postgresql_psycopg2"
|
||||
|
||||
|
||||
class DatabaseTestSuite(unittest.TestCase):
|
||||
def test_postgres_parsing(self):
|
||||
url = "postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
|
||||
url = dj_database_url.parse(url)
|
||||
|
||||
assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
|
||||
assert url["ENGINE"] == "django.db.backends.postgresql"
|
||||
assert url["NAME"] == "d8r82722r2kuvn"
|
||||
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
|
||||
assert url["USER"] == "uf07k1i6d8ia0v"
|
||||
|
|
@ -33,7 +22,7 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
url = "postgres://%2Fvar%2Frun%2Fpostgresql/d8r82722r2kuvn"
|
||||
url = dj_database_url.parse(url)
|
||||
|
||||
assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
|
||||
assert url["ENGINE"] == "django.db.backends.postgresql"
|
||||
assert url["NAME"] == "d8r82722r2kuvn"
|
||||
assert url["HOST"] == "/var/run/postgresql"
|
||||
assert url["USER"] == ""
|
||||
|
|
@ -43,7 +32,7 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
url = "postgres://%2FUsers%2Fpostgres%2FRuN/d8r82722r2kuvn"
|
||||
url = dj_database_url.parse(url)
|
||||
|
||||
assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
|
||||
assert url["ENGINE"] == "django.db.backends.postgresql"
|
||||
assert url["HOST"] == "/Users/postgres/RuN"
|
||||
assert url["USER"] == ""
|
||||
assert url["PASSWORD"] == ""
|
||||
|
|
@ -53,7 +42,7 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
url = "postgres://ieRaekei9wilaim7:wegauwhgeuioweg@[2001:db8:1234::1234:5678:90af]:5431/d8r82722r2kuvn"
|
||||
url = dj_database_url.parse(url)
|
||||
|
||||
assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
|
||||
assert url["ENGINE"] == "django.db.backends.postgresql"
|
||||
assert url["NAME"] == "d8r82722r2kuvn"
|
||||
assert url["HOST"] == "2001:db8:1234::1234:5678:90af"
|
||||
assert url["USER"] == "ieRaekei9wilaim7"
|
||||
|
|
@ -63,7 +52,7 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
def test_postgres_search_path_parsing(self):
|
||||
url = "postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?currentSchema=otherschema"
|
||||
url = dj_database_url.parse(url)
|
||||
assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
|
||||
assert url["ENGINE"] == "django.db.backends.postgresql"
|
||||
assert url["NAME"] == "d8r82722r2kuvn"
|
||||
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
|
||||
assert url["USER"] == "uf07k1i6d8ia0v"
|
||||
|
|
@ -76,7 +65,7 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
url = "postgres://%23user:%23password@ec2-107-21-253-135.compute-1.amazonaws.com:5431/%23database"
|
||||
url = dj_database_url.parse(url)
|
||||
|
||||
assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
|
||||
assert url["ENGINE"] == "django.db.backends.postgresql"
|
||||
assert url["NAME"] == "#database"
|
||||
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
|
||||
assert url["USER"] == "#user"
|
||||
|
|
@ -150,7 +139,7 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
|
||||
url = dj_database_url.config()
|
||||
|
||||
assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
|
||||
assert url["ENGINE"] == "django.db.backends.postgresql"
|
||||
assert url["NAME"] == "d8r82722r2kuvn"
|
||||
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
|
||||
assert url["USER"] == "uf07k1i6d8ia0v"
|
||||
|
|
@ -210,7 +199,7 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
] = "postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?sslrootcert=rds-combined-ca-bundle.pem&sslmode=verify-full"
|
||||
url = dj_database_url.config()
|
||||
|
||||
assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
|
||||
assert url["ENGINE"] == "django.db.backends.postgresql"
|
||||
assert url["NAME"] == "d8r82722r2kuvn"
|
||||
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
|
||||
assert url["USER"] == "uf07k1i6d8ia0v"
|
||||
|
|
|
|||
Loading…
Reference in a new issue