Merge branch 'master' into master

This commit is contained in:
Matt Seymour 2025-04-30 13:29:15 +01:00 committed by GitHub
commit c469885ebf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 207 additions and 155 deletions

View file

@ -11,12 +11,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.10'

View file

@ -6,30 +6,25 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
django-version: ["3.2", "4.2", "5.0"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
django-version: ["4.2", "5.1"]
exclude:
# Python 3.7 is not compatible with 4.1
- python-version: "3.7"
django-version: "4.2"
# Python 3.11 is not compatible with 3.2
- python-version: "3.11"
django-version: "3.2"
- python-version: "3.12"
django-version: "3.2"
# django 5.0 is not compatible with python 3.9 or lower
- python-version: "3.7"
django-version: "5.0"
- python-version: "3.8"
django-version: "5.0"
- python-version: "3.13"
django-version: "3.2"
# django 5.x is not compatible with python 3.9 or lower
- python-version: "3.9"
django-version: "5.0"
django-version: "5.1"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
@ -39,9 +34,10 @@ jobs:
pip install -r requirements.txt
pip install "Django~=${{ matrix.django-version }}.0" .
- name: Run mypy
- name: Run type checking
run: |
python -m mypy dj_database_url
python -m pyright dj_database_url
- name: Run Tests
run: |
@ -50,10 +46,11 @@ jobs:
coverage report
coverage xml
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
- name: Check mypy types installation
- name: Check types installation
run: |
pip install .
cd tests
python -m mypy .
python -m pyright .

View file

@ -1,23 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pycqa/isort
rev: "5.13.2"
rev: "6.0.1"
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 25.1.0
hooks:
- id: black
args: [--target-version=py38]
- repo: https://github.com/pycqa/flake8
rev: '7.0.0'
rev: '7.2.0'
hooks:
- id: flake8

View file

@ -1,5 +1,22 @@
# CHANGELOG
## Unreleased
* Drop dependency on `typing_extensions`.
## v2.3.0 (2024-10-23)
* Remove Python 3.8 support.
* Remove Django 3 support.
* Add python 3.13 support.
* Add Django 5.1 to the testing library.
## v2.2.0 (2024-05-28)
* Add disable_server_side_cursors parameter
* Enhance Query String Parsing for Server-Side Binding in Django 4.2 with psycopg 3.1.8+
* Update django 5.0 python compatability by @mattseymour in #239
* Improved internals
* Improved documentation
## v2.1.0 (2023-08-15)
* Add value to int parsing when deconstructing url string.

View file

@ -206,6 +206,7 @@ URL schema
| Engine | Django Backend | URL |
+======================+===============================================+==================================================+
| PostgreSQL | ``django.db.backends.postgresql`` [1]_ | ``postgres://USER:PASSWORD@HOST:PORT/NAME`` [2]_ |
| | | ``postgresql://USER:PASSWORD@HOST:PORT/NAME`` |
+----------------------+-----------------------------------------------+--------------------------------------------------+
| PostGIS | ``django.contrib.gis.db.backends.postgis`` | ``postgis://USER:PASSWORD@HOST:PORT/NAME`` |
+----------------------+-----------------------------------------------+--------------------------------------------------+

View file

@ -5,10 +5,10 @@ from typing import Any, Callable, Dict, List, Optional, Union
from typing_extensions import TypedDict
DEFAULT_ENV = "DATABASE_URL"
ENGINE_SCHEMES: Dict[str, "Engine"] = {}
# From https://docs.djangoproject.com/en/stable/ref/settings/#databases
class DBConfig(TypedDict, total=False):
ATOMIC_REQUESTS: bool
@ -133,7 +133,7 @@ def config(
conn_health_checks: bool = False,
disable_server_side_cursors: bool = False,
ssl_require: bool = False,
test_options: Optional[Dict] = None,
test_options: Optional[Dict[str, Any]] = None,
) -> DBConfig:
"""Returns configured DATABASE dictionary from DATABASE_URL."""
s = os.environ.get(env, default)
@ -164,7 +164,7 @@ def parse(
conn_health_checks: bool = False,
disable_server_side_cursors: bool = False,
ssl_require: bool = False,
test_options: Optional[dict] = None,
test_options: Optional[Dict[str, Any]] = None,
) -> DBConfig:
"""Parses a database URL and returns configured DATABASE dictionary."""
settings = _convert_to_settings(

View file

@ -6,3 +6,6 @@ show_error_codes=true
disallow_untyped_defs=true
disallow_untyped_calls=true
warn_redundant_casts=true
[tool.pyright]
typeCheckingMode = "strict"

View file

@ -1,2 +1,3 @@
coverage
mypy
pyright

View file

@ -1,12 +1,12 @@
from pathlib import Path
from setuptools import setup
from setuptools import setup # pyright: ignore[reportUnknownVariableType]
readme = Path("README.rst").read_text()
setup(
name="dj-database-url",
version="2.1.0",
version="2.3.0",
url="https://github.com/jazzband/dj-database-url",
license="BSD",
author="Original Author: Kenneth Reitz, Maintained by: JazzBand Community",
@ -14,7 +14,7 @@ setup(
long_description=readme,
long_description_content_type="text/x-rst",
packages=["dj_database_url"],
install_requires=["Django>=3.2", "typing_extensions >= 3.10.0.0"],
install_requires=["Django>=4.2"],
include_package_data=True,
package_data={
"dj_database_url": ["py.typed"],
@ -29,9 +29,9 @@ setup(
classifiers=[
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Django :: 5.1",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
@ -40,11 +40,10 @@ setup(
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
],
)

View file

@ -1,3 +1,5 @@
# pyright: reportTypedDictNotRequiredAccess=false
import os
import re
import unittest
@ -10,9 +12,10 @@ POSTGIS_URL = "postgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compu
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)
def test_postgres_parsing(self) -> None:
url = dj_database_url.parse(
"postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
)
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
@ -21,9 +24,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "wegauwhgeuioweg"
assert url["PORT"] == 5431
def test_postgres_unix_socket_parsing(self):
url = "postgres://%2Fvar%2Frun%2Fpostgresql/d8r82722r2kuvn"
url = dj_database_url.parse(url)
def test_postgres_unix_socket_parsing(self) -> None:
url = dj_database_url.parse(
"postgres://%2Fvar%2Frun%2Fpostgresql/d8r82722r2kuvn"
)
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
@ -32,8 +36,9 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == ""
assert url["PORT"] == ""
url = "postgres://%2FUsers%2Fpostgres%2FRuN/d8r82722r2kuvn"
url = dj_database_url.parse(url)
url = dj_database_url.parse(
"postgres://%2FUsers%2Fpostgres%2FRuN/d8r82722r2kuvn"
)
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["HOST"] == "/Users/postgres/RuN"
@ -41,9 +46,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == ""
assert url["PORT"] == ""
def test_postgres_google_cloud_parsing(self):
url = "postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@%2Fcloudsql%2Fproject_id%3Aregion%3Ainstance_id/d8r82722r2kuvn"
url = dj_database_url.parse(url)
def test_postgres_google_cloud_parsing(self) -> None:
url = dj_database_url.parse(
"postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@%2Fcloudsql%2Fproject_id%3Aregion%3Ainstance_id/d8r82722r2kuvn"
)
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
@ -52,9 +58,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "wegauwhgeuioweg"
assert url["PORT"] == ""
def test_ipv6_parsing(self):
url = "postgres://ieRaekei9wilaim7:wegauwhgeuioweg@[2001:db8:1234::1234:5678:90af]:5431/d8r82722r2kuvn"
url = dj_database_url.parse(url)
def test_ipv6_parsing(self) -> None:
url = dj_database_url.parse(
"postgres://ieRaekei9wilaim7:wegauwhgeuioweg@[2001:db8:1234::1234:5678:90af]:5431/d8r82722r2kuvn"
)
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
@ -63,9 +70,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "wegauwhgeuioweg"
assert url["PORT"] == 5431
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)
def test_postgres_search_path_parsing(self) -> None:
url = dj_database_url.parse(
"postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?currentSchema=otherschema"
)
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
@ -75,9 +83,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["OPTIONS"]["options"] == "-c search_path=otherschema"
assert "currentSchema" not in url["OPTIONS"]
def test_postgres_parsing_with_special_characters(self):
url = "postgres://%23user:%23password@ec2-107-21-253-135.compute-1.amazonaws.com:5431/%23database"
url = dj_database_url.parse(url)
def test_postgres_parsing_with_special_characters(self) -> None:
url = dj_database_url.parse(
"postgres://%23user:%23password@ec2-107-21-253-135.compute-1.amazonaws.com:5431/%23database"
)
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "#database"
@ -86,9 +95,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "#password"
assert url["PORT"] == 5431
def test_postgres_parsing_with_int_bool_str_query_string(self):
url = "postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?server_side_binding=true&timeout=20&service=my_service&passfile=.my_pgpass"
url = dj_database_url.parse(url)
def test_postgres_parsing_with_int_bool_str_query_string(self) -> None:
url = dj_database_url.parse(
"postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?server_side_binding=true&timeout=20&service=my_service&passfile=.my_pgpass"
)
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
@ -101,9 +111,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["OPTIONS"]["service"] == "my_service"
assert url["OPTIONS"]["passfile"] == ".my_pgpass"
def test_postgis_parsing(self):
url = "postgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
url = dj_database_url.parse(url)
def test_postgis_parsing(self) -> None:
url = dj_database_url.parse(
"postgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
)
assert url["ENGINE"] == "django.contrib.gis.db.backends.postgis"
assert url["NAME"] == "d8r82722r2kuvn"
@ -112,9 +123,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "wegauwhgeuioweg"
assert url["PORT"] == 5431
def test_postgis_search_path_parsing(self):
url = "postgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?currentSchema=otherschema"
url = dj_database_url.parse(url)
def test_postgis_search_path_parsing(self) -> None:
url = dj_database_url.parse(
"postgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?currentSchema=otherschema"
)
assert url["ENGINE"] == "django.contrib.gis.db.backends.postgis"
assert url["NAME"] == "d8r82722r2kuvn"
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
@ -124,9 +136,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["OPTIONS"]["options"] == "-c search_path=otherschema"
assert "currentSchema" not in url["OPTIONS"]
def test_mysql_gis_parsing(self):
url = "mysqlgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
url = dj_database_url.parse(url)
def test_mysql_gis_parsing(self) -> None:
url = dj_database_url.parse(
"mysqlgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
)
assert url["ENGINE"] == "django.contrib.gis.db.backends.mysql"
assert url["NAME"] == "d8r82722r2kuvn"
@ -135,9 +148,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "wegauwhgeuioweg"
assert url["PORT"] == 5431
def test_mysql_connector_parsing(self):
url = "mysql-connector://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
url = dj_database_url.parse(url)
def test_mysql_connector_parsing(self) -> None:
url = dj_database_url.parse(
"mysql-connector://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
)
assert url["ENGINE"] == "mysql.connector.django"
assert url["NAME"] == "d8r82722r2kuvn"
@ -146,7 +160,7 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "wegauwhgeuioweg"
assert url["PORT"] == 5431
def test_config_test_options(self):
def test_config_test_options(self) -> None:
with mock.patch.dict(
os.environ,
{
@ -160,9 +174,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url['TEST']['NAME'] == 'mytestdatabase'
def test_cleardb_parsing(self):
url = "mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true"
url = dj_database_url.parse(url)
def test_cleardb_parsing(self) -> None:
url = dj_database_url.parse(
"mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true"
)
assert url["ENGINE"] == "django.db.backends.mysql"
assert url["NAME"] == "heroku_97681db3eff7580"
@ -171,7 +186,7 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "69772142"
assert url["PORT"] == ""
def test_database_url(self):
def test_database_url(self) -> None:
with mock.patch.dict(os.environ, clear=True):
a = dj_database_url.config()
assert not a
@ -191,16 +206,14 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "wegauwhgeuioweg"
assert url["PORT"] == 5431
def test_empty_sqlite_url(self):
url = "sqlite://"
url = dj_database_url.parse(url)
def test_empty_sqlite_url(self) -> None:
url = dj_database_url.parse("sqlite://")
assert url["ENGINE"] == "django.db.backends.sqlite3"
assert url["NAME"] == ":memory:"
def test_memory_sqlite_url(self):
url = "sqlite://:memory:"
url = dj_database_url.parse(url)
def test_memory_sqlite_url(self) -> None:
url = dj_database_url.parse("sqlite://:memory:")
assert url["ENGINE"] == "django.db.backends.sqlite3"
assert url["NAME"] == ":memory:"
@ -223,14 +236,16 @@ class DatabaseTestSuite(unittest.TestCase):
assert config["ENGINE"] == "django.db.backends.sqlite3"
assert config["NAME"] == "/db.sqlite3"
def test_parse_engine_setting(self):
def test_parse_engine_setting(self) -> None:
engine = "django_mysqlpool.backends.mysqlpool"
url = "mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true"
url = dj_database_url.parse(url, engine)
url = dj_database_url.parse(
"mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true",
engine,
)
assert url["ENGINE"] == engine
def test_config_engine_setting(self):
def test_config_engine_setting(self) -> None:
engine = "django_mysqlpool.backends.mysqlpool"
with mock.patch.dict(
os.environ,
@ -242,14 +257,16 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["ENGINE"] == engine
def test_parse_conn_max_age_setting(self):
def test_parse_conn_max_age_setting(self) -> None:
conn_max_age = 600
url = "mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true"
url = dj_database_url.parse(url, conn_max_age=conn_max_age)
url = dj_database_url.parse(
"mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true",
conn_max_age=conn_max_age,
)
assert url["CONN_MAX_AGE"] == conn_max_age
def test_config_conn_max_age_setting(self):
def test_config_conn_max_age_setting(self) -> None:
conn_max_age = 600
with mock.patch.dict(
os.environ,
@ -261,7 +278,7 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["CONN_MAX_AGE"] == conn_max_age
def test_database_url_with_options(self):
def test_database_url_with_options(self) -> None:
# Test full options
with mock.patch.dict(
os.environ,
@ -292,7 +309,7 @@ class DatabaseTestSuite(unittest.TestCase):
url = dj_database_url.config()
assert "OPTIONS" not in url
def test_mysql_database_url_with_sslca_options(self):
def test_mysql_database_url_with_sslca_options(self) -> None:
with mock.patch.dict(
os.environ,
{
@ -319,9 +336,8 @@ class DatabaseTestSuite(unittest.TestCase):
url = dj_database_url.config()
assert "OPTIONS" not in url
def test_oracle_parsing(self):
url = "oracle://scott:tiger@oraclehost:1521/hr"
url = dj_database_url.parse(url)
def test_oracle_parsing(self) -> None:
url = dj_database_url.parse("oracle://scott:tiger@oraclehost:1521/hr")
assert url["ENGINE"] == "django.db.backends.oracle"
assert url["NAME"] == "hr"
@ -330,9 +346,8 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "tiger"
assert url["PORT"] == "1521"
def test_oracle_gis_parsing(self):
url = "oraclegis://scott:tiger@oraclehost:1521/hr"
url = dj_database_url.parse(url)
def test_oracle_gis_parsing(self) -> None:
url = dj_database_url.parse("oraclegis://scott:tiger@oraclehost:1521/hr")
assert url["ENGINE"] == "django.contrib.gis.db.backends.oracle"
assert url["NAME"] == "hr"
@ -341,14 +356,13 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "tiger"
assert url["PORT"] == 1521
def test_oracle_dsn_parsing(self):
url = (
def test_oracle_dsn_parsing(self) -> None:
url = dj_database_url.parse(
"oracle://scott:tiger@/"
"(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)"
"(HOST=oraclehost)(PORT=1521)))"
"(CONNECT_DATA=(SID=hr)))"
)
url = dj_database_url.parse(url)
assert url["ENGINE"] == "django.db.backends.oracle"
assert url["USER"] == "scott"
@ -364,9 +378,8 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["NAME"] == dsn
def test_oracle_tns_parsing(self):
url = "oracle://scott:tiger@/tnsname"
url = dj_database_url.parse(url)
def test_oracle_tns_parsing(self) -> None:
url = dj_database_url.parse("oracle://scott:tiger@/tnsname")
assert url["ENGINE"] == "django.db.backends.oracle"
assert url["USER"] == "scott"
@ -375,9 +388,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["HOST"] == ""
assert url["PORT"] == ""
def test_redshift_parsing(self):
url = "redshift://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5439/d8r82722r2kuvn?currentSchema=otherschema"
url = dj_database_url.parse(url)
def test_redshift_parsing(self) -> None:
url = dj_database_url.parse(
"redshift://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5439/d8r82722r2kuvn?currentSchema=otherschema"
)
assert url["ENGINE"] == "django_redshift_backend"
assert url["NAME"] == "d8r82722r2kuvn"
@ -388,9 +402,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["OPTIONS"]["options"] == "-c search_path=otherschema"
assert "currentSchema" not in url["OPTIONS"]
def test_mssql_parsing(self):
url = "mssql://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com/d8r82722r2kuvn?driver=ODBC Driver 13 for SQL Server"
url = dj_database_url.parse(url)
def test_mssql_parsing(self) -> None:
url = dj_database_url.parse(
"mssql://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com/d8r82722r2kuvn?driver=ODBC Driver 13 for SQL Server"
)
assert url["ENGINE"] == "sql_server.pyodbc"
assert url["NAME"] == "d8r82722r2kuvn"
@ -401,9 +416,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["OPTIONS"]["driver"] == "ODBC Driver 13 for SQL Server"
assert "currentSchema" not in url["OPTIONS"]
def test_mssql_instance_port_parsing(self):
url = "mssql://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com\\insnsnss:12345/d8r82722r2kuvn?driver=ODBC Driver 13 for SQL Server"
url = dj_database_url.parse(url)
def test_mssql_instance_port_parsing(self) -> None:
url = dj_database_url.parse(
"mssql://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com\\insnsnss:12345/d8r82722r2kuvn?driver=ODBC Driver 13 for SQL Server"
)
assert url["ENGINE"] == "sql_server.pyodbc"
assert url["NAME"] == "d8r82722r2kuvn"
@ -414,9 +430,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["OPTIONS"]["driver"] == "ODBC Driver 13 for SQL Server"
assert "currentSchema" not in url["OPTIONS"]
def test_cockroach(self):
url = "cockroach://testuser:testpass@testhost:26257/cockroach?sslmode=verify-full&sslrootcert=/certs/ca.crt&sslcert=/certs/client.myprojectuser.crt&sslkey=/certs/client.myprojectuser.key"
url = dj_database_url.parse(url)
def test_cockroach(self) -> None:
url = dj_database_url.parse(
"cockroach://testuser:testpass@testhost:26257/cockroach?sslmode=verify-full&sslrootcert=/certs/ca.crt&sslcert=/certs/client.myprojectuser.crt&sslkey=/certs/client.myprojectuser.key"
)
assert url['ENGINE'] == 'django_cockroachdb'
assert url['NAME'] == 'cockroach'
assert url['HOST'] == 'testhost'
@ -428,9 +445,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url['OPTIONS']['sslcert'] == '/certs/client.myprojectuser.crt'
assert url['OPTIONS']['sslkey'] == '/certs/client.myprojectuser.key'
def test_mssqlms_parsing(self):
url = "mssqlms://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com/d8r82722r2kuvn?driver=ODBC Driver 13 for SQL Server"
url = dj_database_url.parse(url)
def test_mssqlms_parsing(self) -> None:
url = dj_database_url.parse(
"mssqlms://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com/d8r82722r2kuvn?driver=ODBC Driver 13 for SQL Server"
)
assert url["ENGINE"] == "mssql"
assert url["NAME"] == "d8r82722r2kuvn"
@ -441,9 +459,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["OPTIONS"]["driver"] == "ODBC Driver 13 for SQL Server"
assert "currentSchema" not in url["OPTIONS"]
def test_timescale_parsing(self):
url = "timescale://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
url = dj_database_url.parse(url)
def test_timescale_parsing(self) -> None:
url = dj_database_url.parse(
"timescale://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
)
assert url["ENGINE"] == "timescale.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
@ -452,9 +471,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "wegauwhgeuioweg"
assert url["PORT"] == 5431
def test_timescale_unix_socket_parsing(self):
url = "timescale://%2Fvar%2Frun%2Fpostgresql/d8r82722r2kuvn"
url = dj_database_url.parse(url)
def test_timescale_unix_socket_parsing(self) -> None:
url = dj_database_url.parse(
"timescale://%2Fvar%2Frun%2Fpostgresql/d8r82722r2kuvn"
)
assert url["ENGINE"] == "timescale.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
@ -463,8 +483,9 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == ""
assert url["PORT"] == ""
url = "timescale://%2FUsers%2Fpostgres%2FRuN/d8r82722r2kuvn"
url = dj_database_url.parse(url)
url = dj_database_url.parse(
"timescale://%2FUsers%2Fpostgres%2FRuN/d8r82722r2kuvn"
)
assert url["ENGINE"] == "timescale.db.backends.postgresql"
assert url["HOST"] == "/Users/postgres/RuN"
@ -472,9 +493,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == ""
assert url["PORT"] == ""
def test_timescale_ipv6_parsing(self):
url = "timescale://ieRaekei9wilaim7:wegauwhgeuioweg@[2001:db8:1234::1234:5678:90af]:5431/d8r82722r2kuvn"
url = dj_database_url.parse(url)
def test_timescale_ipv6_parsing(self) -> None:
url = dj_database_url.parse(
"timescale://ieRaekei9wilaim7:wegauwhgeuioweg@[2001:db8:1234::1234:5678:90af]:5431/d8r82722r2kuvn"
)
assert url["ENGINE"] == "timescale.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
@ -483,9 +505,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "wegauwhgeuioweg"
assert url["PORT"] == 5431
def test_timescale_search_path_parsing(self):
url = "timescale://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?currentSchema=otherschema"
url = dj_database_url.parse(url)
def test_timescale_search_path_parsing(self) -> None:
url = dj_database_url.parse(
"timescale://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?currentSchema=otherschema"
)
assert url["ENGINE"] == "timescale.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
@ -495,9 +518,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["OPTIONS"]["options"] == "-c search_path=otherschema"
assert "currentSchema" not in url["OPTIONS"]
def test_timescale_parsing_with_special_characters(self):
url = "timescale://%23user:%23password@ec2-107-21-253-135.compute-1.amazonaws.com:5431/%23database"
url = dj_database_url.parse(url)
def test_timescale_parsing_with_special_characters(self) -> None:
url = dj_database_url.parse(
"timescale://%23user:%23password@ec2-107-21-253-135.compute-1.amazonaws.com:5431/%23database"
)
assert url["ENGINE"] == "timescale.db.backends.postgresql"
assert url["NAME"] == "#database"
@ -506,9 +530,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "#password"
assert url["PORT"] == 5431
def test_timescalegis_parsing(self):
url = "timescalegis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
url = dj_database_url.parse(url)
def test_timescalegis_parsing(self) -> None:
url = dj_database_url.parse(
"timescalegis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
)
assert url["ENGINE"] == "timescale.db.backends.postgis"
assert url["NAME"] == "d8r82722r2kuvn"
@ -517,9 +542,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "wegauwhgeuioweg"
assert url["PORT"] == 5431
def test_timescalegis_unix_socket_parsing(self):
url = "timescalegis://%2Fvar%2Frun%2Fpostgresql/d8r82722r2kuvn"
url = dj_database_url.parse(url)
def test_timescalegis_unix_socket_parsing(self) -> None:
url = dj_database_url.parse(
"timescalegis://%2Fvar%2Frun%2Fpostgresql/d8r82722r2kuvn"
)
assert url["ENGINE"] == "timescale.db.backends.postgis"
assert url["NAME"] == "d8r82722r2kuvn"
@ -528,8 +554,9 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == ""
assert url["PORT"] == ""
url = "timescalegis://%2FUsers%2Fpostgres%2FRuN/d8r82722r2kuvn"
url = dj_database_url.parse(url)
url = dj_database_url.parse(
"timescalegis://%2FUsers%2Fpostgres%2FRuN/d8r82722r2kuvn"
)
assert url["ENGINE"] == "timescale.db.backends.postgis"
assert url["HOST"] == "/Users/postgres/RuN"
@ -537,9 +564,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == ""
assert url["PORT"] == ""
def test_timescalegis_ipv6_parsing(self):
url = "timescalegis://ieRaekei9wilaim7:wegauwhgeuioweg@[2001:db8:1234::1234:5678:90af]:5431/d8r82722r2kuvn"
url = dj_database_url.parse(url)
def test_timescalegis_ipv6_parsing(self) -> None:
url = dj_database_url.parse(
"timescalegis://ieRaekei9wilaim7:wegauwhgeuioweg@[2001:db8:1234::1234:5678:90af]:5431/d8r82722r2kuvn"
)
assert url["ENGINE"] == "timescale.db.backends.postgis"
assert url["NAME"] == "d8r82722r2kuvn"
@ -548,9 +576,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "wegauwhgeuioweg"
assert url["PORT"] == 5431
def test_timescalegis_search_path_parsing(self):
url = "timescalegis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?currentSchema=otherschema"
url = dj_database_url.parse(url)
def test_timescalegis_search_path_parsing(self) -> None:
url = dj_database_url.parse(
"timescalegis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?currentSchema=otherschema"
)
assert url["ENGINE"] == "timescale.db.backends.postgis"
assert url["NAME"] == "d8r82722r2kuvn"
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
@ -560,9 +589,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["OPTIONS"]["options"] == "-c search_path=otherschema"
assert "currentSchema" not in url["OPTIONS"]
def test_timescalegis_parsing_with_special_characters(self):
url = "timescalegis://%23user:%23password@ec2-107-21-253-135.compute-1.amazonaws.com:5431/%23database"
url = dj_database_url.parse(url)
def test_timescalegis_parsing_with_special_characters(self) -> None:
url = dj_database_url.parse(
"timescalegis://%23user:%23password@ec2-107-21-253-135.compute-1.amazonaws.com:5431/%23database"
)
assert url["ENGINE"] == "timescale.db.backends.postgis"
assert url["NAME"] == "#database"
@ -571,7 +601,7 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["PASSWORD"] == "#password"
assert url["PORT"] == 5431
def test_persistent_connection_variables(self):
def test_persistent_connection_variables(self) -> None:
url = dj_database_url.parse(
"sqlite://myfile.db", conn_max_age=600, conn_health_checks=True
)
@ -579,7 +609,7 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["CONN_MAX_AGE"] == 600
assert url["CONN_HEALTH_CHECKS"] is True
def test_sqlite_memory_persistent_connection_variables(self):
def test_sqlite_memory_persistent_connection_variables(self) -> None:
# memory sqlite ignores connection.close(), so persistent connection
# variables arent required
url = dj_database_url.parse(
@ -593,13 +623,13 @@ class DatabaseTestSuite(unittest.TestCase):
os.environ,
{"DATABASE_URL": "postgres://user:password@instance.amazonaws.com:5431/d8r8?"},
)
def test_persistent_connection_variables_config(self):
def test_persistent_connection_variables_config(self) -> None:
url = dj_database_url.config(conn_max_age=600, conn_health_checks=True)
assert url["CONN_MAX_AGE"] == 600
assert url["CONN_HEALTH_CHECKS"] is True
def test_no_env_variable(self):
def test_no_env_variable(self) -> None:
with self.assertLogs() as cm:
with mock.patch.dict(os.environ, clear=True):
url = dj_database_url.config()
@ -639,15 +669,19 @@ class DatabaseTestSuite(unittest.TestCase):
dj_database_url.register("django.contrib.db.backends.bag_end", "bag-end")
assert len(uses_netloc) == len(set(uses_netloc))
def test_bad_url_parsing(self) -> None:
with self.assertRaisesRegex(ValueError, "No support for 'foo'. We support: "):
dj_database_url.parse("foo://bar")
@mock.patch.dict(
os.environ,
{"DATABASE_URL": "postgres://user:password@instance.amazonaws.com:5431/d8r8?"},
)
def test_ssl_require(self):
def test_ssl_require(self) -> None:
url = dj_database_url.config(ssl_require=True)
assert url["OPTIONS"] == {'sslmode': 'require'}
def test_options_int_values(self):
def test_options_int_values(self) -> None:
"""Ensure that options with integer values are parsed correctly."""
url = dj_database_url.parse(
"mysql://user:pw@127.0.0.1:15036/db?connect_timout=3"
@ -658,7 +692,7 @@ class DatabaseTestSuite(unittest.TestCase):
os.environ,
{"DATABASE_URL": "postgres://user:password@instance.amazonaws.com:5431/d8r8?"},
)
def test_server_side_cursors__config(self):
def test_server_side_cursors__config(self) -> None:
url = dj_database_url.config(disable_server_side_cursors=True)
assert url["DISABLE_SERVER_SIDE_CURSORS"] is True